Skip to content

Commit c6de4fa

Browse files
committed
[Frontend] Factor out performEndOfPipelineActions
1 parent c98c862 commit c6de4fa

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,17 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
12031203
return hadAnyError;
12041204
}
12051205

1206+
/// Perform any actions that must have access to the ASTContext, and need to be
1207+
/// delayed until the Swift compile pipeline has finished. This may be called
1208+
/// before or after LLVM depending on when the ASTContext gets freed.
1209+
static void performEndOfPipelineActions(CompilerInstance &Instance) {
1210+
assert(Instance.hasASTContext());
1211+
1212+
// Emit dependencies and index data.
1213+
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
1214+
emitIndexData(Instance);
1215+
}
1216+
12061217
/// Performs the compile requested by the user.
12071218
/// \param Instance Will be reset after performIRGeneration when the verifier
12081219
/// mode is NoVerify and there were no errors.
@@ -1295,15 +1306,12 @@ static bool performCompile(CompilerInstance &Instance,
12951306
emitCompiledSourceForAllPrimaryInputsIfNeeded(Instance);
12961307

12971308
SWIFT_DEFER {
1298-
// We might have freed the ASTContext already, but in that case we must have
1299-
// emitted the dependencies and index first.
1300-
if (Instance.hasASTContext()) {
1301-
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
1302-
emitIndexData(Instance);
1303-
}
1309+
// We might have freed the ASTContext already, but in that case we would
1310+
// have already performed these actions.
1311+
if (Instance.hasASTContext())
1312+
performEndOfPipelineActions(Instance);
13041313
};
13051314

1306-
13071315
if (Context.hadError())
13081316
return true;
13091317

@@ -1498,10 +1506,9 @@ static void freeASTContextIfPossible(CompilerInstance &Instance) {
14981506
return;
14991507
}
15001508

1501-
// Make sure we emit dependencies and index now, because we can't do it after
1502-
// the context is gone.
1503-
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
1504-
emitIndexData(Instance);
1509+
// Make sure to perform the end of pipeline actions now, because they need
1510+
// access to the ASTContext.
1511+
performEndOfPipelineActions(Instance);
15051512

15061513
Instance.freeASTContext();
15071514
}

0 commit comments

Comments
 (0)