Skip to content

Commit

Permalink
Weave the trimming cache into Skyframe, but do not use it yet.
Browse files Browse the repository at this point in the history
Final preparations for the retroactive trimming prototype.

Progress on #6524.

PiperOrigin-RevId: 244960626
  • Loading branch information
mstaib authored and copybara-github committed Apr 24, 2019
1 parent 938db6d commit 794a020
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.devtools.build.lib.analysis.TargetAndConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.BuildOptions.OptionsDiffForReconstruction;
import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
import com.google.devtools.build.lib.analysis.config.ConfigurationResolver;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
Expand Down Expand Up @@ -72,6 +73,7 @@
import com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor.BuildViewProvider;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.trimming.TrimmedConfigurationCache;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.util.OrderedSetMultimap;
import com.google.devtools.build.skyframe.SkyFunction;
Expand Down Expand Up @@ -150,6 +152,9 @@ public synchronized Exception getCause() {

private final boolean shouldUnblockCpuWorkWhenFetchingDeps;

private final TrimmedConfigurationCache<SkyKey, Label, OptionsDiffForReconstruction>
configuredTargetCache;

ConfiguredTargetFunction(
BuildViewProvider buildViewProvider,
RuleClassProvider ruleClassProvider,
Expand All @@ -158,7 +163,9 @@ public synchronized Exception getCause() {
boolean shouldUnblockCpuWorkWhenFetchingDeps,
BuildOptions defaultBuildOptions,
@Nullable ConfiguredTargetProgressReceiver configuredTargetProgress,
Supplier<BigInteger> nonceVersion) {
Supplier<BigInteger> nonceVersion,
TrimmedConfigurationCache<SkyKey, Label, OptionsDiffForReconstruction>
configuredTargetCache) {
this.buildViewProvider = buildViewProvider;
this.ruleClassProvider = ruleClassProvider;
this.cpuBoundSemaphore = cpuBoundSemaphore;
Expand All @@ -168,6 +175,7 @@ public synchronized Exception getCause() {
this.defaultBuildOptions = defaultBuildOptions;
this.configuredTargetProgress = configuredTargetProgress;
this.nonceVersion = nonceVersion;
this.configuredTargetCache = configuredTargetCache;
}

private void acquireWithLogging(SkyKey key) throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ public void setConfigurations(
skyframeExecutor.handleAnalysisInvalidatingChange();
}
}
if (configurations.getTargetConfigurations().stream()
.anyMatch(BuildConfiguration::trimConfigurationsRetroactively)) {
skyframeExecutor.activateRetroactiveTrimming();
} else {
skyframeExecutor.deactivateRetroactiveTrimming();
}
skyframeAnalysisWasDiscarded = false;
this.configurations = configurations;
setTopLevelHostConfiguration(configurations.getHostConfiguration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.BuildOptions.OptionsDiffForReconstruction;
import com.google.devtools.build.lib.analysis.config.ConfigurationResolver;
import com.google.devtools.build.lib.analysis.config.FragmentClassSet;
import com.google.devtools.build.lib.analysis.config.HostTransition;
Expand Down Expand Up @@ -142,6 +143,7 @@
import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ActionCompletedReceiver;
import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ProgressSupplier;
import com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey;
import com.google.devtools.build.lib.skyframe.trimming.TrimmedConfigurationCache;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import com.google.devtools.build.lib.util.AbruptExitException;
import com.google.devtools.build.lib.util.ResourceUsage;
Expand Down Expand Up @@ -329,6 +331,11 @@ public abstract class SkyframeExecutor<T extends BuildDriver> implements Walkabl
@Nullable private final NonexistentFileReceiver nonexistentFileReceiver;
private final MutableSupplier<BigInteger> nonceVersion = new MutableSupplier<>();

private final TrimmedConfigurationCache<SkyKey, Label, OptionsDiffForReconstruction>
trimmingCache = TrimmedConfigurationProgressReceiver.buildCache();
private final TrimmedConfigurationProgressReceiver trimmingListener =
new TrimmedConfigurationProgressReceiver(trimmingCache);

/** An {@link ArtifactResolverSupplier} that supports setting of an {@link ArtifactFactory}. */
public static class MutableArtifactFactorySupplier implements ArtifactResolverSupplier {

Expand Down Expand Up @@ -534,7 +541,8 @@ private ImmutableMap<SkyFunctionName, SkyFunction> skyFunctions(PackageFactory p
shouldUnblockCpuWorkWhenFetchingDeps,
defaultBuildOptions,
configuredTargetProgress,
nonceVersion));
nonceVersion,
trimmingCache));
map.put(
SkyFunctions.ASPECT,
new AspectFunction(
Expand Down Expand Up @@ -797,6 +805,7 @@ protected SkyframeProgressReceiver newSkyframeProgressReceiver() {
public void resetEvaluator() {
init();
emittedEventState.clear();
clearTrimmingCache();
skyframeBuildView.reset();
}

Expand All @@ -817,10 +826,25 @@ public void notifyCommandComplete(ExtendedEventHandler eventHandler) throws Inte
public void handleAnalysisInvalidatingChange() {
logger.info("Dropping configured target data");
analysisCacheDiscarded = true;
clearTrimmingCache();
skyframeBuildView.clearInvalidatedConfiguredTargets();
skyframeBuildView.clearLegacyData();
}

/** Activates retroactive trimming (idempotently, so has no effect if already active). */
void activateRetroactiveTrimming() {
trimmingListener.activate();
}

/** Deactivates retroactive trimming (idempotently, so has no effect if already inactive). */
void deactivateRetroactiveTrimming() {
trimmingListener.deactivate();
}

protected void clearTrimmingCache() {
trimmingCache.clear();
}

/** Used with dump --rules. */
public static class RuleStat {
private final String key;
Expand Down Expand Up @@ -2798,6 +2822,7 @@ protected class SkyframeProgressReceiver
/** This receiver is only needed for loading, so it is null otherwise. */
@Override
public void invalidated(SkyKey skyKey, InvalidationState state) {
trimmingListener.invalidated(skyKey, state);
if (ignoreInvalidations) {
return;
}
Expand All @@ -2806,6 +2831,7 @@ public void invalidated(SkyKey skyKey, InvalidationState state) {

@Override
public void enqueueing(SkyKey skyKey) {
trimmingListener.enqueueing(skyKey);
if (ignoreInvalidations) {
return;
}
Expand All @@ -2821,6 +2847,7 @@ public void evaluated(
@Nullable SkyValue value,
Supplier<EvaluationSuccessState> evaluationSuccessState,
EvaluationState state) {
trimmingListener.evaluated(skyKey, value, evaluationSuccessState, state);
if (ignoreInvalidations) {
return;
}
Expand Down

0 comments on commit 794a020

Please sign in to comment.