Change unshareability to be an overridable method on SkyValue, rather than a marker interface (UnshareableValue).
PiperOrigin-RevId: 236564159
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionValue.java
index f3303f3..3be7aad 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionValue.java
@@ -35,7 +35,6 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
-import com.google.devtools.build.lib.skyframe.serialization.UnshareableValue;
import com.google.devtools.build.lib.util.BigIntegerFingerprint;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyKey;
@@ -300,11 +299,11 @@
}
/**
- * Marker subclass that indicates this value cannot be shared across servers. Note that this is
- * unrelated to the concept of shared actions.
+ * Subclass that reports this value cannot be shared across servers. Note that this is unrelated
+ * to the concept of shared actions.
*/
- private static class CrossServerUnshareableActionExecutionValue extends ActionExecutionValue
- implements UnshareableValue {
+ private static final class CrossServerUnshareableActionExecutionValue
+ extends ActionExecutionValue {
CrossServerUnshareableActionExecutionValue(
Map<Artifact, ArtifactFileMetadata> artifactData,
Map<Artifact, TreeArtifactValue> treeArtifactData,
@@ -314,6 +313,11 @@
super(
artifactData, treeArtifactData, additionalOutputData, outputSymlinks, discoveredModules);
}
+
+ @Override
+ public boolean dataIsShareable() {
+ return false;
+ }
}
private static <V> ImmutableMap<Artifact, V> transformKeys(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
index ff66ebe..50d96ce 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
@@ -27,7 +27,6 @@
import com.google.devtools.build.lib.packages.RuleVisibility;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException;
-import com.google.devtools.build.lib.skyframe.serialization.UnshareableValue;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import com.google.devtools.build.skyframe.AbstractSkyKey;
@@ -186,13 +185,16 @@
}
}
- /** An {@linkplain UnshareableValue unshareable} version of {@link PrecomputedValue}. */
- private static final class UnshareablePrecomputedValue extends PrecomputedValue
- implements UnshareableValue {
-
+ /** An unshareable version of {@link PrecomputedValue}. */
+ private static final class UnshareablePrecomputedValue extends PrecomputedValue {
private UnshareablePrecomputedValue(Object value) {
super(value);
}
+
+ @Override
+ public boolean dataIsShareable() {
+ return false;
+ }
}
/** {@link SkyKey} for {@code PrecomputedValue}. */
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java
index 9f2065e..2910daf 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java
@@ -19,7 +19,6 @@
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
-import com.google.devtools.build.lib.skyframe.serialization.UnshareableValue;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
@@ -30,11 +29,16 @@
* A test completion value represents the completion of a test target. This includes the execution
* of all test shards and repeated runs, if applicable.
*/
-public class TestCompletionValue implements SkyValue, UnshareableValue {
+public class TestCompletionValue implements SkyValue {
static final TestCompletionValue TEST_COMPLETION_MARKER = new TestCompletionValue();
private TestCompletionValue() { }
+ @Override
+ public boolean dataIsShareable() {
+ return false;
+ }
+
public static SkyKey key(
ConfiguredTargetKey lac,
final TopLevelArtifactContext topLevelArtifactContext,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/UnshareableValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/UnshareableValue.java
deleted file mode 100644
index 24ebd0c..0000000
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/UnshareableValue.java
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2018 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.skyframe.serialization;
-
-import com.google.devtools.build.skyframe.SkyValue;
-
-/** Marker interface to indicate that this object contains unshareable data. */
-public interface UnshareableValue extends SkyValue {}
diff --git a/src/main/java/com/google/devtools/build/skyframe/ErrorTransienceValue.java b/src/main/java/com/google/devtools/build/skyframe/ErrorTransienceValue.java
index fc931bd..15f27d1 100644
--- a/src/main/java/com/google/devtools/build/skyframe/ErrorTransienceValue.java
+++ b/src/main/java/com/google/devtools/build/skyframe/ErrorTransienceValue.java
@@ -13,7 +13,6 @@
// limitations under the License.
package com.google.devtools.build.skyframe;
-import com.google.devtools.build.lib.skyframe.serialization.UnshareableValue;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -22,8 +21,8 @@
* A value that represents "error transience", i.e. anything which may have caused an unexpected
* failure. Is not equal to anything, including itself, in order to force re-evaluation.
*/
-public final class ErrorTransienceValue implements SkyValue, UnshareableValue {
- public static final SkyFunctionName FUNCTION_NAME =
+public final class ErrorTransienceValue implements SkyValue {
+ private static final SkyFunctionName FUNCTION_NAME =
SkyFunctionName.create(
"ERROR_TRANSIENCE", ShareabilityOfValue.NEVER, FunctionHermeticity.NONHERMETIC);
@AutoCodec public static final SkyKey KEY = () -> FUNCTION_NAME;
@@ -32,6 +31,11 @@
private ErrorTransienceValue() {}
@Override
+ public boolean dataIsShareable() {
+ return false;
+ }
+
+ @Override
public int hashCode() {
// Not the prettiest, but since we always return false for equals throw exception here to
// catch any errors related to hash-based collections quickly.
diff --git a/src/main/java/com/google/devtools/build/skyframe/ShareabilityOfValue.java b/src/main/java/com/google/devtools/build/skyframe/ShareabilityOfValue.java
index 203f47d..625c5db 100644
--- a/src/main/java/com/google/devtools/build/skyframe/ShareabilityOfValue.java
+++ b/src/main/java/com/google/devtools/build/skyframe/ShareabilityOfValue.java
@@ -27,8 +27,8 @@
*/
public enum ShareabilityOfValue {
/**
- * Indicates that values produced by the function are shareable unless they are an instance of
- * {@link com.google.devtools.build.lib.skyframe.serialization.UnshareableValue}.
+ * Indicates that values produced by the function are shareable unless they override {@link
+ * SkyValue#dataIsShareable}.
*/
SOMETIMES,
/** Indicates that values produced by the function are not shareable. */
diff --git a/src/main/java/com/google/devtools/build/skyframe/SkyValue.java b/src/main/java/com/google/devtools/build/skyframe/SkyValue.java
index 03b5e94..efbabda 100644
--- a/src/main/java/com/google/devtools/build/skyframe/SkyValue.java
+++ b/src/main/java/com/google/devtools/build/skyframe/SkyValue.java
@@ -41,4 +41,13 @@
default boolean mustBeReferenceComparedOnRecomputation() {
return false;
}
+
+ /**
+ * Returns true for values that can be reused across builds. Some values are inherently "flaky",
+ * like test statuses or stamping information, and in certain circumstances, those values cannot
+ * be shared across builds/servers.
+ */
+ default boolean dataIsShareable() {
+ return true;
+ }
}
diff --git a/src/test/java/com/google/devtools/build/skyframe/GraphTester.java b/src/test/java/com/google/devtools/build/skyframe/GraphTester.java
index cb6c791..f2ce18f 100644
--- a/src/test/java/com/google/devtools/build/skyframe/GraphTester.java
+++ b/src/test/java/com/google/devtools/build/skyframe/GraphTester.java
@@ -24,7 +24,6 @@
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable;
-import com.google.devtools.build.lib.skyframe.serialization.UnshareableValue;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
@@ -385,11 +384,16 @@
}
}
- /** An {@linkplain UnshareableValue unshareable} version of {@link StringValue}. */
- public static final class UnshareableStringValue extends StringValue implements UnshareableValue {
+ /** An unshareable version of {@link StringValue}. */
+ public static final class UnshareableStringValue extends StringValue {
public UnshareableStringValue(String value) {
super(value);
}
+
+ @Override
+ public boolean dataIsShareable() {
+ return false;
+ }
}
/**