diff options
author | 2018-03-13 13:07:52 -0700 | |
---|---|---|
committer | 2018-03-13 13:09:37 -0700 | |
commit | 9ba46f8f3c2f62a37914e7bfb199c65a71b64b9f (patch) | |
tree | a37d6665ae4c4f156e0ff27616bfe8ea01791846 /src/main/java/com/google/devtools/build/lib/packages | |
parent | 25f37123a0b33484acedaab2ef7c78d50365c43a (diff) |
Integrate memoization into standard serialization. This involves a number of large changes:
1. SerializationContext and DeserializationContext become the owners of the Memoizer if requested. They produce new versions of themselves on demand that are memoization-aware. Because of intricacies of Skylark that I do not fully understand, we inject a Mutability object when starting memoization, and so to be conservative, that injection starts up a new memoization frame, nested if we were already memoizing, just like before. It would be nice to decouple this injection from memoization in the future.
2. MemoizingCodec is deleted, but really ObjectCodec becomes MemoizingCodec, so it lives on. BaseCodec is deleted since it now has only one implementation.
3. The simplified model of registering MemoizingCodecs is adopted for ObjectCodecs: all codecs are registered based on their #getEncodedClass and #additionalEncodedSubclasses. This also allows us to register codecs that are defined using tricky parameter types, since we're no longer trying to reflectively examine them. This required a clean-up of such codecs, and the addition of ArrayListCodec to stop NullableListCodec from making lists unmodifiable when they shouldn't be.
4. @AutoCodec is extended to allow users to specify that memoization should start with this codec.
To ensure bit-equivalence, SkyKeySerializer disables memoization.
PiperOrigin-RevId: 188918251
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
3 files changed, 105 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 045520aa6d..61878dd4ef 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -57,6 +57,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nullable; @@ -2251,6 +2252,51 @@ public final class Attribute implements Comparable<Attribute> { return name.compareTo(other.name); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Attribute attribute = (Attribute) o; + return Objects.equals(name, attribute.name) + && Objects.equals(type, attribute.type) + && Objects.equals(propertyFlags, attribute.propertyFlags) + && Objects.equals(defaultValue, attribute.defaultValue) + && Objects.equals(configTransition, attribute.configTransition) + && Objects.equals(splitTransitionProvider, attribute.splitTransitionProvider) + && Objects.equals(allowedRuleClassesForLabels, attribute.allowedRuleClassesForLabels) + && Objects.equals( + allowedRuleClassesForLabelsWarning, attribute.allowedRuleClassesForLabelsWarning) + && Objects.equals(allowedFileTypesForLabels, attribute.allowedFileTypesForLabels) + && Objects.equals(validityPredicate, attribute.validityPredicate) + && Objects.equals(condition, attribute.condition) + && Objects.equals(allowedValues, attribute.allowedValues) + && Objects.equals(requiredProviders, attribute.requiredProviders) + && Objects.equals(aspects, attribute.aspects); + } + + @Override + public int hashCode() { + return Objects.hash( + name, + type, + propertyFlags, + defaultValue, + configTransition, + splitTransitionProvider, + allowedRuleClassesForLabels, + allowedRuleClassesForLabelsWarning, + allowedFileTypesForLabels, + validityPredicate, + condition, + allowedValues, + requiredProviders, + aspects); + } + /** * Returns a replica builder of this Attribute. */ diff --git a/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java b/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java index 1551d70f35..2f026c84a2 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java @@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import java.util.Objects; import java.util.function.Function; import java.util.function.Predicate; import javax.annotation.Nullable; @@ -303,6 +304,25 @@ public final class RequiredProviders { } } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RequiredProviders that = (RequiredProviders) o; + return constraint == that.constraint + && Objects.equals(nativeProviders, that.nativeProviders) + && Objects.equals(skylarkProviders, that.skylarkProviders); + } + + @Override + public int hashCode() { + return Objects.hash(constraint, nativeProviders, skylarkProviders); + } + /** * A builder for {@link RequiredProviders} that accepts any dependency * unless restriction provider sets are added. diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkDefinedAspect.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkDefinedAspect.java index 14ec9d646e..e8cd11ae55 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkDefinedAspect.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkDefinedAspect.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Type; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** A Skylark value that is a result of an 'aspect(..)' function call. */ @AutoCodec @@ -224,4 +225,42 @@ public class SkylarkDefinedAspect implements SkylarkExportable, SkylarkAspect { } attrBuilder.aspect(this, loc); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SkylarkDefinedAspect that = (SkylarkDefinedAspect) o; + return Objects.equals(implementation, that.implementation) + && Objects.equals(attributeAspects, that.attributeAspects) + && Objects.equals(attributes, that.attributes) + && Objects.equals(requiredAspectProviders, that.requiredAspectProviders) + && Objects.equals(provides, that.provides) + && Objects.equals(paramAttributes, that.paramAttributes) + && Objects.equals(fragments, that.fragments) + && Objects.equals(hostTransition, that.hostTransition) + && Objects.equals(hostFragments, that.hostFragments) + && Objects.equals(requiredToolchains, that.requiredToolchains) + && Objects.equals(aspectClass, that.aspectClass); + } + + @Override + public int hashCode() { + return Objects.hash( + implementation, + attributeAspects, + attributes, + requiredAspectProviders, + provides, + paramAttributes, + fragments, + hostTransition, + hostFragments, + requiredToolchains, + aspectClass); + } } |