Refactor Skylark Environment-s
Make Environment-s freezable: Introduce a class Mutability
as a revokable capability to mutate objects in an Environment.
For now, only Environment-s carry this capability.
Make sure that every Mutability is revoked in the same function that create...
This reinstates a change that previously rolled-back because it broke the
serializability of SkylarkLookupValue. Bad news: serializing it succeeds for the
wrong reason, because a SkylarkEnvironment was stored as a result (now an
Environment.Extension) that was Serializable but inherited its bindings from an Environment (now an Environment.BaseExtension) which wasn't Serializable.
Apparently, Java doesn't try to serialize the bindings then (or at least doesn't
error out when it fails), because these bindings map variable names to pretty
arbitrary objects, and a lot of those we find in practice aren't Serializable.
Thus the current code passes the same tests as the previous code, but obviously
the serialization is just as ineffective as it used to be.
--
MOS_MIGRATED_REVID=102776694
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClassProvider.java
index 958d88a..e2ce1ba 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClassProvider.java
@@ -15,12 +15,15 @@
package com.google.devtools.build.lib.packages;
import com.google.devtools.build.lib.events.EventHandler;
-import com.google.devtools.build.lib.syntax.SkylarkEnvironment;
-import com.google.devtools.build.lib.syntax.ValidationEnvironment;
+import com.google.devtools.build.lib.syntax.Environment;
+import com.google.devtools.build.lib.syntax.Environment.Extension;
+import com.google.devtools.build.lib.syntax.Mutability;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Map;
+import javax.annotation.Nullable;
+
/**
* The collection of the supported build rules. Provides an Environment for Skylark rule creation.
*/
@@ -47,17 +50,19 @@
Map<String, Class<? extends AspectFactory<?, ?, ?>>> getAspectFactoryMap();
/**
- * Returns a new Skylark Environment instance for rule creation. Implementations need to be
- * thread safe.
+ * Returns a new Skylark Environment instance for rule creation.
+ * Implementations need to be thread safe.
+ * Be sure to close() the mutability before you return the results of said evaluation.
+ * @param mutability the Mutability for the current evaluation context
+ * @param eventHandler the EventHandler for warnings, errors, etc.
+ * @param astFileContentHashCode the hash code identifying this environment.
+ * @return an Environment, in which to evaluate load time skylark forms.
*/
- SkylarkEnvironment createSkylarkRuleClassEnvironment(
- EventHandler eventHandler, String astFileContentHashCode);
-
- /**
- * Returns a validation environment for static analysis of skylark files.
- * The environment has to contain all built-in functions and objects.
- */
- ValidationEnvironment getSkylarkValidationEnvironment();
+ Environment createSkylarkRuleClassEnvironment(
+ Mutability mutability,
+ EventHandler eventHandler,
+ @Nullable String astFileContentHashCode,
+ @Nullable Map<PathFragment, Extension> importMap);
/**
* Returns the default content of the WORKSPACE file.