Customize the builtins bzl environment

This makes @builtins bzls able to load a new "_internal" module that will hold features not accessible to ordinary bzls. In particular, this will include the "original" native module field values before they get optionally replaced by builtins injection, as well as a view of the current StarlarkSemantics flags.

This changes also makes @builtins bzls unable to access the top-level "native" object; we will soon also prohibit direct access to other top-level rule logic symbols like CcInfo. (Rationale: These are the very symbols that @builtins bzls are helping to define for ordinary users. It would be confusing if regular bzls and @builtins bzls attached different meanings to the same names.)

To enable this change, ASTFileLookupFunction now retrieves the predeclared environment from PackageFactory using similar methods as BzlLoadFunction, instead of blindly applying the same environment to all bzls. As it turns out, ASTFileLookupFunction doesn't need access to the injected environment since builtins injection only changes the definitions of symbols, not whether or not the symbol exists at all. Therefore ASTFileLookupFunction doesn't need to request StarlarkBuiltinsValue from Skyframe.

A new builtins ASTFileLookupValue key type is created, and it is wired into the corresponding key type for BzlLoadValue (getASTKey()).

BuiltinsInjectionTest:
- Renamed some test cases to eliminate boilerplate prefix
- Split the test that @builtins bzls can't access stuff into two cases: "native", and rule logic symbols like CcInfo. The latter isn't implemented yet, so its assertions will be flipped.
- Rename "builtins_dummy.bzl" in test case for consistency with other test cases; simplify exports.bzl to remove irrelevant setup in a test case
- Add tests that @builtins bzls can access _internal and ordinary bzls can't

Drive-bys: Rename a test case in BzlLoadFunctionTest for clarity. Add @Nullable to an override in Module.java where the parent method already has it.

Word toward #11437.

RELNOTES: None
PiperOrigin-RevId: 328146383
diff --git a/src/main/java/com/google/devtools/build/lib/packages/InternalModule.java b/src/main/java/com/google/devtools/build/lib/packages/InternalModule.java
new file mode 100644
index 0000000..817f5bb
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/packages/InternalModule.java
@@ -0,0 +1,54 @@
+// Copyright 2020 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.packages;
+
+import com.google.devtools.build.lib.syntax.Printer;
+import com.google.devtools.build.lib.syntax.StarlarkValue;
+import net.starlark.java.annot.StarlarkBuiltin;
+import net.starlark.java.annot.StarlarkDocumentationCategory;
+
+// TODO(#11437): Factor an API out into skylarkbuildapi, for stardoc's benefit. Otherwise, stardoc
+// can't run on @builtins bzls.
+/** The {@code _internal} Starlark object, visible only to {@code @builtins} .bzls. */
+@StarlarkBuiltin(
+    name = "_internal",
+    category = StarlarkDocumentationCategory.BUILTIN,
+    documented = false,
+    doc =
+        "A module accessible only to @builtins .bzls, that permits access to the original "
+            + "(uninjected) native builtins, as well as internal-only symbols not accessible to "
+            + "users.")
+public class InternalModule implements StarlarkValue {
+
+  // TODO(#11437): Can't use a singleton once we're re-exporting fields of the native object.
+  public static final InternalModule INSTANCE = new InternalModule();
+
+  private InternalModule() {}
+
+  @Override
+  public void repr(Printer printer) {
+    printer.append("<_internal module>");
+  }
+
+  @Override
+  public boolean isImmutable() {
+    return true;
+  }
+
+  @Override
+  public boolean isHashable() {
+    return true;
+  }
+}