Add a "nonce version" fingerprint to ActionLookupValue, potentially populated for the ActionLookupValues that need it: *ConfiguredTargetValue and AspectValue. These need it because they contain objects that use reference equality for comparisons (notably, CcLinkingParams). Following an idea coming from shahan@.
PiperOrigin-RevId: 231319823
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionValue.java
index 8ee7db4..e460f47 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionValue.java
@@ -27,7 +27,7 @@
*/
public final class ActionTemplateExpansionValue extends BasicActionLookupValue {
ActionTemplateExpansionValue(GeneratingActions generatingActions) {
- super(generatingActions);
+ super(generatingActions, /*nonceVersion=*/ null);
}
static ActionTemplateExpansionKey key(ActionLookupKey actionLookupKey, int actionIndex) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
index 37a9761..4f7d257 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
@@ -73,9 +73,11 @@
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import com.google.devtools.build.skyframe.ValueOrException;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import java.util.function.Supplier;
import javax.annotation.Nullable;
/**
@@ -108,18 +110,22 @@
*/
private final boolean storeTransitivePackagesForPackageRootResolution;
+ private final Supplier<BigInteger> nonceVersion;
+
AspectFunction(
BuildViewProvider buildViewProvider,
RuleClassProvider ruleClassProvider,
@Nullable SkylarkImportLookupFunction skylarkImportLookupFunctionForInlining,
boolean storeTransitivePackagesForPackageRootResolution,
- BuildOptions defaultBuildOptions) {
+ BuildOptions defaultBuildOptions,
+ Supplier<BigInteger> nonceVersion) {
this.buildViewProvider = buildViewProvider;
this.ruleClassProvider = ruleClassProvider;
this.skylarkImportLookupFunctionForInlining = skylarkImportLookupFunctionForInlining;
this.storeTransitivePackagesForPackageRootResolution =
storeTransitivePackagesForPackageRootResolution;
this.defaultBuildOptions = defaultBuildOptions;
+ this.nonceVersion = nonceVersion;
}
/**
@@ -580,7 +586,8 @@
originalTarget.getLabel(),
originalTarget.getLocation(),
ConfiguredAspect.forAlias(real.getConfiguredAspect()),
- transitivePackagesForPackageRootResolution);
+ transitivePackagesForPackageRootResolution,
+ nonceVersion.get());
}
@Nullable
@@ -658,7 +665,8 @@
configuredAspect,
transitivePackagesForPackageRootResolution == null
? null
- : transitivePackagesForPackageRootResolution.build());
+ : transitivePackagesForPackageRootResolution.build(),
+ nonceVersion.get());
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java
index eb525be..c5f3242 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java
@@ -36,6 +36,7 @@
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.syntax.SkylarkImport;
import com.google.devtools.build.skyframe.SkyFunctionName;
+import java.math.BigInteger;
import javax.annotation.Nullable;
/** An aspect in the context of the Skyframe graph. */
@@ -442,8 +443,9 @@
Label label,
Location location,
ConfiguredAspect configuredAspect,
- NestedSet<Package> transitivePackagesForPackageRootResolution) {
- super(configuredAspect.getActions(), configuredAspect.getGeneratingActionIndex());
+ NestedSet<Package> transitivePackagesForPackageRootResolution,
+ BigInteger nonceVersion) {
+ super(configuredAspect.getActions(), configuredAspect.getGeneratingActionIndex(), nonceVersion);
this.label = Preconditions.checkNotNull(label, actions);
this.aspect = Preconditions.checkNotNull(aspect, label);
this.location = Preconditions.checkNotNull(location, label);
@@ -489,6 +491,11 @@
transitivePackagesForPackageRootResolution = null;
}
+ @Override
+ public final boolean mustBeReferenceComparedOnRecomputation() {
+ return true;
+ }
+
/**
* Returns the set of packages transitively loaded by this value. Must only be used for
* constructing the package -> source root map needed for some builds. If the caller has not
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionValue.java
index 298e002..e3acadb 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionValue.java
@@ -34,7 +34,7 @@
private final BuildInfoCollection collection;
BuildInfoCollectionValue(BuildInfoCollection collection, GeneratingActions generatingActions) {
- super(generatingActions);
+ super(generatingActions, /*nonceVersion=*/ null);
this.collection = collection;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
index 8115236..bebbc06 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
@@ -79,6 +79,7 @@
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import com.google.devtools.build.skyframe.ValueOrException;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -88,6 +89,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Semaphore;
+import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
@@ -136,6 +138,8 @@
private final Semaphore cpuBoundSemaphore;
private final BuildOptions defaultBuildOptions;
@Nullable private final ConfiguredTargetProgressReceiver configuredTargetProgress;
+ private final Supplier<BigInteger> nonceVersion;
+
/**
* Indicates whether the set of packages transitively loaded for a given {@link
* ConfiguredTargetValue} will be needed for package root resolution later in the build. If not,
@@ -152,7 +156,8 @@
boolean storeTransitivePackagesForPackageRootResolution,
boolean shouldUnblockCpuWorkWhenFetchingDeps,
BuildOptions defaultBuildOptions,
- @Nullable ConfiguredTargetProgressReceiver configuredTargetProgress) {
+ @Nullable ConfiguredTargetProgressReceiver configuredTargetProgress,
+ Supplier<BigInteger> nonceVersion) {
this.buildViewProvider = buildViewProvider;
this.ruleClassProvider = ruleClassProvider;
this.cpuBoundSemaphore = cpuBoundSemaphore;
@@ -161,6 +166,7 @@
this.shouldUnblockCpuWorkWhenFetchingDeps = shouldUnblockCpuWorkWhenFetchingDeps;
this.defaultBuildOptions = defaultBuildOptions;
this.configuredTargetProgress = configuredTargetProgress;
+ this.nonceVersion = nonceVersion;
}
@Override
@@ -831,7 +837,8 @@
ruleConfiguredTarget,
transitivePackagesForPackageRootResolution == null
? null
- : transitivePackagesForPackageRootResolution.build());
+ : transitivePackagesForPackageRootResolution.build(),
+ nonceVersion.get());
} else {
GeneratingActions generatingActions;
// Check for conflicting actions within this configured target (that indicates a bug in the
@@ -849,7 +856,8 @@
generatingActions,
transitivePackagesForPackageRootResolution == null
? null
- : transitivePackagesForPackageRootResolution.build());
+ : transitivePackagesForPackageRootResolution.build(),
+ nonceVersion.get());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetValue.java
index a4532c8..46e7d4b 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetValue.java
@@ -70,4 +70,9 @@
* called.
*/
void clear(boolean clearEverything);
+
+ @Override
+ default boolean mustBeReferenceComparedOnRecomputation() {
+ return true;
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/CoverageReportValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/CoverageReportValue.java
index 2972664..1b78692 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/CoverageReportValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/CoverageReportValue.java
@@ -28,7 +28,7 @@
@AutoCodec public static final CoverageReportKey COVERAGE_REPORT_KEY = new CoverageReportKey();
CoverageReportValue(GeneratingActions generatingActions) {
- super(generatingActions);
+ super(generatingActions, /*nonceVersion=*/ null);
}
static class CoverageReportKey extends ActionLookupKey {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/NonRuleConfiguredTargetValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/NonRuleConfiguredTargetValue.java
index 0bb8ff2..7c4e01c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/NonRuleConfiguredTargetValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/NonRuleConfiguredTargetValue.java
@@ -30,6 +30,7 @@
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
+import java.math.BigInteger;
import javax.annotation.Nullable;
/** A non-rule configured target in the context of a Skyframe graph. */
@@ -54,7 +55,7 @@
ImmutableList<ActionAnalysisMetadata> actions,
ImmutableMap<Artifact, Integer> generatingActionIndex,
ConfiguredTarget configuredTarget) {
- super(actions, generatingActionIndex);
+ super(actions, generatingActionIndex, /*nonceVersion=*/ null);
this.configuredTarget = configuredTarget;
// Transitive packages are not serialized.
this.transitivePackagesForPackageRootResolution = null;
@@ -63,8 +64,9 @@
NonRuleConfiguredTargetValue(
ConfiguredTarget configuredTarget,
GeneratingActions generatingActions,
- @Nullable NestedSet<Package> transitivePackagesForPackageRootResolution) {
- super(generatingActions);
+ @Nullable NestedSet<Package> transitivePackagesForPackageRootResolution,
+ @Nullable BigInteger nonceVersion) {
+ super(generatingActions, nonceVersion);
this.configuredTarget = Preconditions.checkNotNull(configuredTarget, generatingActions);
this.transitivePackagesForPackageRootResolution = transitivePackagesForPackageRootResolution;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RuleConfiguredTargetValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RuleConfiguredTargetValue.java
index d5b0744..43cdbc4 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RuleConfiguredTargetValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RuleConfiguredTargetValue.java
@@ -28,6 +28,7 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import java.math.BigInteger;
import javax.annotation.Nullable;
/** A configured target in the context of a Skyframe graph. */
@@ -50,12 +51,17 @@
// Transitive packages are not serialized.
@AutoCodec.Instantiator
RuleConfiguredTargetValue(RuleConfiguredTarget configuredTarget) {
- this(configuredTarget, /*transitivePackagesForPackageRootResolution=*/ null);
+ this(
+ configuredTarget,
+ /*transitivePackagesForPackageRootResolution=*/ null,
+ /*nonceVersion=*/ null);
}
RuleConfiguredTargetValue(
RuleConfiguredTarget configuredTarget,
- @Nullable NestedSet<Package> transitivePackagesForPackageRootResolution) {
+ @Nullable NestedSet<Package> transitivePackagesForPackageRootResolution,
+ @Nullable BigInteger nonceVersion) {
+ super(nonceVersion);
this.configuredTarget = Preconditions.checkNotNull(configuredTarget);
this.transitivePackagesForPackageRootResolution = transitivePackagesForPackageRootResolution;
// These are specifically *not* copied to save memory.
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index adaf81e..4de80d8 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -171,6 +171,7 @@
import com.google.devtools.build.skyframe.WalkableGraph.WalkableGraphFactory;
import com.google.devtools.common.options.OptionsProvider;
import java.io.PrintStream;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -317,6 +318,7 @@
private final PathResolverFactory pathResolverFactory = new PathResolverFactoryImpl();
@Nullable private final NonexistentFileReceiver nonexistentFileReceiver;
+ private final MutableSupplier<BigInteger> nonceVersion = new MutableSupplier<>();
/** An {@link ArtifactResolverSupplier} that supports setting of an {@link ArtifactFactory}. */
public static class MutableArtifactFactorySupplier implements ArtifactResolverSupplier {
@@ -514,7 +516,8 @@
shouldStoreTransitivePackagesInLoadingAndAnalysis(),
shouldUnblockCpuWorkWhenFetchingDeps,
defaultBuildOptions,
- configuredTargetProgress));
+ configuredTargetProgress,
+ nonceVersion));
map.put(
SkyFunctions.ASPECT,
new AspectFunction(
@@ -522,7 +525,8 @@
ruleClassProvider,
skylarkImportLookupFunctionForInlining,
shouldStoreTransitivePackagesInLoadingAndAnalysis(),
- defaultBuildOptions));
+ defaultBuildOptions,
+ nonceVersion));
map.put(
SkyFunctions.LOAD_SKYLARK_ASPECT,
new ToplevelSkylarkAspectFunction(skylarkImportLookupFunctionForInlining));
@@ -626,6 +630,11 @@
return perBuildSyscallCache;
}
+ /** Do not use except in subclasses. */
+ protected void setNonceVersion(BigInteger nonceVersion) {
+ this.nonceVersion.set(nonceVersion);
+ }
+
@ThreadCompatible
public void setActive(boolean active) {
this.active = active;
@@ -2599,4 +2608,3 @@
return buildDriver.evaluate(roots, evaluationContext);
}
}
-