@@ -774,6 +774,7 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage) {
774
774
assert (!InputSourceCodeBufferIDs.empty ());
775
775
assert (InputSourceCodeBufferIDs.size () == 1 );
776
776
assert (MainBufferID != NO_SUCH_BUFFER);
777
+ assert (isPrimaryInput (MainBufferID) || isWholeModuleCompilation ());
777
778
createSILModule ();
778
779
}
779
780
@@ -829,7 +830,7 @@ void CompilerInstance::parseAndCheckTypesUpTo(
829
830
SourceFile::ASTStage_t limitStage) {
830
831
FrontendStatsTracer tracer (getStatsReporter (), " parse-and-check-types" );
831
832
832
- bool hadLoadError = parsePartialModulesAndLibraryFiles ();
833
+ bool hadLoadError = parsePartialModulesAndInputFiles ();
833
834
if (Invocation.isCodeCompletion ()) {
834
835
// When we are doing code completion, make sure to emit at least one
835
836
// diagnostic, so that ASTContext is marked as erroneous. In this case
@@ -840,14 +841,6 @@ void CompilerInstance::parseAndCheckTypesUpTo(
840
841
if (hadLoadError)
841
842
return ;
842
843
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
844
assert (llvm::all_of (MainModule->getFiles (), [](const FileUnit *File) -> bool {
852
845
auto *SF = dyn_cast<SourceFile>(File);
853
846
if (!SF)
@@ -864,17 +857,24 @@ void CompilerInstance::parseAndCheckTypesUpTo(
864
857
865
858
performTypeChecking (SF);
866
859
867
- if (!Context->hadError () && Invocation.getFrontendOptions ().PCMacro ) {
868
- performPCMacro (SF);
860
+ // Parse the SIL decls if needed.
861
+ // TODO: Requestify SIL parsing.
862
+ if (TheSILModule) {
863
+ SILParserState SILContext (TheSILModule.get ());
864
+ parseSourceFileSIL (SF, &SILContext);
869
865
}
870
866
867
+ auto &opts = Invocation.getFrontendOptions ();
868
+ if (!Context->hadError () && opts.DebuggerTestingTransform )
869
+ performDebuggerTestingTransform (SF);
870
+
871
+ if (!Context->hadError () && opts.PCMacro )
872
+ performPCMacro (SF);
873
+
871
874
// Playground transform knows to look out for PCMacro's changes and not
872
875
// to playground log them.
873
- if (!Context->hadError () &&
874
- Invocation.getFrontendOptions ().PlaygroundTransform ) {
875
- performPlaygroundTransform (
876
- SF, Invocation.getFrontendOptions ().PlaygroundHighPerformance );
877
- }
876
+ if (!Context->hadError () && opts.PlaygroundTransform )
877
+ performPlaygroundTransform (SF, opts.PlaygroundHighPerformance );
878
878
});
879
879
880
880
// If the limiting AST stage is import resolution, we're done.
@@ -885,19 +885,9 @@ void CompilerInstance::parseAndCheckTypesUpTo(
885
885
finishTypeChecking ();
886
886
}
887
887
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 () {
888
+ bool CompilerInstance::parsePartialModulesAndInputFiles () {
899
889
FrontendStatsTracer tracer (getStatsReporter (),
900
- " parse-partial-modules-and-library -files" );
890
+ " parse-partial-modules-and-input -files" );
901
891
bool hadLoadError = false ;
902
892
// Parse all the partial modules first.
903
893
for (auto &PM : PartialModules) {
@@ -909,47 +899,22 @@ bool CompilerInstance::parsePartialModulesAndLibraryFiles() {
909
899
hadLoadError = true ;
910
900
}
911
901
912
- // Then parse all the library files.
902
+ // Then parse all the input files.
913
903
for (auto BufferID : InputSourceCodeBufferIDs) {
914
- if (BufferID != MainBufferID) {
915
- parseLibraryFile (BufferID);
904
+ SourceFile *SF;
905
+ if (BufferID == MainBufferID) {
906
+ // If this is the main file, we've already created it.
907
+ SF = &getMainModule ()->getMainSourceFile (Invocation.getSourceFileKind ());
908
+ } else {
909
+ // Otherwise create a library file.
910
+ SF = createSourceFileForMainModule (SourceFileKind::Library, BufferID);
916
911
}
912
+ // Import resolution will lazily trigger parsing of the file.
913
+ performImportResolution (*SF);
917
914
}
918
915
return hadLoadError;
919
916
}
920
917
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
- // For a primary, perform type checking if needed. Otherwise, just do import
933
- // resolution.
934
- if (mainIsPrimary && LimitStage >= SourceFile::TypeChecked) {
935
- performTypeChecking (MainFile);
936
- } else {
937
- assert (!TheSILModule && " Should perform type checking for SIL" );
938
- performImportResolution (MainFile);
939
- }
940
-
941
- // Parse the SIL decls if needed.
942
- if (TheSILModule) {
943
- SILParserState SILContext (TheSILModule.get ());
944
- parseSourceFileSIL (MainFile, &SILContext);
945
- }
946
-
947
- if (mainIsPrimary && !Context->hadError () &&
948
- Invocation.getFrontendOptions ().DebuggerTestingTransform ) {
949
- performDebuggerTestingTransform (MainFile);
950
- }
951
- }
952
-
953
918
static void
954
919
forEachSourceFileIn (ModuleDecl *module ,
955
920
llvm::function_ref<void (SourceFile &)> fn) {
@@ -1030,35 +995,28 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
1030
995
if (!CanDelayBodies)
1031
996
parsingOpts |= SourceFile::ParsingFlags::DisableDelayedBodies;
1032
997
1033
- // Make sure the main file is the first file in the module but parse it last,
1034
- // to match the parsing logic used when performing Sema.
998
+ // Make sure the main file is the first file in the module.
1035
999
if (MainBufferID != NO_SUCH_BUFFER) {
1036
1000
assert (Kind == InputFileKind::Swift ||
1037
1001
Kind == InputFileKind::SwiftModuleInterface);
1038
- createSourceFileForMainModule (Invocation.getSourceFileKind (),
1039
- MainBufferID, parsingOpts);
1040
- }
1041
-
1042
- // Parse all the library files.
1043
- for (auto BufferID : InputSourceCodeBufferIDs) {
1044
- if (BufferID == MainBufferID)
1045
- continue ;
1046
-
1047
- SourceFile *NextInput = createSourceFileForMainModule (
1048
- SourceFileKind::Library, BufferID, parsingOpts);
1049
-
1050
- // Force the parsing of the top level decls.
1051
- (void )NextInput->getTopLevelDecls ();
1002
+ auto *mainFile = createSourceFileForMainModule (
1003
+ Invocation.getSourceFileKind (), MainBufferID, parsingOpts);
1004
+ mainFile->SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache ();
1052
1005
}
1053
1006
1054
- // Now parse the main file.
1055
- if (MainBufferID != NO_SUCH_BUFFER) {
1056
- SourceFile &MainFile =
1057
- MainModule->getMainSourceFile (Invocation.getSourceFileKind ());
1058
- MainFile.SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache ();
1059
-
1007
+ // Parse all of the input files.
1008
+ for (auto bufferID : InputSourceCodeBufferIDs) {
1009
+ SourceFile *SF;
1010
+ if (bufferID == MainBufferID) {
1011
+ // If this is the main file, we've already created it.
1012
+ SF = &MainModule->getMainSourceFile (Invocation.getSourceFileKind ());
1013
+ } else {
1014
+ // Otherwise create a library file.
1015
+ SF = createSourceFileForMainModule (SourceFileKind::Library, bufferID,
1016
+ parsingOpts);
1017
+ }
1060
1018
// Force the parsing of the top level decls.
1061
- (void )MainFile. getTopLevelDecls ();
1019
+ (void )SF-> getTopLevelDecls ();
1062
1020
}
1063
1021
1064
1022
assert (Context->LoadedModules .size () == 1 &&
0 commit comments