@@ -198,15 +198,6 @@ void CompilerInstance::recordPrimaryInputBuffer(unsigned BufID) {
198
198
PrimaryBufferIDs.insert (BufID);
199
199
}
200
200
201
- void CompilerInstance::recordPrimarySourceFile (SourceFile *SF) {
202
- assert (MainModule && " main module not created yet" );
203
- PrimarySourceFiles.push_back (SF);
204
- SF->enableInterfaceHash ();
205
- SF->createReferencedNameTracker ();
206
- if (SF->getBufferID ().hasValue ())
207
- recordPrimaryInputBuffer (SF->getBufferID ().getValue ());
208
- }
209
-
210
201
bool CompilerInstance::setUpASTContextIfNeeded () {
211
202
if (Invocation.getFrontendOptions ().RequestedAction ==
212
203
FrontendOptions::ActionType::CompileModuleFromInterface) {
@@ -774,6 +765,7 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage) {
774
765
assert (!InputSourceCodeBufferIDs.empty ());
775
766
assert (InputSourceCodeBufferIDs.size () == 1 );
776
767
assert (MainBufferID != NO_SUCH_BUFFER);
768
+ assert (isPrimaryInput (MainBufferID) || isWholeModuleCompilation ());
777
769
createSILModule ();
778
770
}
779
771
@@ -829,7 +821,7 @@ void CompilerInstance::parseAndCheckTypesUpTo(
829
821
SourceFile::ASTStage_t limitStage) {
830
822
FrontendStatsTracer tracer (getStatsReporter (), " parse-and-check-types" );
831
823
832
- bool hadLoadError = parsePartialModulesAndLibraryFiles ();
824
+ bool hadLoadError = parsePartialModulesAndInputFiles ();
833
825
if (Invocation.isCodeCompletion ()) {
834
826
// When we are doing code completion, make sure to emit at least one
835
827
// diagnostic, so that ASTContext is marked as erroneous. In this case
@@ -840,14 +832,6 @@ void CompilerInstance::parseAndCheckTypesUpTo(
840
832
if (hadLoadError)
841
833
return ;
842
834
843
- // Type-check main file after parsing all other files so that
844
- // it can use declarations from other files.
845
- // In addition, in SIL mode the main file has parsing and
846
- // type-checking interwined.
847
- if (MainBufferID != NO_SUCH_BUFFER) {
848
- parseAndTypeCheckMainFileUpTo (limitStage);
849
- }
850
-
851
835
assert (llvm::all_of (MainModule->getFiles (), [](const FileUnit *File) -> bool {
852
836
auto *SF = dyn_cast<SourceFile>(File);
853
837
if (!SF)
@@ -864,17 +848,24 @@ void CompilerInstance::parseAndCheckTypesUpTo(
864
848
865
849
performTypeChecking (SF);
866
850
867
- if (!Context->hadError () && Invocation.getFrontendOptions ().PCMacro ) {
868
- performPCMacro (SF);
851
+ // Parse the SIL decls if needed.
852
+ // TODO: Requestify SIL parsing.
853
+ if (TheSILModule) {
854
+ SILParserState SILContext (TheSILModule.get ());
855
+ parseSourceFileSIL (SF, &SILContext);
869
856
}
870
857
858
+ auto &opts = Invocation.getFrontendOptions ();
859
+ if (!Context->hadError () && opts.DebuggerTestingTransform )
860
+ performDebuggerTestingTransform (SF);
861
+
862
+ if (!Context->hadError () && opts.PCMacro )
863
+ performPCMacro (SF);
864
+
871
865
// Playground transform knows to look out for PCMacro's changes and not
872
866
// to playground log them.
873
- if (!Context->hadError () &&
874
- Invocation.getFrontendOptions ().PlaygroundTransform ) {
875
- performPlaygroundTransform (
876
- SF, Invocation.getFrontendOptions ().PlaygroundHighPerformance );
877
- }
867
+ if (!Context->hadError () && opts.PlaygroundTransform )
868
+ performPlaygroundTransform (SF, opts.PlaygroundHighPerformance );
878
869
});
879
870
880
871
// If the limiting AST stage is import resolution, we're done.
@@ -885,19 +876,9 @@ void CompilerInstance::parseAndCheckTypesUpTo(
885
876
finishTypeChecking ();
886
877
}
887
878
888
- void CompilerInstance::parseLibraryFile (unsigned BufferID) {
889
- FrontendStatsTracer tracer (getStatsReporter (), " parse-library-file" );
890
-
891
- auto *NextInput =
892
- createSourceFileForMainModule (SourceFileKind::Library, BufferID);
893
-
894
- // Import resolution will lazily trigger parsing of the file.
895
- performImportResolution (*NextInput);
896
- }
897
-
898
- bool CompilerInstance::parsePartialModulesAndLibraryFiles () {
879
+ bool CompilerInstance::parsePartialModulesAndInputFiles () {
899
880
FrontendStatsTracer tracer (getStatsReporter (),
900
- " parse-partial-modules-and-library -files" );
881
+ " parse-partial-modules-and-input -files" );
901
882
bool hadLoadError = false ;
902
883
// Parse all the partial modules first.
903
884
for (auto &PM : PartialModules) {
@@ -909,53 +890,22 @@ bool CompilerInstance::parsePartialModulesAndLibraryFiles() {
909
890
hadLoadError = true ;
910
891
}
911
892
912
- // Then parse all the library files.
893
+ // Then parse all the input files.
913
894
for (auto BufferID : InputSourceCodeBufferIDs) {
914
- if (BufferID != MainBufferID) {
915
- parseLibraryFile (BufferID);
895
+ SourceFile *SF;
896
+ if (BufferID == MainBufferID) {
897
+ // If this is the main file, we've already created it.
898
+ SF = &getMainModule ()->getMainSourceFile (Invocation.getSourceFileKind ());
899
+ } else {
900
+ // Otherwise create a library file.
901
+ SF = createSourceFileForMainModule (SourceFileKind::Library, BufferID);
916
902
}
903
+ // Import resolution will lazily trigger parsing of the file.
904
+ performImportResolution (*SF);
917
905
}
918
906
return hadLoadError;
919
907
}
920
908
921
- void CompilerInstance::parseAndTypeCheckMainFileUpTo (
922
- SourceFile::ASTStage_t LimitStage) {
923
- assert (LimitStage >= SourceFile::ImportsResolved);
924
- FrontendStatsTracer tracer (getStatsReporter (),
925
- " parse-and-typecheck-main-file" );
926
- bool mainIsPrimary =
927
- (isWholeModuleCompilation () || isPrimaryInput (MainBufferID));
928
-
929
- SourceFile &MainFile =
930
- MainModule->getMainSourceFile (Invocation.getSourceFileKind ());
931
-
932
- auto &Diags = MainFile.getASTContext ().Diags ;
933
- auto DidSuppressWarnings = Diags.getSuppressWarnings ();
934
- Diags.setSuppressWarnings (DidSuppressWarnings || !mainIsPrimary);
935
-
936
- // For a primary, perform type checking if needed. Otherwise, just do import
937
- // resolution.
938
- if (mainIsPrimary && LimitStage >= SourceFile::TypeChecked) {
939
- performTypeChecking (MainFile);
940
- } else {
941
- assert (!TheSILModule && " Should perform type checking for SIL" );
942
- performImportResolution (MainFile);
943
- }
944
-
945
- // Parse the SIL decls if needed.
946
- if (TheSILModule) {
947
- SILParserState SILContext (TheSILModule.get ());
948
- parseSourceFileSIL (MainFile, &SILContext);
949
- }
950
-
951
- Diags.setSuppressWarnings (DidSuppressWarnings);
952
-
953
- if (mainIsPrimary && !Context->hadError () &&
954
- Invocation.getFrontendOptions ().DebuggerTestingTransform ) {
955
- performDebuggerTestingTransform (MainFile);
956
- }
957
- }
958
-
959
909
static void
960
910
forEachSourceFileIn (ModuleDecl *module ,
961
911
llvm::function_ref<void (SourceFile &)> fn) {
@@ -1007,8 +957,11 @@ SourceFile *CompilerInstance::createSourceFileForMainModule(
1007
957
Invocation.getLangOptions ().BuildSyntaxTree , opts);
1008
958
MainModule->addFile (*inputFile);
1009
959
1010
- if (isPrimary)
1011
- recordPrimarySourceFile (inputFile);
960
+ if (isPrimary) {
961
+ PrimarySourceFiles.push_back (inputFile);
962
+ inputFile->enableInterfaceHash ();
963
+ inputFile->createReferencedNameTracker ();
964
+ }
1012
965
1013
966
if (bufferID == SourceMgr.getCodeCompletionBufferID ()) {
1014
967
assert (!CodeCompletionFile && " Multiple code completion files?" );
@@ -1036,35 +989,28 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
1036
989
if (!CanDelayBodies)
1037
990
parsingOpts |= SourceFile::ParsingFlags::DisableDelayedBodies;
1038
991
1039
- // Make sure the main file is the first file in the module but parse it last,
1040
- // to match the parsing logic used when performing Sema.
992
+ // Make sure the main file is the first file in the module.
1041
993
if (MainBufferID != NO_SUCH_BUFFER) {
1042
994
assert (Kind == InputFileKind::Swift ||
1043
995
Kind == InputFileKind::SwiftModuleInterface);
1044
- createSourceFileForMainModule (Invocation.getSourceFileKind (),
1045
- MainBufferID, parsingOpts);
996
+ auto *mainFile = createSourceFileForMainModule (
997
+ Invocation.getSourceFileKind (), MainBufferID, parsingOpts);
998
+ mainFile->SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache ();
1046
999
}
1047
1000
1048
- // Parse all the library files.
1049
- for (auto BufferID : InputSourceCodeBufferIDs) {
1050
- if (BufferID == MainBufferID)
1051
- continue ;
1052
-
1053
- SourceFile *NextInput = createSourceFileForMainModule (
1054
- SourceFileKind::Library, BufferID, parsingOpts);
1055
-
1056
- // Force the parsing of the top level decls.
1057
- (void )NextInput->getTopLevelDecls ();
1058
- }
1059
-
1060
- // Now parse the main file.
1061
- if (MainBufferID != NO_SUCH_BUFFER) {
1062
- SourceFile &MainFile =
1063
- MainModule->getMainSourceFile (Invocation.getSourceFileKind ());
1064
- MainFile.SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache ();
1065
-
1001
+ // Parse all of the input files.
1002
+ for (auto bufferID : InputSourceCodeBufferIDs) {
1003
+ SourceFile *SF;
1004
+ if (bufferID == MainBufferID) {
1005
+ // If this is the main file, we've already created it.
1006
+ SF = &MainModule->getMainSourceFile (Invocation.getSourceFileKind ());
1007
+ } else {
1008
+ // Otherwise create a library file.
1009
+ SF = createSourceFileForMainModule (SourceFileKind::Library, bufferID,
1010
+ parsingOpts);
1011
+ }
1066
1012
// Force the parsing of the top level decls.
1067
- (void )MainFile. getTopLevelDecls ();
1013
+ (void )SF-> getTopLevelDecls ();
1068
1014
}
1069
1015
1070
1016
assert (Context->LoadedModules .size () == 1 &&
0 commit comments