@@ -458,8 +458,9 @@ static void countStatsPostSema(UnifiedStatsReporter &Stats,
458
458
C.NumReferencedMemberNames = R->getUsedMembers ().size ();
459
459
}
460
460
461
- if (auto *SF = Instance.getPrimarySourceFile ()) {
462
- countStatsOfSourceFile (Stats, Instance, SF);
461
+ if (!Instance.getPrimarySourceFiles ().empty ()) {
462
+ for (auto SF : Instance.getPrimarySourceFiles ())
463
+ countStatsOfSourceFile (Stats, Instance, SF);
463
464
} else if (auto *M = Instance.getMainModule ()) {
464
465
// No primary source file, but a main module; this is WMO-mode
465
466
for (auto *F : M->getFiles ()) {
@@ -642,8 +643,6 @@ static bool performCompile(CompilerInstance &Instance,
642
643
return Context.hadError ();
643
644
}
644
645
645
- SourceFile *PrimarySourceFile = Instance.getPrimarySourceFile ();
646
-
647
646
// We've been told to dump the AST (either after parsing or type-checking,
648
647
// which is already differentiated in CompilerInstance::performSema()),
649
648
// so dump or print the main source file and return.
@@ -654,7 +653,7 @@ static bool performCompile(CompilerInstance &Instance,
654
653
Action == FrontendOptions::ActionType::DumpScopeMaps ||
655
654
Action == FrontendOptions::ActionType::DumpTypeRefinementContexts ||
656
655
Action == FrontendOptions::ActionType::DumpInterfaceHash) {
657
- SourceFile *SF = PrimarySourceFile ;
656
+ SourceFile *SF = Instance. getPrimarySourceFile () ;
658
657
if (!SF) {
659
658
SourceFileKind Kind = Invocation.getSourceFileKind ();
660
659
SF = &Instance.getMainModule ()->getMainSourceFile (Kind);
@@ -729,9 +728,12 @@ static bool performCompile(CompilerInstance &Instance,
729
728
(void )emitMakeDependencies (Context.Diags , *Instance.getDependencyTracker (),
730
729
opts);
731
730
732
- if (shouldTrackReferences)
733
- emitReferenceDependencies (Context.Diags , Instance.getPrimarySourceFile (),
734
- *Instance.getDependencyTracker (), opts);
731
+ if (shouldTrackReferences) {
732
+ for (auto *SF : Instance.getPrimarySourceFiles ()) {
733
+ emitReferenceDependencies (Context.Diags , SF,
734
+ *Instance.getDependencyTracker (), opts);
735
+ }
736
+ }
735
737
736
738
if (!opts.InputsAndOutputs .preBatchModeLoadedModuleTracePath ().empty ())
737
739
(void )emitLoadedModuleTrace (Context, *Instance.getDependencyTracker (),
@@ -742,7 +744,8 @@ static bool performCompile(CompilerInstance &Instance,
742
744
if (Context.hadError ()) {
743
745
if (shouldIndex) {
744
746
// Emit the index store data even if there were compiler errors.
745
- if (emitIndexData (PrimarySourceFile, Invocation, Instance))
747
+ if (emitIndexData (Instance.getPrimarySourceFile (),
748
+ Invocation, Instance))
746
749
return true ;
747
750
}
748
751
return true ;
@@ -763,7 +766,8 @@ static bool performCompile(CompilerInstance &Instance,
763
766
Instance.getMainModule (), opts.ImplicitObjCHeaderPath ,
764
767
moduleIsPublic);
765
768
if (shouldIndex) {
766
- if (emitIndexData (PrimarySourceFile, Invocation, Instance))
769
+ if (emitIndexData (Instance.getPrimarySourceFile (),
770
+ Invocation, Instance))
767
771
return true ;
768
772
}
769
773
return Context.hadError ();
@@ -793,8 +797,8 @@ static bool performCompile(CompilerInstance &Instance,
793
797
auto SASTF = dyn_cast<SerializedASTFile>(File);
794
798
return SASTF && SASTF->isSIB ();
795
799
};
796
- if (opts.InputsAndOutputs .hasPrimaries ()) {
797
- FileUnit *PrimaryFile = PrimarySourceFile ;
800
+ if (opts.Inputs .hasPrimaries ()) {
801
+ FileUnit *PrimaryFile = Instance. getPrimarySourceFile () ;
798
802
if (!PrimaryFile) {
799
803
for (FileUnit *fileUnit : Instance.getMainModule ()->getFiles ()) {
800
804
if (auto SASTF = dyn_cast<SerializedASTFile>(fileUnit)) {
@@ -842,8 +846,7 @@ static bool performCompile(CompilerInstance &Instance,
842
846
if (Invocation.getSILOptions ().LinkMode == SILOptions::LinkAll)
843
847
performSILLinking (SM.get (), true );
844
848
845
- auto DC = PrimarySourceFile ? ModuleOrSourceFile (PrimarySourceFile) :
846
- Instance.getMainModule ();
849
+ auto DC = Instance.getPrimarySourceFileOrMainModule ();
847
850
if (!opts.InputsAndOutputs .preBatchModeModuleOutputPath ().empty ()) {
848
851
SerializationOptions serializationOpts;
849
852
serializationOpts.OutputPath =
@@ -899,10 +902,9 @@ static bool performCompile(CompilerInstance &Instance,
899
902
// done, depending on the compiler setting.
900
903
901
904
auto SerializeSILModuleAction = [&]() {
902
- if (!opts.InputsAndOutputs .preBatchModeModuleOutputPath ().empty () ||
903
- !opts.InputsAndOutputs .preBatchModeModuleDocOutputPath ().empty ()) {
904
- auto DC = PrimarySourceFile ? ModuleOrSourceFile (PrimarySourceFile)
905
- : Instance.getMainModule ();
905
+ if (!opts.InputsAndOutputs .preBatchModeModuleOutputPath ().empty () ||
906
+ !opts.InputsAndOutputs .preBatchModeModuleDocOutputPath ().empty ()) {
907
+ auto DC = Instance.getPrimarySourceFileOrMainModule ();
906
908
if (!opts.InputsAndOutputs .preBatchModeModuleOutputPath ().empty ()) {
907
909
SerializationOptions serializationOpts;
908
910
serializationOpts.OutputPath =
@@ -975,8 +977,9 @@ static bool performCompile(CompilerInstance &Instance,
975
977
976
978
// Get the main source file's private discriminator and attach it to
977
979
// the compile unit's flags.
978
- if (PrimarySourceFile) {
979
- Identifier PD = PrimarySourceFile->getPrivateDiscriminator ();
980
+ if (IRGenOpts.DebugInfoKind != IRGenDebugInfoKind::None &&
981
+ Instance.getPrimarySourceFile ()) {
982
+ Identifier PD = Instance.getPrimarySourceFile ()->getPrivateDiscriminator ();
980
983
if (!PD.empty ())
981
984
IRGenOpts.DWARFDebugFlags += (" -private-discriminator " +PD.str ()).str ();
982
985
}
@@ -988,8 +991,7 @@ static bool performCompile(CompilerInstance &Instance,
988
991
}
989
992
990
993
if (Action == FrontendOptions::ActionType::EmitSIB) {
991
- auto DC = PrimarySourceFile ? ModuleOrSourceFile (PrimarySourceFile) :
992
- Instance.getMainModule ();
994
+ auto DC = Instance.getPrimarySourceFileOrMainModule ();
993
995
if (!opts.InputsAndOutputs .preBatchModeModuleOutputPath ().empty ()) {
994
996
SerializationOptions serializationOpts;
995
997
serializationOpts.OutputPath =
@@ -1010,7 +1012,8 @@ static bool performCompile(CompilerInstance &Instance,
1010
1012
if (Action == FrontendOptions::ActionType::MergeModules ||
1011
1013
Action == FrontendOptions::ActionType::EmitModuleOnly) {
1012
1014
if (shouldIndex) {
1013
- if (emitIndexData (PrimarySourceFile, Invocation, Instance))
1015
+ if (emitIndexData (Instance.getPrimarySourceFile (),
1016
+ Invocation, Instance))
1014
1017
return true ;
1015
1018
}
1016
1019
return Context.hadError ();
@@ -1042,7 +1045,8 @@ static bool performCompile(CompilerInstance &Instance,
1042
1045
// TODO: remove once the frontend understands what action it should perform
1043
1046
IRGenOpts.OutputKind = getOutputKind (Action);
1044
1047
if (Action == FrontendOptions::ActionType::Immediate) {
1045
- assert (!PrimarySourceFile && " -i doesn't work in -primary-file mode" );
1048
+ assert (Instance.getPrimarySourceFiles ().empty () &&
1049
+ " -i doesn't work in -primary-file mode" );
1046
1050
IRGenOpts.UseJIT = true ;
1047
1051
IRGenOpts.DebugInfoKind = IRGenDebugInfoKind::Normal;
1048
1052
const ProcessCmdLine &CmdLine = ProcessCmdLine (opts.ImmediateArgv .begin (),
@@ -1063,11 +1067,12 @@ static bool performCompile(CompilerInstance &Instance,
1063
1067
auto &LLVMContext = getGlobalLLVMContext ();
1064
1068
std::unique_ptr<llvm::Module> IRModule;
1065
1069
llvm::GlobalVariable *HashGlobal;
1066
- if (PrimarySourceFile) {
1067
- IRModule = performIRGeneration (
1068
- IRGenOpts, *PrimarySourceFile, std::move (SM),
1069
- opts.InputsAndOutputs .preBatchModeGetSingleOutputFilename (),
1070
- LLVMContext, 0 , &HashGlobal);
1070
+ if (!Instance.getPrimarySourceFiles ().empty ()) {
1071
+ IRModule = performIRGeneration (IRGenOpts,
1072
+ *Instance.getPrimarySourceFile (),
1073
+ std::move (SM),
1074
+ opts.InputsAndOutputs .preBatchModeGetSingleOutputFilename ()(), LLVMContext,
1075
+ 0 , &HashGlobal);
1071
1076
} else {
1072
1077
IRModule = performIRGeneration (
1073
1078
IRGenOpts, Instance.getMainModule (), std::move (SM),
@@ -1078,7 +1083,7 @@ static bool performCompile(CompilerInstance &Instance,
1078
1083
// Walk the AST for indexing after IR generation. Walking it before seems
1079
1084
// to cause miscompilation issues.
1080
1085
if (shouldIndex) {
1081
- if (emitIndexData (PrimarySourceFile , Invocation, Instance))
1086
+ if (emitIndexData (Instance. getPrimarySourceFile () , Invocation, Instance))
1082
1087
return true ;
1083
1088
}
1084
1089
@@ -1107,8 +1112,9 @@ static bool performCompile(CompilerInstance &Instance,
1107
1112
const auto &SILOpts = Invocation.getSILOptions ();
1108
1113
const auto hasMultipleIGMs = SILOpts.hasMultipleIGMs ();
1109
1114
bool error;
1110
- if (PrimarySourceFile)
1111
- error = validateTBD (PrimarySourceFile, *IRModule, hasMultipleIGMs,
1115
+ if (!Instance.getPrimarySourceFiles ().empty ())
1116
+ error = validateTBD (Instance.getPrimarySourceFile (),
1117
+ *IRModule, hasMultipleIGMs,
1112
1118
allSymbols);
1113
1119
else
1114
1120
error = validateTBD (Instance.getMainModule (), *IRModule, hasMultipleIGMs,
0 commit comments