Skip to content

Commit dcd8585

Browse files
joelebacopybara-github
authored andcommitted
Make --discard_analysis_cache work with Skymeld.
Until this CL, Skymeld has been disregarding --discard_analysis_cache. PiperOrigin-RevId: 462130511 Change-Id: I0e6a183d73be1b228799cbb363226f9bc646075d
1 parent 334f780 commit dcd8585

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

src/main/java/com/google/devtools/build/lib/analysis/BuildView.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ public AnalysisResult update(
431431
checkForActionConflicts,
432432
loadingPhaseThreads,
433433
viewOptions.cpuHeavySkyKeysThreadPoolSize,
434-
mergedPhasesExecutionJobsCount);
434+
mergedPhasesExecutionJobsCount,
435+
/*shouldDiscardAnalysisCache=*/ viewOptions.discardAnalysisCache
436+
|| !skyframeExecutor.tracksStateForIncrementality());
435437
}
436438
} finally {
437439
skyframeBuildView.clearInvalidatedActionLookupKeys();

src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverFunction.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ public SkyValue compute(SkyKey skyKey, Environment env)
208208
env,
209209
topLevelArtifactContext);
210210
} else {
211-
env.getListener().post(TopLevelEntityAnalysisConcludedEvent.create(buildDriverKey));
212-
requestAspectExecution((TopLevelAspectsValue) topLevelSkyValue, env, topLevelArtifactContext);
211+
announceAspectAnalysisDoneAndRequestExecution(
212+
buildDriverKey, (TopLevelAspectsValue) topLevelSkyValue, env, topLevelArtifactContext);
213213
}
214214

215215
if (env.valuesMissing()) {
@@ -345,7 +345,8 @@ private void requestConfiguredTargetExecution(
345345
declareDependenciesAndCheckValues(env, artifactsToBuild.build());
346346
}
347347

348-
private void requestAspectExecution(
348+
private void announceAspectAnalysisDoneAndRequestExecution(
349+
BuildDriverKey buildDriverKey,
349350
TopLevelAspectsValue topLevelAspectsValue,
350351
Environment env,
351352
TopLevelArtifactContext topLevelArtifactContext)
@@ -362,6 +363,9 @@ private void requestAspectExecution(
362363
env.getListener().post(AspectAnalyzedEvent.create(aspectKey, configuredAspect));
363364
aspectCompletionKeys.add(AspectCompletionKey.create(aspectKey, topLevelArtifactContext));
364365
}
366+
// Send the AspectAnalyzedEvents first to make sure the BuildResultListener is up-to-date before
367+
// signaling that the analysis of this top level aspect has concluded.
368+
env.getListener().post(TopLevelEntityAnalysisConcludedEvent.create(buildDriverKey));
365369

366370
declareDependenciesAndCheckValues(
367371
env, Iterables.concat(artifactsToBuild.build(), aspectCompletionKeys));

src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java

+31-10
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ public void clearAnalysisCache(
362362
ImmutableSet<ConfiguredTarget> topLevelTargets, ImmutableSet<AspectKey> topLevelAspects) {
363363
// TODO(bazel-team): Consider clearing packages too to save more memory.
364364
skyframeAnalysisWasDiscarded = true;
365-
skyframeExecutor.clearAnalysisCache(topLevelTargets, topLevelAspects);
365+
try (SilentCloseable c = Profiler.instance().profile("skyframeExecutor.clearAnalysisCache")) {
366+
skyframeExecutor.clearAnalysisCache(topLevelTargets, topLevelAspects);
367+
}
366368
}
367369

368370
/**
@@ -633,7 +635,8 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
633635
boolean checkForActionConflicts,
634636
int numThreads,
635637
int cpuHeavySkyKeysThreadPoolSize,
636-
int mergedPhasesExecutionJobsCount)
638+
int mergedPhasesExecutionJobsCount,
639+
boolean shouldDiscardAnalysisCache)
637640
throws InterruptedException, ViewCreationFailedException, BuildFailedException,
638641
TestExecException {
639642
enableAnalysis(true);
@@ -683,14 +686,11 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
683686
Sets.newConcurrentHashSet(Sets.union(buildDriverCTKeys, buildDriverAspectKeys)),
684687
eventBus,
685688
/*finisher=*/ () ->
686-
eventBus.post(
687-
AnalysisPhaseCompleteEvent.fromSkymeld(
688-
buildResultListener.getAnalyzedTargets(),
689-
getEvaluatedCounts(),
690-
getEvaluatedActionCounts(),
691-
analysisWorkTimer.stop().elapsed().toMillis(),
692-
skyframeExecutor.getPackageManager().getAndClearStatistics(),
693-
skyframeExecutor.wasAnalysisCacheInvalidatedAndResetBit())))) {
689+
analysisFinishedCallback(
690+
eventBus,
691+
buildResultListener,
692+
shouldDiscardAnalysisCache,
693+
/*measuredAnalysisTime=*/ analysisWorkTimer.stop().elapsed().toMillis()))) {
694694

695695
try {
696696
resourceManager.resetResourceUsage();
@@ -814,6 +814,27 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
814814
}
815815
}
816816

817+
/** Handles the required steps after all analysis work in this build is done. */
818+
private void analysisFinishedCallback(
819+
EventBus eventBus,
820+
BuildResultListener buildResultListener,
821+
boolean shouldDiscardAnalysisCache,
822+
long measuredAnalysisTime) {
823+
if (shouldDiscardAnalysisCache) {
824+
clearAnalysisCache(
825+
buildResultListener.getAnalyzedTargets(),
826+
buildResultListener.getAnalyzedAspects().keySet());
827+
}
828+
eventBus.post(
829+
AnalysisPhaseCompleteEvent.fromSkymeld(
830+
buildResultListener.getAnalyzedTargets(),
831+
getEvaluatedCounts(),
832+
getEvaluatedActionCounts(),
833+
measuredAnalysisTime,
834+
skyframeExecutor.getPackageManager().getAndClearStatistics(),
835+
skyframeExecutor.wasAnalysisCacheInvalidatedAndResetBit()));
836+
}
837+
817838
/**
818839
* Report the appropriate conflicts and return a TopLevelActionConflictReport.
819840
*

0 commit comments

Comments
 (0)