Skip to content

Commit 46a093a

Browse files
committed
[Frontend] Only enable request reference tracking when needed
Only enable when we have a reference dependency output, or are validating dependencies or collecting statistics. This avoids enabling for SourceKit.
1 parent 850118c commit 46a093a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ void CompilerInstance::recordPrimaryInputBuffer(unsigned BufID) {
308308
PrimaryBufferIDs.insert(BufID);
309309
}
310310

311+
static bool shouldEnableRequestReferenceTracking(const CompilerInstance &CI) {
312+
// Enable request reference dependency tracking when we're either writing
313+
// dependencies for incremental mode, verifying dependencies, or collecting
314+
// stats.
315+
auto &opts = CI.getInvocation().getFrontendOptions();
316+
return opts.InputsAndOutputs.hasReferenceDependenciesFilePath() ||
317+
opts.EnableIncrementalDependencyVerifier ||
318+
!opts.StatsOutputDir.empty();
319+
}
320+
311321
bool CompilerInstance::setUpASTContextIfNeeded() {
312322
if (FrontendOptions::doesActionBuildModuleFromInterface(
313323
Invocation.getFrontendOptions().RequestedAction) &&
@@ -318,10 +328,8 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
318328
return false;
319329
}
320330

321-
// For the time being, we only need to record dependencies in batch mode
322-
// and single file builds.
323-
Invocation.getLangOptions().RecordRequestReferences
324-
= !isWholeModuleCompilation();
331+
Invocation.getLangOptions().RecordRequestReferences =
332+
shouldEnableRequestReferenceTracking(*this);
325333

326334
Context.reset(ASTContext::get(
327335
Invocation.getLangOptions(), Invocation.getTypeCheckerOptions(),

test/Driver/createCompilerInvocation.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@
4040
// NOOUTPUT_ARGS-DAG: -typecheck
4141
// NOOUTPUT_ARGS-DAG: -module-name
4242
// NOOUTPUT_ARGS: Frontend Arguments END
43+
44+
// Make sure that '-incremental' is ignored, we don't want SourceKit to run with
45+
// reference dependency tracking enabled. The legacy driver simply doesn't
46+
// implement incremental compilation, but make sure when we switch to the new
47+
// driver this doesn't start failing.
48+
// RUN: %swift-ide-test_plain -test-createCompilerInvocation -incremental %S/Input/main.swift | %FileCheck --check-prefix INCREMENTAL %s
49+
// INCREMENTAL-NOT: emit-reference-dependencies

0 commit comments

Comments
 (0)