Make the distinction between "global frame" and "lexical frame" explicit. As a nice consequence, this lets us reduce GC churn since we no longer need to create a frame instance for the lexical frame at a callsite of either a function when the environment is frozen or a builtin function (since builtins cannot modify bindings in their lexical frame).
RELNOTES: None
PiperOrigin-RevId: 187495787
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java
index a7fcf19..b4fc95f 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java
@@ -19,6 +19,7 @@
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
+import com.google.devtools.build.lib.syntax.Environment.LexicalFrame;
/**
* The actual function registered in the environment. This function is defined in the
@@ -29,14 +30,14 @@
private final ImmutableList<Statement> statements;
// we close over the globals at the time of definition
- private final Environment.Frame definitionGlobals;
+ private final Environment.GlobalFrame definitionGlobals;
public UserDefinedFunction(
String name,
Location loc,
FunctionSignature.WithValues<Object, SkylarkType> signature,
ImmutableList<Statement> statements,
- Environment.Frame definitionGlobals) {
+ Environment.GlobalFrame definitionGlobals) {
super(name, signature, loc);
this.statements = statements;
this.definitionGlobals = definitionGlobals;
@@ -46,7 +47,7 @@
return statements;
}
- public Environment.Frame getDefinitionGlobals() {
+ public Environment.GlobalFrame getDefinitionGlobals() {
return definitionGlobals;
}
@@ -64,7 +65,7 @@
Profiler.instance().startTask(ProfilerTask.SKYLARK_USER_FN, getName());
try {
- env.enterScope(this, ast, definitionGlobals);
+ env.enterScope(this, LexicalFrame.create(env.mutability()), ast, definitionGlobals);
ImmutableList<String> names = signature.getSignature().getNames();
// Registering the functions's arguments as variables in the local Environment