Skip to content

Commit 024e346

Browse files
committed
[Frontend] Enable delayed body parsing for a non-primary main
This better matches the behavior of `parseAndTypeCheckMainFileUpTo`.
1 parent 6b87dce commit 024e346

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,30 +1095,36 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
10951095
PersistentState = llvm::make_unique<PersistentParserState>();
10961096
PersistentState->PerformConditionEvaluation = EvaluateConditionals;
10971097

1098+
auto shouldDelayBodies = [&](unsigned bufferID) -> bool {
1099+
if (!CanDelayBodies)
1100+
return false;
1101+
1102+
// Don't delay bodies in whole module mode or for primary files.
1103+
return !(isWholeModuleCompilation() || isPrimaryInput(bufferID));
1104+
};
1105+
10981106
// Parse all the library files.
10991107
for (auto BufferID : InputSourceCodeBufferIDs) {
11001108
if (BufferID == MainBufferID)
11011109
continue;
11021110

1103-
auto IsPrimary = isWholeModuleCompilation() || isPrimaryInput(BufferID);
1104-
11051111
SourceFile *NextInput = createSourceFileForMainModule(
11061112
SourceFileKind::Library, SourceFile::ImplicitModuleImportKind::None,
11071113
BufferID);
11081114

11091115
parseIntoSourceFileFull(*NextInput, BufferID, PersistentState.get(),
1110-
/*DelayBodyParsing=*/!IsPrimary && CanDelayBodies);
1116+
shouldDelayBodies(BufferID));
11111117
}
11121118

11131119
// Now parse the main file.
11141120
if (MainBufferID != NO_SUCH_BUFFER) {
11151121
SourceFile &MainFile =
11161122
MainModule->getMainSourceFile(Invocation.getSourceFileKind());
11171123
MainFile.SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache();
1124+
assert(MainBufferID == MainFile.getBufferID());
11181125

1119-
parseIntoSourceFileFull(MainFile, MainFile.getBufferID().getValue(),
1120-
PersistentState.get(),
1121-
/*DelayBodyParsing=*/false);
1126+
parseIntoSourceFileFull(MainFile, MainBufferID, PersistentState.get(),
1127+
shouldDelayBodies(MainBufferID));
11221128
}
11231129

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

0 commit comments

Comments
 (0)