Skip to content

Commit 83472bc

Browse files
committed
Frontend: Only enable delayed member parsing for non-primary files
1 parent fb0fbc0 commit 83472bc

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ void CompilerInstance::parseLibraryFile(
849849
// Parser may stop at some erroneous constructions like #else, #endif
850850
// or '}' in some cases, continue parsing until we are done
851851
parseIntoSourceFile(*NextInput, BufferID, &Done, nullptr, &PersistentState,
852-
DelayedCB);
852+
DelayedCB, /*DelayedBodyParsing=*/!IsPrimary);
853853
} while (!Done);
854854

855855
Diags.setSuppressWarnings(DidSuppressWarnings);
@@ -928,7 +928,7 @@ void CompilerInstance::parseAndTypeCheckMainFileUpTo(
928928
// with 'sil' definitions.
929929
parseIntoSourceFile(MainFile, MainFile.getBufferID().getValue(), &Done,
930930
TheSILModule ? &SILContext : nullptr, &PersistentState,
931-
DelayedParseCB);
931+
DelayedParseCB, /*DelayedBodyParsing=*/false);
932932

933933
if (mainIsPrimary && (Done || CurTUElem < MainFile.Decls.size())) {
934934
switch (LimitStage) {
@@ -1055,11 +1055,14 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
10551055
if (BufferID == MainBufferID)
10561056
continue;
10571057

1058+
auto IsPrimary = isWholeModuleCompilation() || isPrimaryInput(BufferID);
1059+
10581060
SourceFile *NextInput = createSourceFileForMainModule(
10591061
SourceFileKind::Library, SourceFile::ImplicitModuleImportKind::None,
10601062
BufferID);
10611063

1062-
parseIntoSourceFileFull(*NextInput, BufferID, &PersistentState);
1064+
parseIntoSourceFileFull(*NextInput, BufferID, &PersistentState,
1065+
nullptr, /*DelayBodyParsing=*/!IsPrimary);
10631066
}
10641067

10651068
// Now parse the main file.
@@ -1069,7 +1072,8 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
10691072
MainFile.SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache();
10701073

10711074
parseIntoSourceFileFull(MainFile, MainFile.getBufferID().getValue(),
1072-
&PersistentState);
1075+
&PersistentState, nullptr,
1076+
/*DelayBodyParsing=*/false);
10731077
}
10741078

10751079
assert(Context->LoadedModules.size() == 1 &&

lib/Parse/Parser.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ class ParseDelayedFunctionBodies : public ASTWalker {
139139
SourceFile &SF = *AFD->getDeclContext()->getParentSourceFile();
140140
SourceManager &SourceMgr = SF.getASTContext().SourceMgr;
141141
unsigned BufferID = SourceMgr.findBufferContainingLoc(AFD->getLoc());
142-
Parser TheParser(BufferID, SF, nullptr, &ParserState);
142+
Parser TheParser(BufferID, SF, nullptr, &ParserState, nullptr,
143+
/*DelayBodyParsing=*/false);
143144
TheParser.SyntaxContext->disable();
144145
std::unique_ptr<CodeCompletionCallbacks> CodeCompletion;
145146
if (CodeCompletionFactory) {
@@ -165,7 +166,8 @@ static void parseDelayedDecl(
165166
SourceManager &SourceMgr = SF.getASTContext().SourceMgr;
166167
unsigned BufferID =
167168
SourceMgr.findBufferContainingLoc(ParserState.getDelayedDeclLoc());
168-
Parser TheParser(BufferID, SF, nullptr, &ParserState);
169+
Parser TheParser(BufferID, SF, nullptr, &ParserState, nullptr,
170+
/*DelayBodyParsing=*/false);
169171

170172
// Disable libSyntax creation in the delayed parsing.
171173
TheParser.SyntaxContext->disable();
@@ -1105,7 +1107,8 @@ ParserUnit::ParserUnit(SourceManager &SM, SourceFileKind SFKind, unsigned Buffer
11051107

11061108
Impl.SF->SyntaxParsingCache = SyntaxCache;
11071109
Impl.TheParser.reset(new Parser(BufferID, *Impl.SF, /*SIL=*/nullptr,
1108-
/*PersistentState=*/nullptr, Impl.SPActions));
1110+
/*PersistentState=*/nullptr, Impl.SPActions,
1111+
/*DelayBodyParsing=*/false));
11091112
}
11101113

11111114
ParserUnit::ParserUnit(SourceManager &SM, SourceFileKind SFKind, unsigned BufferID,
@@ -1122,7 +1125,7 @@ ParserUnit::ParserUnit(SourceManager &SM, SourceFileKind SFKind, unsigned Buffer
11221125
TriviaRetentionMode::WithoutTrivia,
11231126
Offset, EndOffset));
11241127
Impl.TheParser.reset(new Parser(std::move(Lex), *Impl.SF, /*SIL=*/nullptr,
1125-
/*PersistentState=*/nullptr, Impl.SPActions));
1128+
/*PersistentState=*/nullptr, Impl.SPActions, /*DelayBodyParsing=*/false));
11261129
}
11271130

11281131
ParserUnit::~ParserUnit() {

lib/ParseSIL/ParseSIL.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ static bool parseIntoSourceFileImpl(SourceFile &SF,
127127
SF.SyntaxParsingCache, SF.getASTContext().getSyntaxArena());
128128
}
129129

130+
// Not supported right now.
131+
if (SF.Kind == SourceFileKind::REPL)
132+
DelayBodyParsing = false;
133+
if (SF.hasInterfaceHash())
134+
DelayBodyParsing = false;
135+
if (SF.shouldCollectToken())
136+
DelayBodyParsing = false;
137+
if (SF.shouldBuildSyntaxTree())
138+
DelayBodyParsing = false;
139+
if (SIL)
140+
DelayBodyParsing = false;
141+
130142
SharedTimer timer("Parsing");
131143
Parser P(BufferID, SF, SIL ? SIL->Impl.get() : nullptr,
132144
PersistentState, STreeCreator, DelayBodyParsing);

0 commit comments

Comments
 (0)