@@ -1203,6 +1203,17 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
1203
1203
return hadAnyError;
1204
1204
}
1205
1205
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
+
1206
1217
// / Performs the compile requested by the user.
1207
1218
// / \param Instance Will be reset after performIRGeneration when the verifier
1208
1219
// / mode is NoVerify and there were no errors.
@@ -1295,15 +1306,12 @@ static bool performCompile(CompilerInstance &Instance,
1295
1306
emitCompiledSourceForAllPrimaryInputsIfNeeded (Instance);
1296
1307
1297
1308
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);
1304
1313
};
1305
1314
1306
-
1307
1315
if (Context.hadError ())
1308
1316
return true ;
1309
1317
@@ -1498,10 +1506,9 @@ static void freeASTContextIfPossible(CompilerInstance &Instance) {
1498
1506
return ;
1499
1507
}
1500
1508
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);
1505
1512
1506
1513
Instance.freeASTContext ();
1507
1514
}
0 commit comments