Make PackageFactory the canonical home for Starlark env business logic

This moves the computation of the predeclared environment for bzl files from StarlarkBuiltinsFunction to PackageFactory. This will allow PackageFactory to encapsulate decisions about what symbols can and can't be overridden, reducing its API surface. StarlarkBuiltinsFunction only needs to obtain the exports dicts and call into PackageFactory. At the same time, we simplify BzlLoadFunction by moving its cache of (uninjected) predeclared environments into PackageFactory.

This change will make it easier for ASTFileLookupFunction to access the names of predeclared symbols, which will soon vary depending on the type of bzl being loaded.

(Thanks to adonovan@ for suggesting that PackageFactory be the one to manage the environment.)

PackageFactory:
- Added fields to hold the top-level environments for the three dialects of bzl files -- BUILD-loaded, WORKSPACE-loaded, and builtins-loaded. For BUILD-loaded ones, we store the uninjected environment as a field, but the injected environment must be computed dynamically. (The other dialects don't support injection.) Note that in time, BUILD-loaded and WORKSPACE-loaded bzls should converge.
- Renamed the existing two fields that hold the (uninjected) contents of "native" for consistency.
- Added create*() static initializer methods, with code and TODOs taken from StarlarkBuiltinsFunction.
- Moved the method for creating the injected environment to here from StarlarkBuiltinsFunction.

Work toward #11437

RELNOTES: None
PiperOrigin-RevId: 327659505
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
index 7673f61..52b7472 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
@@ -94,15 +94,6 @@
   // computeInline() entry point.
   private final PackageFactory packageFactory;
 
-  // Used for BUILD .bzls if injection is disabled.
-  // TODO(#11437): Remove once injection is on unconditionally.
-  private final ImmutableMap<String, Object> predeclaredForBuildBzlWithoutInjection;
-
-  // Predeclareds for workspace .bzls and builtins .bzls are not subject to builtins injection, so
-  // these environments are stored globally.
-  private final ImmutableMap<String, Object> predeclaredForWorkspaceBzl;
-  private final ImmutableMap<String, Object> predeclaredForBuiltinsBzl;
-
   // Handles retrieving ASTFileLookupValues, either by calling Skyframe or by inlining
   // ASTFileLookupFunction; the latter is not to be confused with inlining of BzlLoadFunction. See
   // comment in create() for rationale.
@@ -118,12 +109,6 @@
       ASTManager astManager,
       @Nullable CachedBzlLoadDataManager cachedBzlLoadDataManager) {
     this.packageFactory = packageFactory;
-    this.predeclaredForBuildBzlWithoutInjection =
-        StarlarkBuiltinsFunction.createPredeclaredForBuildBzlWithoutInjection(packageFactory);
-    this.predeclaredForWorkspaceBzl =
-        StarlarkBuiltinsFunction.createPredeclaredForWorkspaceBzl(packageFactory);
-    this.predeclaredForBuiltinsBzl =
-        StarlarkBuiltinsFunction.createPredeclaredForBuiltinsBzl(packageFactory);
     this.astManager = astManager;
     this.cachedBzlLoadDataManager = cachedBzlLoadDataManager;
   }
@@ -865,7 +850,7 @@
     if (key instanceof BzlLoadValue.KeyForBuild) {
       // TODO(#11437): Remove ability to disable injection by setting flag to empty string.
       if (starlarkSemantics.experimentalBuiltinsBzlPath().isEmpty()) {
-        return predeclaredForBuildBzlWithoutInjection;
+        return packageFactory.getUninjectedBuildBzlEnv();
       }
       StarlarkBuiltinsValue starlarkBuiltinsValue;
       try {
@@ -891,9 +876,9 @@
       fp.addBytes(starlarkBuiltinsValue.transitiveDigest);
       return starlarkBuiltinsValue.predeclaredForBuildBzl;
     } else if (key instanceof BzlLoadValue.KeyForWorkspace) {
-      return predeclaredForWorkspaceBzl;
+      return packageFactory.getWorkspaceBzlEnv();
     } else if (key instanceof BzlLoadValue.KeyForBuiltins) {
-      return predeclaredForBuiltinsBzl;
+      return packageFactory.getBuiltinsBzlEnv();
     } else {
       throw new AssertionError("Unknown key type: " + key.getClass());
     }