Create infrastructure to restrict top-level Starlark objects by flag

As proof of concept, this restricts AnalysisFailureInfo and AnalysisTestResultInfo to be unavailable as top-level symbols without --experimental_analysis_testing_improvements . This is technically a breaking change, but these symbols were unusable before this change, documented as being experimental, and are not included in any binary release of Bazel.

RELNOTES: None.
PiperOrigin-RevId: 217593936
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
index 0240a67..3605c61 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
@@ -33,7 +33,10 @@
 @AutoValue
 public abstract class SkylarkSemantics {
 
-  /** Enum where each element represents a skylark semantics flag. */
+  /**
+   * Enum where each element represents a skylark semantics flag. The name of each value should
+   * be the exact name of the flag transformed to upper case (for error representation).
+   */
   public enum FlagIdentifier {
     EXPERIMENTAL_ANALYSIS_TESTING_IMPROVEMENTS(
         SkylarkSemantics::experimentalAnalysisTestingImprovements),
@@ -52,6 +55,14 @@
     FlagIdentifier(Function<SkylarkSemantics, Boolean> semanticsFunction) {
       this.semanticsFunction = semanticsFunction;
     }
+
+    /**
+     * Returns the name of the flag that this identifier controls. For example, EXPERIMENTAL_FOO
+     * would return 'experimental_foo'.
+     */
+    public String getFlagName() {
+      return this.name().toLowerCase();
+    }
   }
 
   /**