Environment: introduce method for more specific lookups

Callers should know in which frame a value is defined. This is needed for
static name resolution. It avoids extra lookups and will allow other
performance improvements.

https://github.com/bazelbuild/bazel/issues/5637

RELNOTES: None.
PiperOrigin-RevId: 210762449
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 f0f695e..7b4da3f 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
@@ -1074,16 +1074,38 @@
   }
 
   /**
-   * Returns the value of a variable defined in the current lexical frame. Do not search in any
-   * parent scope. This function should be used once the AST has been analysed and we know which
-   * variables are local.
+   * Returns the value of a variable defined in Local scope. Do not search in any parent scope. This
+   * function should be used once the AST has been analysed and we know which variables are local.
    */
   public Object localLookup(String varname) {
     return lexicalFrame.get(varname);
   }
 
   /**
+   * Returns the value of a variable defined in the Module scope (e.g. global variables,
+   * functions).
+   */
+  public Object moduleLookup(String varname) {
+    return globalFrame.get(varname);
+  }
+
+  /** Returns the value of a variable defined in the Universe scope (builtins). */
+  public Object universeLookup(String varname) {
+    // TODO(laurentlb): We should distinguish between Module and Universe. Values in Module can
+    // shadow those in Universe.
+    return globalFrame.get(varname);
+  }
+
+  /** Returns the value of a variable defined with setupDynamic. */
+  public Object dynamicLookup(String varname) {
+    return dynamicFrame.get(varname);
+  }
+
+  /**
    * Returns the value from the environment whose name is "varname" if it exists, otherwise null.
+   *
+   * <p>TODO(laurentlb): Remove this method. Callers should know where the value is defined and use
+   * the corresponding method (e.g. localLookup or moduleLookup).
    */
   public Object lookup(String varname) {
     // Lexical frame takes precedence, then globals, then dynamics.