@@ -1290,10 +1290,16 @@ static bool performCompile(CompilerInstance &Instance,
1290
1290
if (opts.PrintClangStats && Context.getClangModuleLoader ())
1291
1291
Context.getClangModuleLoader ()->printStatistics ();
1292
1292
1293
- emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
1294
1293
emitSwiftRangesForAllPrimaryInputsIfNeeded (Instance);
1295
1294
emitCompiledSourceForAllPrimaryInputsIfNeeded (Instance);
1296
1295
1296
+ SWIFT_DEFER {
1297
+ // We might have freed the ASTContext already, but in that case we must have
1298
+ // emitted the dependencies first.
1299
+ if (Instance.hasASTContext ())
1300
+ emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
1301
+ };
1302
+
1297
1303
emitIndexData (Instance);
1298
1304
1299
1305
if (Context.hadError ())
@@ -1508,6 +1514,11 @@ static void freeDeallocatableResourcesIfPossible(CompilerInstance &Instance) {
1508
1514
break ;
1509
1515
case DeallocatableResources::SILModuleAndASTContext:
1510
1516
Instance.freeSILModule ();
1517
+
1518
+ // Make sure we emit dependencies now, because we can't do it after the
1519
+ // context is gone.
1520
+ emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
1521
+
1511
1522
Instance.freeASTContext ();
1512
1523
break ;
1513
1524
}
@@ -2184,14 +2195,6 @@ int swift::performFrontend(ArrayRef<const char *> Args,
2184
2195
Invocation.getFrontendOptions ().DumpAPIPath );
2185
2196
}
2186
2197
2187
- // If we're asked to enable private intransitive dependencies, we need to
2188
- // write over the dependency files we just emitted because we need to
2189
- // get the dependencies written post-Sema down on disk.
2190
- // FIXME: Evaluate the impact turning this on universally has.
2191
- if (Invocation.getLangOptions ().EnableExperientalPrivateIntransitiveDependencies ) {
2192
- emitReferenceDependenciesForAllPrimaryInputsIfNeeded (*Instance);
2193
- }
2194
-
2195
2198
// Verify reference dependencies of the current compilation job *before*
2196
2199
// verifying diagnostics so that the former can be tested via the latter.
2197
2200
if (Invocation.getFrontendOptions ().EnableIncrementalDependencyVerifier ) {
0 commit comments