Skip to content

Commit 63c8044

Browse files
committed
[Frontend] Move more outputs to end of pipeline
Move both the loaded module trace output and "additional whole module outputs" to the end of the pipeline, ensuring to preserve the behaviour where we skip them if we encountered an error.
1 parent 1e8f24a commit 63c8044

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,11 @@ static bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
480480
return true;
481481
}
482482

483-
static bool
483+
static void
484484
emitLoadedModuleTraceForAllPrimariesIfNeeded(ModuleDecl *mainModule,
485485
DependencyTracker *depTracker,
486486
const FrontendOptions &opts) {
487-
return opts.InputsAndOutputs.forEachInputProducingSupplementaryOutput(
487+
opts.InputsAndOutputs.forEachInputProducingSupplementaryOutput(
488488
[&](const InputFile &input) -> bool {
489489
return emitLoadedModuleTraceIfNeeded(
490490
mainModule, depTracker, opts.PrebuiltModuleCachePath,
@@ -1154,15 +1154,22 @@ static void emitIndexData(const CompilerInstance &Instance) {
11541154

11551155
/// Emits all "one-per-module" supplementary outputs that don't depend on
11561156
/// 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).
11611157
static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
11621158
CompilerInstance &Instance) {
11631159
const auto &Invocation = Instance.getInvocation();
11641160
const FrontendOptions &opts = Invocation.getFrontendOptions();
11651161

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+
11661173
// Record whether we failed to emit any of these outputs, but keep going; one
11671174
// failure does not mean skipping the rest.
11681175
bool hadAnyError = false;
@@ -1250,6 +1257,15 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
12501257
// Verify generic signatures if we've been asked to.
12511258
verifyGenericSignaturesIfNeeded(Invocation, ctx);
12521259

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+
12531269
// Emit dependencies and index data.
12541270
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
12551271
emitIndexData(Instance);
@@ -1360,26 +1376,9 @@ static bool performCompile(CompilerInstance &Instance,
13601376
if (Context.hadError())
13611377
return true;
13621378

1363-
(void)emitLoadedModuleTraceForAllPrimariesIfNeeded(
1364-
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
1365-
13661379
// 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)
13811381
return false;
1382-
}
13831382

13841383
assert(FrontendOptions::doesActionGenerateSIL(Action) &&
13851384
"All actions not requiring SILGen must have been handled!");
@@ -1649,8 +1648,6 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
16491648
if (observer)
16501649
observer->performedSILProcessing(*SM);
16511650

1652-
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
1653-
16541651
if (Action == FrontendOptions::ActionType::EmitSIB)
16551652
return serializeSIB(SM.get(), PSPs, Context, MSF);
16561653

0 commit comments

Comments
 (0)