@@ -480,11 +480,11 @@ static bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
480
480
return true ;
481
481
}
482
482
483
- static bool
483
+ static void
484
484
emitLoadedModuleTraceForAllPrimariesIfNeeded (ModuleDecl *mainModule,
485
485
DependencyTracker *depTracker,
486
486
const FrontendOptions &opts) {
487
- return opts.InputsAndOutputs .forEachInputProducingSupplementaryOutput (
487
+ opts.InputsAndOutputs .forEachInputProducingSupplementaryOutput (
488
488
[&](const InputFile &input) -> bool {
489
489
return emitLoadedModuleTraceIfNeeded (
490
490
mainModule, depTracker, opts.PrebuiltModuleCachePath ,
@@ -1154,15 +1154,22 @@ static void emitIndexData(const CompilerInstance &Instance) {
1154
1154
1155
1155
// / Emits all "one-per-module" supplementary outputs that don't depend on
1156
1156
// / anything past type-checking.
1157
- // /
1158
- // / These are extracted out so that they can be invoked early when using
1159
- // / `-typecheck`, but skipped for any mode that runs SIL diagnostics if there's
1160
- // / an error found there (to get those diagnostics back to the user faster).
1161
1157
static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs (
1162
1158
CompilerInstance &Instance) {
1163
1159
const auto &Invocation = Instance.getInvocation ();
1164
1160
const FrontendOptions &opts = Invocation.getFrontendOptions ();
1165
1161
1162
+ // FIXME: Whole-module outputs with a non-whole-module action ought to
1163
+ // be disallowed, but the driver implements -index-file mode by generating a
1164
+ // regular whole-module frontend command line and modifying it to index just
1165
+ // one file (by making it a primary) instead of all of them. If that
1166
+ // invocation also has flags to emit whole-module supplementary outputs, the
1167
+ // compiler can crash trying to access information for non-type-checked
1168
+ // declarations in the non-primary files. For now, prevent those crashes by
1169
+ // guarding the emission of whole-module supplementary outputs.
1170
+ if (!opts.InputsAndOutputs .isWholeModule ())
1171
+ return false ;
1172
+
1166
1173
// Record whether we failed to emit any of these outputs, but keep going; one
1167
1174
// failure does not mean skipping the rest.
1168
1175
bool hadAnyError = false ;
@@ -1250,6 +1257,15 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
1250
1257
// Verify generic signatures if we've been asked to.
1251
1258
verifyGenericSignaturesIfNeeded (Invocation, ctx);
1252
1259
1260
+ // Emit any additional outputs that we only need for a successful compilation.
1261
+ // We don't want to unnecessarily delay getting any errors back to the user.
1262
+ if (!ctx.hadError ()) {
1263
+ emitLoadedModuleTraceForAllPrimariesIfNeeded (
1264
+ Instance.getMainModule (), Instance.getDependencyTracker (), opts);
1265
+
1266
+ emitAnyWholeModulePostTypeCheckSupplementaryOutputs (Instance);
1267
+ }
1268
+
1253
1269
// Emit dependencies and index data.
1254
1270
emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
1255
1271
emitIndexData (Instance);
@@ -1360,26 +1376,9 @@ static bool performCompile(CompilerInstance &Instance,
1360
1376
if (Context.hadError ())
1361
1377
return true ;
1362
1378
1363
- (void )emitLoadedModuleTraceForAllPrimariesIfNeeded (
1364
- Instance.getMainModule (), Instance.getDependencyTracker (), opts);
1365
-
1366
1379
// We've just been told to perform a typecheck, so we can return now.
1367
- if (Action == FrontendOptions::ActionType::Typecheck) {
1368
- // FIXME: Whole-module outputs with a non-whole-module -typecheck ought to
1369
- // be disallowed, but the driver implements -index-file mode by generating a
1370
- // regular whole-module frontend command line and modifying it to index just
1371
- // one file (by making it a primary) instead of all of them. If that
1372
- // invocation also has flags to emit whole-module supplementary outputs, the
1373
- // compiler can crash trying to access information for non-type-checked
1374
- // declarations in the non-primary files. For now, prevent those crashes by
1375
- // guarding the emission of whole-module supplementary outputs.
1376
- if (opts.InputsAndOutputs .isWholeModule ()) {
1377
- if (emitAnyWholeModulePostTypeCheckSupplementaryOutputs (Instance)) {
1378
- return true ;
1379
- }
1380
- }
1380
+ if (Action == FrontendOptions::ActionType::Typecheck)
1381
1381
return false ;
1382
- }
1383
1382
1384
1383
assert (FrontendOptions::doesActionGenerateSIL (Action) &&
1385
1384
" All actions not requiring SILGen must have been handled!" );
@@ -1649,8 +1648,6 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
1649
1648
if (observer)
1650
1649
observer->performedSILProcessing (*SM);
1651
1650
1652
- emitAnyWholeModulePostTypeCheckSupplementaryOutputs (Instance);
1653
-
1654
1651
if (Action == FrontendOptions::ActionType::EmitSIB)
1655
1652
return serializeSIB (SM.get (), PSPs, Context, MSF);
1656
1653
0 commit comments