@@ -735,12 +735,10 @@ void CompilerInstance::createREPLFile(const ImplicitImports &implicitImports) {
735
735
}
736
736
737
737
std::unique_ptr<DelayedParsingCallbacks>
738
- CompilerInstance::computeDelayedParsingCallback (bool isPrimary ) {
738
+ CompilerInstance::computeDelayedParsingCallback () {
739
739
if (Invocation.isCodeCompletion ())
740
740
return llvm::make_unique<CodeCompleteDelayedCallbacks>(
741
741
SourceMgr.getCodeCompletionLoc ());
742
- if (!isPrimary)
743
- return llvm::make_unique<AlwaysDelayedCallbacks>();
744
742
return nullptr ;
745
743
}
746
744
@@ -754,22 +752,13 @@ void CompilerInstance::addMainFileToModule(
754
752
void CompilerInstance::parseAndCheckTypesUpTo (
755
753
const ImplicitImports &implicitImports, SourceFile::ASTStage_t limitStage) {
756
754
FrontendStatsTracer tracer (Context->Stats , " parse-and-check-types" );
757
- // Delayed parsing callback for the primary file, or all files
758
- // in non-WMO mode.
759
- std::unique_ptr<DelayedParsingCallbacks> PrimaryDelayedCB{
760
- computeDelayedParsingCallback (true )};
761
-
762
- // Delayed parsing callback for non-primary files. Not used in
763
- // WMO mode.
764
- std::unique_ptr<DelayedParsingCallbacks> SecondaryDelayedCB{
765
- computeDelayedParsingCallback (false )};
755
+ std::unique_ptr<DelayedParsingCallbacks> DelayedCB{
756
+ computeDelayedParsingCallback ()};
766
757
767
758
PersistentParserState PersistentState (getASTContext ());
768
759
769
760
bool hadLoadError = parsePartialModulesAndLibraryFiles (
770
- implicitImports, PersistentState,
771
- PrimaryDelayedCB.get (),
772
- SecondaryDelayedCB.get ());
761
+ implicitImports, PersistentState, DelayedCB.get ());
773
762
if (Invocation.isCodeCompletion ()) {
774
763
// When we are doing code completion, make sure to emit at least one
775
764
// diagnostic, so that ASTContext is marked as erroneous. In this case
@@ -788,7 +777,7 @@ void CompilerInstance::parseAndCheckTypesUpTo(
788
777
// interwined.
789
778
if (MainBufferID != NO_SUCH_BUFFER) {
790
779
parseAndTypeCheckMainFileUpTo (limitStage, PersistentState,
791
- PrimaryDelayedCB .get (), TypeCheckOptions);
780
+ DelayedCB .get (), TypeCheckOptions);
792
781
}
793
782
794
783
assert (llvm::all_of (MainModule->getFiles (), [](const FileUnit *File) -> bool {
@@ -829,16 +818,14 @@ void CompilerInstance::parseAndCheckTypesUpTo(
829
818
void CompilerInstance::parseLibraryFile (
830
819
unsigned BufferID, const ImplicitImports &implicitImports,
831
820
PersistentParserState &PersistentState,
832
- DelayedParsingCallbacks *PrimaryDelayedCB,
833
- DelayedParsingCallbacks *SecondaryDelayedCB) {
821
+ DelayedParsingCallbacks *DelayedCB) {
834
822
FrontendStatsTracer tracer (Context->Stats , " parse-library-file" );
835
823
836
824
auto *NextInput = createSourceFileForMainModule (
837
825
SourceFileKind::Library, implicitImports.kind , BufferID);
838
826
addAdditionalInitialImportsTo (NextInput, implicitImports);
839
827
840
828
auto IsPrimary = isWholeModuleCompilation () || isPrimaryInput (BufferID);
841
- auto *DelayedCB = IsPrimary ? PrimaryDelayedCB : SecondaryDelayedCB;
842
829
843
830
auto &Diags = NextInput->getASTContext ().Diags ;
844
831
auto DidSuppressWarnings = Diags.getSuppressWarnings ();
@@ -849,7 +836,7 @@ void CompilerInstance::parseLibraryFile(
849
836
// Parser may stop at some erroneous constructions like #else, #endif
850
837
// or '}' in some cases, continue parsing until we are done
851
838
parseIntoSourceFile (*NextInput, BufferID, &Done, nullptr , &PersistentState,
852
- DelayedCB);
839
+ DelayedCB, /* DelayedBodyParsing= */ !IsPrimary );
853
840
} while (!Done);
854
841
855
842
Diags.setSuppressWarnings (DidSuppressWarnings);
@@ -878,8 +865,7 @@ OptionSet<TypeCheckingFlags> CompilerInstance::computeTypeCheckingOptions() {
878
865
bool CompilerInstance::parsePartialModulesAndLibraryFiles (
879
866
const ImplicitImports &implicitImports,
880
867
PersistentParserState &PersistentState,
881
- DelayedParsingCallbacks *PrimaryDelayedCB,
882
- DelayedParsingCallbacks *SecondaryDelayedCB) {
868
+ DelayedParsingCallbacks *DelayedCB) {
883
869
FrontendStatsTracer tracer (Context->Stats ,
884
870
" parse-partial-modules-and-library-files" );
885
871
bool hadLoadError = false ;
@@ -894,8 +880,7 @@ bool CompilerInstance::parsePartialModulesAndLibraryFiles(
894
880
// Then parse all the library files.
895
881
for (auto BufferID : InputSourceCodeBufferIDs) {
896
882
if (BufferID != MainBufferID) {
897
- parseLibraryFile (BufferID, implicitImports, PersistentState,
898
- PrimaryDelayedCB, SecondaryDelayedCB);
883
+ parseLibraryFile (BufferID, implicitImports, PersistentState, DelayedCB);
899
884
}
900
885
}
901
886
return hadLoadError;
@@ -928,7 +913,7 @@ void CompilerInstance::parseAndTypeCheckMainFileUpTo(
928
913
// with 'sil' definitions.
929
914
parseIntoSourceFile (MainFile, MainFile.getBufferID ().getValue (), &Done,
930
915
TheSILModule ? &SILContext : nullptr , &PersistentState,
931
- DelayedParseCB);
916
+ DelayedParseCB, /* DelayedBodyParsing= */ false );
932
917
933
918
if (mainIsPrimary && (Done || CurTUElem < MainFile.Decls .size ())) {
934
919
switch (LimitStage) {
@@ -1055,11 +1040,14 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
1055
1040
if (BufferID == MainBufferID)
1056
1041
continue ;
1057
1042
1043
+ auto IsPrimary = isWholeModuleCompilation () || isPrimaryInput (BufferID);
1044
+
1058
1045
SourceFile *NextInput = createSourceFileForMainModule (
1059
1046
SourceFileKind::Library, SourceFile::ImplicitModuleImportKind::None,
1060
1047
BufferID);
1061
1048
1062
- parseIntoSourceFileFull (*NextInput, BufferID, &PersistentState);
1049
+ parseIntoSourceFileFull (*NextInput, BufferID, &PersistentState,
1050
+ nullptr , /* DelayBodyParsing=*/ !IsPrimary);
1063
1051
}
1064
1052
1065
1053
// Now parse the main file.
@@ -1069,7 +1057,8 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
1069
1057
MainFile.SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache ();
1070
1058
1071
1059
parseIntoSourceFileFull (MainFile, MainFile.getBufferID ().getValue (),
1072
- &PersistentState);
1060
+ &PersistentState, nullptr ,
1061
+ /* DelayBodyParsing=*/ false );
1073
1062
}
1074
1063
1075
1064
assert (Context->LoadedModules .size () == 1 &&
0 commit comments