@@ -61,14 +61,16 @@ void CompilerInstance::createSILModule() {
61
61
Invocation.getFrontendOptions ().Inputs .isWholeModule ());
62
62
}
63
63
64
- void CompilerInstance::setPrimarySourceFile (SourceFile *SF) {
65
- assert (SF);
64
+ void CompilerInstance::recordPrimaryInputBuffer (unsigned BufID) {
65
+ PrimaryBufferIDs.insert (BufID);
66
+ }
67
+
68
+ void CompilerInstance::recordPrimarySourceFile (SourceFile *SF) {
66
69
assert (MainModule && " main module not created yet" );
67
- assert (!PrimarySourceFile && " already has a primary source file" );
68
- assert (PrimaryBufferID == NO_SUCH_BUFFER || !SF->getBufferID ().hasValue () ||
69
- SF->getBufferID ().getValue () == PrimaryBufferID);
70
- PrimarySourceFile = SF;
71
- PrimarySourceFile->setReferencedNameTracker (NameTracker);
70
+ PrimarySourceFiles.push_back (SF);
71
+ SF->setReferencedNameTracker (NameTracker);
72
+ if (SF->getBufferID ().hasValue ())
73
+ recordPrimaryInputBuffer (SF->getBufferID ().getValue ());
72
74
}
73
75
74
76
bool CompilerInstance::setup (const CompilerInvocation &Invok) {
@@ -186,9 +188,9 @@ bool CompilerInstance::setUpInputs() {
186
188
187
189
// Set the primary file to the code-completion point if one exists.
188
190
if (codeCompletionBufferID.hasValue () &&
189
- *codeCompletionBufferID != PrimaryBufferID ) {
190
- assert (PrimaryBufferID == NO_SUCH_BUFFER && " re-setting PrimaryBufferID" );
191
- PrimaryBufferID = *codeCompletionBufferID;
191
+ ! isPrimaryInput ( *codeCompletionBufferID) ) {
192
+ assert (PrimaryBufferIDs. empty () && " re-setting PrimaryBufferID" );
193
+ recordPrimaryInputBuffer ( *codeCompletionBufferID) ;
192
194
}
193
195
194
196
if (isInputSwift () && MainBufferID == NO_SUCH_BUFFER &&
@@ -214,8 +216,8 @@ bool CompilerInstance::setUpForInput(const InputFile &input) {
214
216
}
215
217
216
218
if (input.isPrimary ()) {
217
- assert (PrimaryBufferID == NO_SUCH_BUFFER && " re-setting PrimaryBufferID" );
218
- PrimaryBufferID = *bufferID;
219
+ assert (PrimaryBufferIDs. empty () && " re-setting PrimaryBufferID" );
220
+ recordPrimaryInputBuffer ( *bufferID) ;
219
221
}
220
222
return false ;
221
223
}
@@ -587,15 +589,15 @@ void CompilerInstance::parseLibraryFile(
587
589
addAdditionalInitialImportsTo (NextInput, implicitImports);
588
590
589
591
auto *DelayedCB = SecondaryDelayedCB;
590
- if (BufferID == PrimaryBufferID ) {
592
+ if (isPrimaryInput ( BufferID) ) {
591
593
DelayedCB = PrimaryDelayedCB;
592
594
}
593
595
if (isWholeModuleCompilation ())
594
596
DelayedCB = PrimaryDelayedCB;
595
597
596
598
auto &Diags = NextInput->getASTContext ().Diags ;
597
599
auto DidSuppressWarnings = Diags.getSuppressWarnings ();
598
- auto IsPrimary = isWholeModuleCompilation () || BufferID == PrimaryBufferID ;
600
+ auto IsPrimary = isWholeModuleCompilation () || isPrimaryInput ( BufferID) ;
599
601
Diags.setSuppressWarnings (DidSuppressWarnings || !IsPrimary);
600
602
601
603
bool Done;
@@ -661,7 +663,7 @@ void CompilerInstance::parseAndTypeCheckMainFile(
661
663
SharedTimer timer (
662
664
" performSema-checkTypesWhileParsingMain-parseAndTypeCheckMainFile" );
663
665
bool mainIsPrimary =
664
- (isWholeModuleCompilation () || MainBufferID == PrimaryBufferID );
666
+ (isWholeModuleCompilation () || isPrimaryInput ( MainBufferID) );
665
667
666
668
SourceFile &MainFile =
667
669
MainModule->getMainSourceFile (Invocation.getSourceFileKind ());
@@ -724,7 +726,9 @@ void CompilerInstance::forEachFileToTypeCheck(
724
726
if (isWholeModuleCompilation ()) {
725
727
forEachSourceFileIn (MainModule, [&](SourceFile &SF) { fn (SF); });
726
728
} else {
727
- fn (*PrimarySourceFile);
729
+ for (auto *SF : PrimarySourceFiles) {
730
+ fn (*SF);
731
+ }
728
732
}
729
733
}
730
734
@@ -746,8 +750,9 @@ SourceFile *CompilerInstance::createSourceFileForMainModule(
746
750
SourceFile (*mainModule, fileKind, bufferID, importKind, keepSyntaxInfo);
747
751
MainModule->addFile (*inputFile);
748
752
749
- if (bufferID && *bufferID == PrimaryBufferID)
750
- setPrimarySourceFile (inputFile);
753
+ if (bufferID && isPrimaryInput (*bufferID)) {
754
+ recordPrimarySourceFile (inputFile);
755
+ }
751
756
752
757
return inputFile;
753
758
}
@@ -813,6 +818,7 @@ void CompilerInstance::freeContextAndSIL() {
813
818
TheSILModule.reset ();
814
819
MainModule = nullptr ;
815
820
SML = nullptr ;
816
- PrimarySourceFile = nullptr ;
821
+ PrimaryBufferIDs.clear ();
822
+ PrimarySourceFiles.clear ();
817
823
}
818
824
0 commit comments