Skip to content

Commit 3789b6e

Browse files
authored
Merge pull request #31597 from slavapestov/record-dependencies-later
Frontend: Emit reference dependencies at the end of the frontend pipeline
2 parents 724c760 + 5b6aa8d commit 3789b6e

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)