@@ -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+
311321bool 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 (),
0 commit comments