Skip to content

Commit 5b6aa8d

Browse files
committed
Frontend: Emit reference dependencies at the end of the frontend pipeline
As part of eliminating cascading dependencies, we need to make sure to capture any dependencies discovered during SILGen and IRGen. This is a little bit tricky because we exit early in various places in the pipeline, so we want to do it after performCompileStepsPostSema() returns, but we can't do it too late, because the ASTContext might already have been deallocated. So emit the dependencies manually before freeing the ASTContext if we decide to do that, or just do it before returning from performCompile() using a SWIFT_DEFER otherwise. This should have no observable effect until we start recording dependencies for lookups done on behalf of declarations in secondary files.
1 parent e08020f commit 5b6aa8d

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,10 +1290,16 @@ static bool performCompile(CompilerInstance &Instance,
12901290
if (opts.PrintClangStats && Context.getClangModuleLoader())
12911291
Context.getClangModuleLoader()->printStatistics();
12921292

1293-
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
12941293
emitSwiftRangesForAllPrimaryInputsIfNeeded(Instance);
12951294
emitCompiledSourceForAllPrimaryInputsIfNeeded(Instance);
12961295

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+
12971303
emitIndexData(Instance);
12981304

12991305
if (Context.hadError())
@@ -1508,6 +1514,11 @@ static void freeDeallocatableResourcesIfPossible(CompilerInstance &Instance) {
15081514
break;
15091515
case DeallocatableResources::SILModuleAndASTContext:
15101516
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+
15111522
Instance.freeASTContext();
15121523
break;
15131524
}
@@ -2184,14 +2195,6 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21842195
Invocation.getFrontendOptions().DumpAPIPath);
21852196
}
21862197

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-
21952198
// Verify reference dependencies of the current compilation job *before*
21962199
// verifying diagnostics so that the former can be tested via the latter.
21972200
if (Invocation.getFrontendOptions().EnableIncrementalDependencyVerifier) {

test/Incremental/PrivateDependencies/reference-dependencies-dynamic-lookup-fine.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ import Foundation
2929
// CHECK-DAG: dynamicLookup implementation '' bar true
3030
// CHECK-DAG: dynamicLookup interface '' bar true
3131

32+
// DUPLICATE-NOT: dynamicLookup implementation '' bar true
3233
// DUPLICATE: dynamicLookup implementation '' bar true
33-
// DUPLICATE: dynamicLookup implementation '' bar true
34-
// DUPLICATE: dynamicLookup interface '' bar true
34+
// DUPLICATE-NOT: dynamicLookup implementation '' bar true
35+
// DUPLICATE-NOT: dynamicLookup interface '' bar true
3536
// DUPLICATE: dynamicLookup interface '' bar true
37+
// DUPLICATE-NOT: dynamicLookup interface '' bar true
3638
func bar(_ x: Int, y: Int) {}
3739
func bar(_ str: String) {}
3840

0 commit comments

Comments
 (0)