bazel syntax: hide EvalUtils.execToplevelStatement
All file execution now happens through EvalUtils.exec(StarlarkFile)
or EvalUtils.execOrEval (which I plan to eliminate in a followup).
Clients do not execute individual statements.
This requires a temporary hack: StarlarkThread.postAssignHook is a
hook that clients can install to be notified of each assignment at top
level. SkylarkImportLookupFunction uses it to "export" values such as
rules, aspects, and transitions during execution, instead of at the
end of execution. (The behavior will be changed soon; see unknown commit
and b/65374671.)
This may seem like two steps forward and one back, but it will allow us
to develop the EvalUtils API, in particular, turning the top-level statements
of a StarlarkFile into a StarlarkFunction, leading to a consistent treatment
of the call stack.
Also:
- EvalUtils.debugExec is now expressible in terms of the API,
and has been moved up into the debugger.
- Identifier.boundIdentifiers is no longer public.
- Minor simplifications to tests.
PiperOrigin-RevId: 273741627
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
index 5bd720a..e1a33ab 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
@@ -824,6 +824,9 @@
*/
@Nullable private Continuation continuation;
+ /** A hook for notifications of assignments at top level. */
+ PostAssignHook postAssignHook;
+
/**
* Enters a scope by saving state to a new Continuation
*
@@ -1063,6 +1066,23 @@
}
/**
+ * Specifies a hook function to be run after each assignment at top level.
+ *
+ * <p>This is a short-term hack to allow us to consolidate all StarlarkFile execution in one place
+ * even while SkylarkImportLookupFunction implements the old "export" behavior, in which rules,
+ * aspects and providers are "exported" as soon as they are assigned, not at the end of file
+ * execution.
+ */
+ public void setPostAssignHook(PostAssignHook postAssignHook) {
+ this.postAssignHook = postAssignHook;
+ }
+
+ /** A hook for notifications of assignments at top level. */
+ public interface PostAssignHook {
+ void assign(String name, Object value);
+ }
+
+ /**
* Modifies a binding in the current Frame of this StarlarkThread, as would an {@link
* AssignmentStatement}. Does not try to modify an inherited binding. This will shadow any
* inherited binding, which may be an error that you want to guard against before calling this
@@ -1199,22 +1219,6 @@
return Eval.eval(this, expr);
}
- /** Executes a Skylark file (sequence of statements) in this thread. (Debugger API) */
- // TODO(adonovan): push this up into the debugger once the exec API is finalized.
- public void debugExec(ParserInput input) throws SyntaxError, EvalException, InterruptedException {
- StarlarkFile file = StarlarkFile.parse(input);
- ValidationEnvironment.validateFile(file, getGlobals(), getSemantics(), /*isBuildFile=*/ false);
- if (!file.ok()) {
- throw new SyntaxError(file.errors());
- }
- for (Statement stmt : file.getStatements()) {
- if (stmt instanceof LoadStatement) {
- throw new EvalException(stmt.getLocation(), "cannot execute load statements in debugger");
- }
- }
- Eval.execStatements(this, file.getStatements());
- }
-
/**
* Returns the stack frames corresponding of the context's current (paused) state. (Debugger API)
*