diff --git a/include/swift/AST/SourceFile.h b/include/swift/AST/SourceFile.h index 533ff6696dca3..61173f8efefe4 100644 --- a/include/swift/AST/SourceFile.h +++ b/include/swift/AST/SourceFile.h @@ -125,11 +125,38 @@ class SourceFile final : public FileUnit { /// been validated. llvm::SetVector UnvalidatedDeclsWithOpaqueReturnTypes; + /// The list of top-level declarations in the source file. + std::vector Decls; + friend ASTContext; friend Impl; + public: - /// The list of top-level declarations in the source file. - std::vector Decls; + /// Appends the given declaration to the end of the top-level decls list. + void addTopLevelDecl(Decl *d) { + Decls.push_back(d); + } + + /// Prepends a declaration to the top-level decls list. + /// + /// FIXME: This entrypoint exists to support LLDB. Calls to this function are + /// always a mistake, and additional uses should not be added. + /// + /// See rdar://58355191 + void prependTopLevelDecl(Decl *d) { + Decls.insert(Decls.begin(), d); + } + + /// Retrieves an immutable view of the list of top-level decls in this file. + ArrayRef getTopLevelDecls() const { + return Decls; + } + + /// Truncates the list of top-level decls so it contains \c count elements. + void truncateTopLevelDecls(unsigned count) { + assert(count <= Decls.size() && "Can only truncate top-level decls!"); + Decls.resize(count); + } /// A cache of syntax nodes that can be reused when creating the syntax tree /// for this file. diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index a2e81377121a3..7b7bf462b9cd7 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -794,7 +794,7 @@ namespace { PrintWithColorRAII(OS, ASTNodeColor) << "source_file "; PrintWithColorRAII(OS, LocationColor) << '\"' << SF.getFilename() << '\"'; - for (Decl *D : SF.Decls) { + for (Decl *D : SF.getTopLevelDecls()) { if (D->isImplicit()) continue; diff --git a/lib/AST/ASTScopeCreation.cpp b/lib/AST/ASTScopeCreation.cpp index 4c1966841c53e..bb54182e1f0fd 100644 --- a/lib/AST/ASTScopeCreation.cpp +++ b/lib/AST/ASTScopeCreation.cpp @@ -1193,7 +1193,7 @@ AnnotatedInsertionPoint ASTSourceFileScope::expandAScopeThatCreatesANewInsertionPoint( ScopeCreator &scopeCreator) { ASTScopeAssert(SF, "Must already have a SourceFile."); - ArrayRef decls = SF->Decls; + ArrayRef decls = SF->getTopLevelDecls(); // Assume that decls are only added at the end, in source order ArrayRef newDecls = decls.slice(numberOfDeclsAlreadySeen); std::vector newNodes(newDecls.begin(), newDecls.end()); @@ -1865,10 +1865,10 @@ void ASTScopeImpl::beCurrent() {} bool ASTScopeImpl::isCurrentIfWasExpanded() const { return true; } void ASTSourceFileScope::beCurrent() { - numberOfDeclsAlreadySeen = SF->Decls.size(); + numberOfDeclsAlreadySeen = SF->getTopLevelDecls().size(); } bool ASTSourceFileScope::isCurrentIfWasExpanded() const { - return SF->Decls.size() == numberOfDeclsAlreadySeen; + return SF->getTopLevelDecls().size() == numberOfDeclsAlreadySeen; } void IterableTypeScope::beCurrent() { portion->beCurrent(this); } diff --git a/lib/AST/ASTScopeSourceRange.cpp b/lib/AST/ASTScopeSourceRange.cpp index c5689881e176f..99a38518883c5 100644 --- a/lib/AST/ASTScopeSourceRange.cpp +++ b/lib/AST/ASTScopeSourceRange.cpp @@ -284,12 +284,12 @@ SourceRange ASTSourceFileScope::getSourceRangeOfThisASTNode( return SourceRange(charRange.getStart(), charRange.getEnd()); } - if (SF->Decls.empty()) + if (SF->getTopLevelDecls().empty()) return SourceRange(); // Use the source ranges of the declarations in the file. - return SourceRange(SF->Decls.front()->getStartLoc(), - SF->Decls.back()->getEndLoc()); + return SourceRange(SF->getTopLevelDecls().front()->getStartLoc(), + SF->getTopLevelDecls().back()->getEndLoc()); } SourceRange GenericTypeOrExtensionScope::getSourceRangeOfThisASTNode( diff --git a/lib/AST/FineGrainedDependenciesSourceFileDepGraphConstructor.cpp b/lib/AST/FineGrainedDependenciesSourceFileDepGraphConstructor.cpp index 24f7dbb8a3b63..853aaaaade902 100644 --- a/lib/AST/FineGrainedDependenciesSourceFileDepGraphConstructor.cpp +++ b/lib/AST/FineGrainedDependenciesSourceFileDepGraphConstructor.cpp @@ -191,7 +191,7 @@ struct SourceFileDeclFinder { // clang-format off SourceFileDeclFinder(const SourceFile *const SF, const bool includePrivateDecls) : includePrivateDecls(includePrivateDecls) { - for (const Decl *const D : SF->Decls) { + for (const Decl *const D : SF->getTopLevelDecls()) { select(D, extensions, false) || select(D, operators, false) || diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index 486a1e26ba6dd..0d719728b0398 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -230,7 +230,7 @@ void SourceLookupCache::populateMemberCache(const SourceFile &SF) { FrontendStatsTracer tracer(SF.getASTContext().Stats, "populate-source-file-class-member-cache"); - addToMemberCache(SF.Decls); + addToMemberCache(SF.getTopLevelDecls()); MemberCachePopulated = true; } @@ -243,7 +243,7 @@ void SourceLookupCache::populateMemberCache(const ModuleDecl &Mod) { for (const FileUnit *file : Mod.getFiles()) { auto &SF = *cast(file); - addToMemberCache(SF.Decls); + addToMemberCache(SF.getTopLevelDecls()); } MemberCachePopulated = true; @@ -275,7 +275,7 @@ void SourceLookupCache::addToMemberCache(Range decls) { SourceLookupCache::SourceLookupCache(const SourceFile &SF) { FrontendStatsTracer tracer(SF.getASTContext().Stats, "source-file-populate-cache"); - addToUnqualifiedLookupCache(SF.Decls, false); + addToUnqualifiedLookupCache(SF.getTopLevelDecls(), false); } SourceLookupCache::SourceLookupCache(const ModuleDecl &M) { @@ -283,7 +283,7 @@ SourceLookupCache::SourceLookupCache(const ModuleDecl &M) { "module-populate-cache"); for (const FileUnit *file : M.getFiles()) { auto &SF = *cast(file); - addToUnqualifiedLookupCache(SF.Decls, false); + addToUnqualifiedLookupCache(SF.getTopLevelDecls(), false); } } diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index dfaf9ca71f5b2..450f762eeecad 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -2470,7 +2470,7 @@ void FindLocalVal::checkGenericParams(GenericParamList *Params) { } void FindLocalVal::checkSourceFile(const SourceFile &SF) { - for (Decl *D : SF.Decls) + for (Decl *D : SF.getTopLevelDecls()) if (auto *TLCD = dyn_cast(D)) visitBraceStmt(TLCD->getBody(), /*isTopLevel=*/true); } diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index f43739bf2bde8..2bb8ff300c30f 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -984,13 +984,13 @@ void CompilerInstance::parseAndTypeCheckMainFileUpTo( // For SIL we actually have to interleave parsing and type checking // because the SIL parser expects to see fully type checked declarations. if (TheSILModule) { - if (Done || CurTUElem < MainFile.Decls.size()) { + if (Done || CurTUElem < MainFile.getTopLevelDecls().size()) { assert(mainIsPrimary); performTypeChecking(MainFile, CurTUElem); } } - CurTUElem = MainFile.Decls.size(); + CurTUElem = MainFile.getTopLevelDecls().size(); } while (!Done); if (!TheSILModule) { diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index fd01c1131faf5..676a601f35fdb 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -667,7 +667,7 @@ static void countStatsOfSourceFile(UnifiedStatsReporter &Stats, SourceFile *SF) { auto &C = Stats.getFrontendCounters(); auto &SM = Instance.getSourceMgr(); - C.NumDecls += SF->Decls.size(); + C.NumDecls += SF->getTopLevelDecls().size(); C.NumLocalTypeDecls += SF->LocalTypeDecls.size(); C.NumObjCMethods += SF->ObjCMethods.size(); C.NumInfixOperators += SF->InfixOperators.size(); diff --git a/lib/FrontendTool/ReferenceDependencies.cpp b/lib/FrontendTool/ReferenceDependencies.cpp index ef198c095afd1..c9cb5117a0a57 100644 --- a/lib/FrontendTool/ReferenceDependencies.cpp +++ b/lib/FrontendTool/ReferenceDependencies.cpp @@ -252,7 +252,7 @@ ProvidesEmitter::emitTopLevelNames() const { out << providesTopLevel << ":\n"; CollectedDeclarations cpd; - for (const Decl *D : SF->Decls) + for (const Decl *D : SF->getTopLevelDecls()) emitTopLevelDecl(D, cpd); for (auto *operatorFunction : cpd.memberOperatorDecls) out << "- \"" << escape(operatorFunction->getName()) << "\"\n"; diff --git a/lib/IDE/CompletionInstance.cpp b/lib/IDE/CompletionInstance.cpp index ab3c289019116..155b72c5b859f 100644 --- a/lib/IDE/CompletionInstance.cpp +++ b/lib/IDE/CompletionInstance.cpp @@ -88,7 +88,7 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC, auto *parentDC = newDC->getParent(); unsigned N; if (auto parentSF = dyn_cast(parentDC)) - N = findIndexInRange(D, parentSF->Decls); + N = findIndexInRange(D, parentSF->getTopLevelDecls()); else if (auto parentIDC = dyn_cast(parentDC->getAsDecl())) N = findIndexInRange(D, parentIDC->getMembers()); @@ -114,7 +114,7 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC, auto N = IndexStack.pop_back_val(); Decl *D; if (auto parentSF = dyn_cast(newDC)) - D = getElementAt(parentSF->Decls, N); + D = getElementAt(parentSF->getTopLevelDecls(), N); else if (auto parentIDC = dyn_cast(newDC->getAsDecl())) D = getElementAt(parentIDC->getMembers(), N); else diff --git a/lib/IDE/ExprContextAnalysis.cpp b/lib/IDE/ExprContextAnalysis.cpp index d7dbf5fd1bcab..c955d2f81d184 100644 --- a/lib/IDE/ExprContextAnalysis.cpp +++ b/lib/IDE/ExprContextAnalysis.cpp @@ -111,7 +111,7 @@ void swift::ide::typeCheckContextUntil(DeclContext *DC, SourceLoc Loc) { // Here, 'value' is '' unless we explicitly typecheck the // 'guard' statement. SourceFile *SF = DC->getParentSourceFile(); - for (auto *D : SF->Decls) { + for (auto *D : SF->getTopLevelDecls()) { if (auto Code = dyn_cast(D)) { typeCheckTopLevelCodeDecl(Code); if (Code == TLCD) diff --git a/lib/IDE/ModuleInterfacePrinting.cpp b/lib/IDE/ModuleInterfacePrinting.cpp index e87deadb53b05..81a19b86f80dd 100644 --- a/lib/IDE/ModuleInterfacePrinting.cpp +++ b/lib/IDE/ModuleInterfacePrinting.cpp @@ -667,7 +667,7 @@ static SourceLoc getDeclStartPosition(SourceFile &File) { return false; }; - for (auto D : File.Decls) { + for (auto D : File.getTopLevelDecls()) { if (tryUpdateStart(D->getStartLoc())) { tryUpdateStart(D->getAttrs().getStartLoc()); auto RawComment = D->getRawComment(); diff --git a/lib/IDE/REPLCodeCompletion.cpp b/lib/IDE/REPLCodeCompletion.cpp index 4d3356c440687..247ddb4d0e473 100644 --- a/lib/IDE/REPLCodeCompletion.cpp +++ b/lib/IDE/REPLCodeCompletion.cpp @@ -205,7 +205,7 @@ doCodeCompletion(SourceFile &SF, StringRef EnteredCode, unsigned *BufferID, Ctx.SourceMgr.setCodeCompletionPoint(*BufferID, CodeCompletionOffset); // Parse, typecheck and temporarily insert the incomplete code into the AST. - const unsigned OriginalDeclCount = SF.Decls.size(); + const unsigned OriginalDeclCount = SF.getTopLevelDecls().size(); PersistentParserState PersistentState; bool Done; @@ -218,7 +218,7 @@ doCodeCompletion(SourceFile &SF, StringRef EnteredCode, unsigned *BufferID, // Now we are done with code completion. Remove the declarations we // temporarily inserted. - SF.Decls.resize(OriginalDeclCount); + SF.truncateTopLevelDecls(OriginalDeclCount); // Reset the error state because it's only relevant to the code that we just // processed, which now gets thrown away. diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index cc5e490b601ca..3aae01d228ae2 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -431,7 +431,7 @@ void IRGenModule::emitSourceFile(SourceFile &SF) { llvm::SaveAndRestore SetCurSourceFile(CurSourceFile, &SF); // Emit types and other global decls. - for (auto *decl : SF.Decls) + for (auto *decl : SF.getTopLevelDecls()) emitGlobalDecl(decl); for (auto *localDecl : SF.LocalTypeDecls) emitGlobalDecl(localDecl); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 719f64d318e70..83574c17c2f16 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -175,7 +175,7 @@ namespace { DebuggerClient *debug_client = getDebuggerClient(); assert (debug_client); debug_client->didGlobalize(D); - SF->Decls.push_back(D); + SF->addTopLevelDecl(D); P.markWasHandled(D); } }; @@ -250,7 +250,7 @@ void Parser::parseTopLevel() { for (auto Item : Items) { if (auto *D = Item.dyn_cast()) { assert(!isa(D) && "accessors should not be added here"); - SF.Decls.push_back(D); + SF.addTopLevelDecl(D); } } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index be223823a366e..1a76ec7359319 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -182,7 +182,7 @@ void Parser::performCodeCompletionSecondPassImpl( } else if (auto *ED = dyn_cast(DC)) { ED->addMember(D); } else if (auto *SF = dyn_cast(DC)) { - SF->Decls.push_back(D); + SF->addTopLevelDecl(D); } else { llvm_unreachable("invalid decl context kind"); } diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 242f3d32106c9..b87b9521dbffb 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -1670,7 +1670,7 @@ class SourceFileScope { void SILGenModule::emitSourceFile(SourceFile *sf) { SourceFileScope scope(*this, sf); FrontendStatsTracer StatsTracer(getASTContext().Stats, "SILgen-file", sf); - for (Decl *D : sf->Decls) { + for (Decl *D : sf->getTopLevelDecls()) { FrontendStatsTracer StatsTracer(getASTContext().Stats, "SILgen-decl", D); visit(D); } diff --git a/lib/Sema/DebuggerTestingTransform.cpp b/lib/Sema/DebuggerTestingTransform.cpp index 0a4ad23767bfc..4853943d687d6 100644 --- a/lib/Sema/DebuggerTestingTransform.cpp +++ b/lib/Sema/DebuggerTestingTransform.cpp @@ -261,11 +261,11 @@ void swift::performDebuggerTestingTransform(SourceFile &SF) { // Walk over all decls in the file to find the next available closure // discriminator. DiscriminatorFinder DF; - for (Decl *D : SF.Decls) + for (Decl *D : SF.getTopLevelDecls()) D->walk(DF); // Instrument the decls with checkExpect() sanity-checks. - for (Decl *D : SF.Decls) { + for (Decl *D : SF.getTopLevelDecls()) { DebuggerTestingTransform Transform{D->getASTContext(), DF}; D->walk(Transform); swift::verify(D); diff --git a/lib/Sema/NameBinding.cpp b/lib/Sema/NameBinding.cpp index 4b86626e941da..328562e9c23e8 100644 --- a/lib/Sema/NameBinding.cpp +++ b/lib/Sema/NameBinding.cpp @@ -402,7 +402,7 @@ void swift::performNameBinding(SourceFile &SF, unsigned StartElem) { // Make sure we skip adding the standard library imports if the // source file is empty. - if (SF.ASTStage == SourceFile::NameBound || SF.Decls.empty()) { + if (SF.ASTStage == SourceFile::NameBound || SF.getTopLevelDecls().empty()) { SF.ASTStage = SourceFile::NameBound; return; } @@ -417,7 +417,7 @@ void swift::performNameBinding(SourceFile &SF, unsigned StartElem) { // Do a prepass over the declarations to find and load the imported modules // and map operator decls. - for (auto D : llvm::makeArrayRef(SF.Decls).slice(StartElem)) { + for (auto D : SF.getTopLevelDecls().slice(StartElem)) { if (auto *ID = dyn_cast(D)) { Binder.addImport(ImportedModules, ID); } else if (auto *OD = dyn_cast(D)) { diff --git a/lib/Sema/PCMacro.cpp b/lib/Sema/PCMacro.cpp index 9109dd250f607..839176b7aa88d 100644 --- a/lib/Sema/PCMacro.cpp +++ b/lib/Sema/PCMacro.cpp @@ -705,7 +705,7 @@ void swift::performPCMacro(SourceFile &SF) { }; ExpressionFinder EF; - for (Decl *D : SF.Decls) { + for (Decl *D : SF.getTopLevelDecls()) { D->walk(EF); } } diff --git a/lib/Sema/TypeCheckAvailability.cpp b/lib/Sema/TypeCheckAvailability.cpp index 72f3abe58b2ba..0f6812903c459 100644 --- a/lib/Sema/TypeCheckAvailability.cpp +++ b/lib/Sema/TypeCheckAvailability.cpp @@ -604,7 +604,7 @@ void TypeChecker::buildTypeRefinementContextHierarchy(SourceFile &SF, // Build refinement contexts, if necessary, for all declarations starting // with StartElem. TypeRefinementContextBuilder Builder(RootTRC, Context); - for (auto D : llvm::makeArrayRef(SF.Decls).slice(StartElem)) { + for (auto D : SF.getTopLevelDecls().slice(StartElem)) { Builder.build(D); } } @@ -904,8 +904,9 @@ static const Decl *findContainingDeclaration(SourceRange ReferenceRange, if (!SF) return nullptr; - auto BestTopLevelDecl = llvm::find_if(SF->Decls, ContainsReferenceRange); - if (BestTopLevelDecl != SF->Decls.end()) + auto BestTopLevelDecl = llvm::find_if(SF->getTopLevelDecls(), + ContainsReferenceRange); + if (BestTopLevelDecl != SF->getTopLevelDecls().end()) return *BestTopLevelDecl; return nullptr; diff --git a/lib/Sema/TypeCheckREPL.cpp b/lib/Sema/TypeCheckREPL.cpp index 59c3cf05d14f1..ef4a5aab3dc9e 100644 --- a/lib/Sema/TypeCheckREPL.cpp +++ b/lib/Sema/TypeCheckREPL.cpp @@ -300,7 +300,7 @@ void REPLChecker::generatePrintOfExpression(StringRef NameStr, Expr *E) { newTopLevel->setBody(BS); TypeChecker::checkTopLevelErrorHandling(newTopLevel); - SF.Decls.push_back(newTopLevel); + SF.addTopLevelDecl(newTopLevel); } /// When we see an expression in a TopLevelCodeDecl in the REPL, process it, @@ -323,7 +323,7 @@ void REPLChecker::processREPLTopLevelExpr(Expr *E) { // Remove the expression from being in the list of decls to execute, we're // going to reparent it. - auto TLCD = cast(SF.Decls.back()); + auto TLCD = cast(SF.getTopLevelDecls().back()); E = TypeChecker::coerceToRValue(Context, E); @@ -333,7 +333,7 @@ void REPLChecker::processREPLTopLevelExpr(Expr *E) { /*IsCaptureList*/false, E->getStartLoc(), name, &SF); vd->setInterfaceType(E->getType()); - SF.Decls.push_back(vd); + SF.addTopLevelDecl(vd); // Create a PatternBindingDecl to bind the expression into the decl. Pattern *metavarPat = new (Context) NamedPattern(vd); @@ -397,8 +397,8 @@ void REPLChecker::processREPLTopLevelPatternBinding(PatternBindingDecl *PBD) { // replPrint(r123) // Remove PBD from the list of Decls so we can insert before it. - auto PBTLCD = cast(SF.Decls.back()); - SF.Decls.pop_back(); + auto PBTLCD = cast(SF.getTopLevelDecls().back()); + SF.truncateTopLevelDecls(SF.getTopLevelDecls().size() - 1); // Create the meta-variable, let the typechecker name it. Identifier name = getNextResponseVariableName(SF.getParentModule()); @@ -407,7 +407,7 @@ void REPLChecker::processREPLTopLevelPatternBinding(PatternBindingDecl *PBD) { /*IsCaptureList*/false, PBD->getStartLoc(), name, &SF); vd->setInterfaceType(pattern->getType()); - SF.Decls.push_back(vd); + SF.addTopLevelDecl(vd); // Create a PatternBindingDecl to bind the expression into the decl. Pattern *metavarPat = new (Context) NamedPattern(vd); @@ -422,7 +422,7 @@ void REPLChecker::processREPLTopLevelPatternBinding(PatternBindingDecl *PBD) { metavarBinding->getEndLoc()); auto *MVTLCD = new (Context) TopLevelCodeDecl(&SF, MVBrace); - SF.Decls.push_back(MVTLCD); + SF.addTopLevelDecl(MVTLCD); // Replace the initializer of PBD with a reference to our repl temporary. @@ -431,7 +431,7 @@ void REPLChecker::processREPLTopLevelPatternBinding(PatternBindingDecl *PBD) { /*Implicit=*/true); E = TypeChecker::coerceToRValue(Context, E); PBD->setInit(entryIdx, E); - SF.Decls.push_back(PBTLCD); + SF.addTopLevelDecl(PBTLCD); // Finally, print out the result, by referring to the repl temp. E = TypeChecker::buildCheckedRefExpr(vd, &SF, @@ -466,19 +466,20 @@ void TypeChecker::processREPLTopLevel(SourceFile &SF, unsigned FirstDecl) { // Walk over all decls in the file to find the next available closure // discriminator. DiscriminatorFinder DF; - for (Decl *D : SF.Decls) + for (Decl *D : SF.getTopLevelDecls()) D->walk(DF); // Move new declarations out. - std::vector NewDecls(SF.Decls.begin()+FirstDecl, SF.Decls.end()); - SF.Decls.resize(FirstDecl); + std::vector NewDecls(SF.getTopLevelDecls().begin()+FirstDecl, + SF.getTopLevelDecls().end()); + SF.truncateTopLevelDecls(FirstDecl); REPLChecker RC(SF, DF); // Loop over each of the new decls, processing them, adding them back to // the Decls list. for (Decl *D : NewDecls) { - SF.Decls.push_back(D); + SF.addTopLevelDecl(D); auto *TLCD = dyn_cast(D); if (!TLCD || TLCD->getBody()->getElements().empty()) diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp index 5194117fc9854..b5a702309c7f3 100644 --- a/lib/Sema/TypeChecker.cpp +++ b/lib/Sema/TypeChecker.cpp @@ -263,7 +263,7 @@ static void bindExtensions(SourceFile &SF) { if (!SF) continue; - for (auto D : SF->Decls) { + for (auto D : SF->getTopLevelDecls()) { if (auto ED = dyn_cast(D)) if (!tryBindExtension(ED)) worklist.push_back(ED); @@ -378,7 +378,7 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, ::bindExtensions(*SF); // Type check the top-level elements of the source file. - for (auto D : llvm::makeArrayRef(SF->Decls).slice(StartElem)) { + for (auto D : SF->getTopLevelDecls().slice(StartElem)) { if (auto *TLCD = dyn_cast(D)) { // Immediately perform global name-binding etc. TypeChecker::typeCheckTopLevelCodeDecl(TLCD); @@ -465,7 +465,7 @@ void swift::checkInconsistentImplementationOnlyImports(ModuleDecl *MainModule) { if (!SF) continue; - for (auto *topLevelDecl : SF->Decls) { + for (auto *topLevelDecl : SF->getTopLevelDecls()) { auto *nextImport = dyn_cast(topLevelDecl); if (!nextImport) continue; diff --git a/unittests/AST/TestContext.cpp b/unittests/AST/TestContext.cpp index d246d8a0fce33..70d5e2edebb6b 100644 --- a/unittests/AST/TestContext.cpp +++ b/unittests/AST/TestContext.cpp @@ -30,7 +30,7 @@ static void declareOptionalType(ASTContext &ctx, SourceFile *fileForLookups, auto decl = new (ctx) EnumDecl(SourceLoc(), name, SourceLoc(), /*inherited*/{}, params, fileForLookups); wrapped->setDeclContext(decl); - fileForLookups->Decls.push_back(decl); + fileForLookups->addTopLevelDecl(decl); } TestContext::TestContext(ShouldDeclareOptionalTypes optionals)