Skip to content

Commit

Permalink
Make --discard_analysis_cache work with Skymeld.
Browse files Browse the repository at this point in the history
Until this CL, Skymeld has been disregarding --discard_analysis_cache.

PiperOrigin-RevId: 462130511
Change-Id: I0e6a183d73be1b228799cbb363226f9bc646075d
  • Loading branch information
joeleba authored and copybara-github committed Jul 20, 2022
1 parent 334f780 commit dcd8585
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ public AnalysisResult update(
checkForActionConflicts,
loadingPhaseThreads,
viewOptions.cpuHeavySkyKeysThreadPoolSize,
mergedPhasesExecutionJobsCount);
mergedPhasesExecutionJobsCount,
/*shouldDiscardAnalysisCache=*/ viewOptions.discardAnalysisCache
|| !skyframeExecutor.tracksStateForIncrementality());
}
} finally {
skyframeBuildView.clearInvalidatedActionLookupKeys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ public SkyValue compute(SkyKey skyKey, Environment env)
env,
topLevelArtifactContext);
} else {
env.getListener().post(TopLevelEntityAnalysisConcludedEvent.create(buildDriverKey));
requestAspectExecution((TopLevelAspectsValue) topLevelSkyValue, env, topLevelArtifactContext);
announceAspectAnalysisDoneAndRequestExecution(
buildDriverKey, (TopLevelAspectsValue) topLevelSkyValue, env, topLevelArtifactContext);
}

if (env.valuesMissing()) {
Expand Down Expand Up @@ -345,7 +345,8 @@ private void requestConfiguredTargetExecution(
declareDependenciesAndCheckValues(env, artifactsToBuild.build());
}

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

declareDependenciesAndCheckValues(
env, Iterables.concat(artifactsToBuild.build(), aspectCompletionKeys));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ public void clearAnalysisCache(
ImmutableSet<ConfiguredTarget> topLevelTargets, ImmutableSet<AspectKey> topLevelAspects) {
// TODO(bazel-team): Consider clearing packages too to save more memory.
skyframeAnalysisWasDiscarded = true;
skyframeExecutor.clearAnalysisCache(topLevelTargets, topLevelAspects);
try (SilentCloseable c = Profiler.instance().profile("skyframeExecutor.clearAnalysisCache")) {
skyframeExecutor.clearAnalysisCache(topLevelTargets, topLevelAspects);
}
}

/**
Expand Down Expand Up @@ -633,7 +635,8 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
boolean checkForActionConflicts,
int numThreads,
int cpuHeavySkyKeysThreadPoolSize,
int mergedPhasesExecutionJobsCount)
int mergedPhasesExecutionJobsCount,
boolean shouldDiscardAnalysisCache)
throws InterruptedException, ViewCreationFailedException, BuildFailedException,
TestExecException {
enableAnalysis(true);
Expand Down Expand Up @@ -683,14 +686,11 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
Sets.newConcurrentHashSet(Sets.union(buildDriverCTKeys, buildDriverAspectKeys)),
eventBus,
/*finisher=*/ () ->
eventBus.post(
AnalysisPhaseCompleteEvent.fromSkymeld(
buildResultListener.getAnalyzedTargets(),
getEvaluatedCounts(),
getEvaluatedActionCounts(),
analysisWorkTimer.stop().elapsed().toMillis(),
skyframeExecutor.getPackageManager().getAndClearStatistics(),
skyframeExecutor.wasAnalysisCacheInvalidatedAndResetBit())))) {
analysisFinishedCallback(
eventBus,
buildResultListener,
shouldDiscardAnalysisCache,
/*measuredAnalysisTime=*/ analysisWorkTimer.stop().elapsed().toMillis()))) {

try {
resourceManager.resetResourceUsage();
Expand Down Expand Up @@ -814,6 +814,27 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
}
}

/** Handles the required steps after all analysis work in this build is done. */
private void analysisFinishedCallback(
EventBus eventBus,
BuildResultListener buildResultListener,
boolean shouldDiscardAnalysisCache,
long measuredAnalysisTime) {
if (shouldDiscardAnalysisCache) {
clearAnalysisCache(
buildResultListener.getAnalyzedTargets(),
buildResultListener.getAnalyzedAspects().keySet());
}
eventBus.post(
AnalysisPhaseCompleteEvent.fromSkymeld(
buildResultListener.getAnalyzedTargets(),
getEvaluatedCounts(),
getEvaluatedActionCounts(),
measuredAnalysisTime,
skyframeExecutor.getPackageManager().getAndClearStatistics(),
skyframeExecutor.wasAnalysisCacheInvalidatedAndResetBit()));
}

/**
* Report the appropriate conflicts and return a TopLevelActionConflictReport.
*
Expand Down

0 comments on commit dcd8585

Please sign in to comment.