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
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
index eb06a10..86d9c36 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
@@ -24,6 +24,8 @@
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.events.EventKind;
 import com.google.devtools.build.lib.events.Location;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.Memoization;
 import com.google.devtools.build.lib.syntax.Mutability.Freezable;
 import com.google.devtools.build.lib.syntax.Mutability.MutabilityException;
 import com.google.devtools.build.lib.util.Fingerprint;
@@ -473,6 +475,9 @@
 
   /** An Extension to be imported with load() into a BUILD or .bzl file. */
   @Immutable
+  // TODO(janakr,brandjon): Do Extensions actually have to start their own memoization? Or can we
+  // have a node higher up in the hierarchy inject the mutability?
+  @AutoCodec(memoization = Memoization.START_MEMOIZING)
   public static final class Extension {
 
     private final ImmutableMap<String, Object> bindings;
@@ -485,6 +490,7 @@
     private final String transitiveContentHashCode;
 
     /** Constructs with the given hash code and bindings. */
+    @AutoCodec.Instantiator
     public Extension(ImmutableMap<String, Object> bindings, String transitiveContentHashCode) {
       this.bindings = bindings;
       this.transitiveContentHashCode = transitiveContentHashCode;