Remove BuildConfiguration and PlatformInfo from the
RegisteredExecutionPlatformsFunction.

PiperOrigin-RevId: 185947540
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
index 8e20302..df5bb86 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
@@ -16,22 +16,15 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.PlatformConfiguration;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
-import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
-import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.packages.Package;
-import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredValueCreationException;
 import com.google.devtools.build.skyframe.SkyFunction;
 import com.google.devtools.build.skyframe.SkyFunctionException;
-import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
 import com.google.devtools.build.skyframe.SkyKey;
 import com.google.devtools.build.skyframe.SkyValue;
-import com.google.devtools.build.skyframe.ValueOrException;
 import java.util.List;
-import java.util.Map;
 import javax.annotation.Nullable;
 
 /** {@link SkyFunction} that returns all registered execution platforms available. */
@@ -42,7 +35,13 @@
   public SkyValue compute(SkyKey skyKey, Environment env)
       throws SkyFunctionException, InterruptedException {
 
-    BuildConfiguration configuration = (BuildConfiguration) skyKey.argument();
+    BuildConfigurationValue buildConfigurationValue =
+        (BuildConfigurationValue)
+            env.getValue(((RegisteredExecutionPlatformsValue.Key) skyKey).getConfigurationKey());
+    if (env.valuesMissing()) {
+      return null;
+    }
+    BuildConfiguration configuration = buildConfigurationValue.getConfiguration();
 
     ImmutableList.Builder<Label> registeredExecutionPlatformLabels = new ImmutableList.Builder<>();
 
@@ -61,14 +60,14 @@
     registeredExecutionPlatformLabels.addAll(workspaceExecutionPlatforms);
 
     // Load the configured target for each, and get the declared execution platforms providers.
-    ImmutableList<PlatformInfo> registeredExecutionPlatforms =
+    ImmutableList<ConfiguredTargetKey> registeredExecutionPlatformKeys =
         configureRegisteredExecutionPlatforms(
-            env, configuration, registeredExecutionPlatformLabels.build());
+            configuration, registeredExecutionPlatformLabels.build());
     if (env.valuesMissing()) {
       return null;
     }
 
-    return RegisteredExecutionPlatformsValue.create(registeredExecutionPlatforms);
+    return RegisteredExecutionPlatformsValue.create(registeredExecutionPlatformKeys);
   }
 
   /**
@@ -90,47 +89,15 @@
     return externalPackage.getRegisteredExecutionPlatformLabels();
   }
 
-  private ImmutableList<PlatformInfo> configureRegisteredExecutionPlatforms(
-      Environment env, BuildConfiguration configuration, List<Label> labels)
-      throws InterruptedException, RegisteredExecutionPlatformsFunctionException {
-    ImmutableList<SkyKey> keys =
+  private ImmutableList<ConfiguredTargetKey> configureRegisteredExecutionPlatforms(
+      BuildConfiguration configuration, List<Label> labels) {
+    ImmutableList<ConfiguredTargetKey> keys =
         labels
             .stream()
             .map(label -> ConfiguredTargetKey.of(label, configuration))
             .collect(ImmutableList.toImmutableList());
 
-    Map<SkyKey, ValueOrException<ConfiguredValueCreationException>> values =
-        env.getValuesOrThrow(keys, ConfiguredValueCreationException.class);
-    ImmutableList.Builder<PlatformInfo> platforms = new ImmutableList.Builder<>();
-    boolean valuesMissing = false;
-    for (SkyKey key : keys) {
-      ConfiguredTargetKey configuredTargetKey = (ConfiguredTargetKey) key.argument();
-      Label platformLabel = configuredTargetKey.getLabel();
-      try {
-        ValueOrException<ConfiguredValueCreationException> valueOrException = values.get(key);
-        if (valueOrException.get() == null) {
-          valuesMissing = true;
-          continue;
-        }
-        ConfiguredTarget target =
-            ((ConfiguredTargetValue) valueOrException.get()).getConfiguredTarget();
-        PlatformInfo platformInfo = PlatformProviderUtils.platform(target);
-
-        if (platformInfo == null) {
-          throw new RegisteredExecutionPlatformsFunctionException(
-              new InvalidExecutionPlatformLabelException(platformLabel), Transience.PERSISTENT);
-        }
-        platforms.add(platformInfo);
-      } catch (ConfiguredValueCreationException e) {
-        throw new RegisteredExecutionPlatformsFunctionException(
-            new InvalidExecutionPlatformLabelException(platformLabel, e), Transience.PERSISTENT);
-      }
-    }
-
-    if (valuesMissing) {
-      return null;
-    }
-    return platforms.build();
+    return keys;
   }
 
   @Nullable
@@ -138,47 +105,4 @@
   public String extractTag(SkyKey skyKey) {
     return null;
   }
-
-  /**
-   * Used to indicate that the given {@link Label} represents a {@link ConfiguredTarget} which is
-   * not a valid {@link PlatformInfo} provider.
-   */
-  public static final class InvalidExecutionPlatformLabelException extends Exception {
-
-    private final Label invalidLabel;
-
-    public InvalidExecutionPlatformLabelException(Label invalidLabel) {
-      super(
-          String.format(
-              "invalid registered execution platform '%s': "
-                  + "target does not provide the PlatformInfo provider",
-              invalidLabel));
-      this.invalidLabel = invalidLabel;
-    }
-
-    public InvalidExecutionPlatformLabelException(
-        Label invalidLabel, ConfiguredValueCreationException e) {
-      super(
-          String.format(
-              "invalid registered execution platform '%s': %s", invalidLabel, e.getMessage()),
-          e);
-      this.invalidLabel = invalidLabel;
-    }
-
-    public Label getInvalidLabel() {
-      return invalidLabel;
-    }
-  }
-
-  /**
-   * Used to declare all the exception types that can be wrapped in the exception thrown by {@link
-   * #compute}.
-   */
-  public static class RegisteredExecutionPlatformsFunctionException extends SkyFunctionException {
-
-    public RegisteredExecutionPlatformsFunctionException(
-        InvalidExecutionPlatformLabelException cause, Transience transience) {
-      super(cause, transience);
-    }
-  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
index e242ff6..03d4e92 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
@@ -16,11 +16,13 @@
 
 import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
-import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
-import com.google.devtools.build.skyframe.LegacySkyKey;
+import com.google.common.collect.Interner;
+import com.google.devtools.build.lib.concurrent.BlazeInterners;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.skyframe.SkyFunctionName;
 import com.google.devtools.build.skyframe.SkyKey;
 import com.google.devtools.build.skyframe.SkyValue;
+import java.util.Objects;
 
 /**
  * A value which represents every execution platform known to Bazel and available to run actions.
@@ -29,15 +31,54 @@
 public abstract class RegisteredExecutionPlatformsValue implements SkyValue {
 
   /** Returns the {@link SkyKey} for {@link RegisteredExecutionPlatformsValue}s. */
-  public static SkyKey key(BuildConfiguration configuration) {
-    return LegacySkyKey.create(SkyFunctions.REGISTERED_EXECUTION_PLATFORMS, configuration);
+  public static SkyKey key(BuildConfigurationValue.Key configurationKey) {
+    return Key.of(configurationKey);
+  }
+
+  @AutoCodec
+  static class Key implements SkyKey {
+    private static final Interner<Key> interners = BlazeInterners.newWeakInterner();
+    private final BuildConfigurationValue.Key configurationKey;
+
+    private Key(BuildConfigurationValue.Key configurationKey) {
+      this.configurationKey = configurationKey;
+    }
+
+    @AutoCodec.Instantiator
+    @AutoCodec.VisibleForSerialization
+    static Key of(BuildConfigurationValue.Key configurationKey) {
+      return interners.intern(new Key(configurationKey));
+    }
+
+    @Override
+    public SkyFunctionName functionName() {
+      return SkyFunctions.REGISTERED_EXECUTION_PLATFORMS;
+    }
+
+    BuildConfigurationValue.Key getConfigurationKey() {
+      return configurationKey;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (!(obj instanceof Key)) {
+        return false;
+      }
+      Key that = (Key) obj;
+      return Objects.equals(this.configurationKey, that.configurationKey);
+    }
+
+    @Override
+    public int hashCode() {
+      return configurationKey.hashCode();
+    }
   }
 
   static RegisteredExecutionPlatformsValue create(
-      Iterable<PlatformInfo> registeredExecutionPlatforms) {
+      Iterable<ConfiguredTargetKey> registeredExecutionPlatformKeys) {
     return new AutoValue_RegisteredExecutionPlatformsValue(
-        ImmutableList.copyOf(registeredExecutionPlatforms));
+        ImmutableList.copyOf(registeredExecutionPlatformKeys));
   }
 
-  public abstract ImmutableList<PlatformInfo> registeredExecutionPlatforms();
+  public abstract ImmutableList<ConfiguredTargetKey> registeredExecutionPlatformKeys();
 }
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java
index 08319a4..0d3e155 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java
@@ -20,7 +20,6 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.testing.EqualsTester;
 import com.google.common.truth.IterableSubject;
-import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
 import com.google.devtools.build.lib.analysis.platform.PlatformInfo.DuplicateConstraintException;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.rules.platform.ToolchainTestCase;
@@ -55,31 +54,31 @@
   protected static IterableSubject assertExecutionPlatformLabels(
       RegisteredExecutionPlatformsValue registeredExecutionPlatformsValue) {
     assertThat(registeredExecutionPlatformsValue).isNotNull();
-    ImmutableList<PlatformInfo> declaredExecutionPlatforms =
-        registeredExecutionPlatformsValue.registeredExecutionPlatforms();
-    List<Label> labels = collectExecutionPlatformLabels(declaredExecutionPlatforms);
+    ImmutableList<ConfiguredTargetKey> declaredExecutionPlatformKeys =
+        registeredExecutionPlatformsValue.registeredExecutionPlatformKeys();
+    List<Label> labels = collectExecutionPlatformLabels(declaredExecutionPlatformKeys);
     return assertThat(labels);
   }
 
   protected static List<Label> collectExecutionPlatformLabels(
-      List<PlatformInfo> executionPlatforms) {
-    return executionPlatforms
+      List<ConfiguredTargetKey> executionPlatformKeys) {
+    return executionPlatformKeys
         .stream()
-        .map((executionPlatform -> executionPlatform.label()))
+        .map(ConfiguredTargetKey::getLabel)
         .collect(Collectors.toList());
   }
 
   @Test
   public void testRegisteredExecutionPlatforms() throws Exception {
     // Request the executionPlatforms.
-    SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfig);
+    SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey);
     EvaluationResult<RegisteredExecutionPlatformsValue> result =
         requestExecutionPlatformsFromSkyframe(executionPlatformsKey);
     assertThatEvaluationResult(result).hasNoError();
     assertThatEvaluationResult(result).hasEntryThat(executionPlatformsKey).isNotNull();
 
     RegisteredExecutionPlatformsValue value = result.get(executionPlatformsKey);
-    assertThat(value.registeredExecutionPlatforms()).isEmpty();
+    assertThat(value.registeredExecutionPlatformKeys()).isEmpty();
   }
 
   @Test
@@ -94,7 +93,7 @@
     rewriteWorkspace("register_execution_platforms('//extra:execution_platform_2')");
     useConfiguration("--extra_execution_platforms=//extra:execution_platform_1");
 
-    SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfig);
+    SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey);
     EvaluationResult<RegisteredExecutionPlatformsValue> result =
         requestExecutionPlatformsFromSkyframe(executionPlatformsKey);
     assertThatEvaluationResult(result).hasNoError();
@@ -108,24 +107,6 @@
   }
 
   @Test
-  public void testRegisteredExecutionPlatforms_notExecutionPlatform() throws Exception {
-    rewriteWorkspace("register_execution_platforms(", "    '//error:not_an_execution_platform')");
-    scratch.file("error/BUILD", "filegroup(name = 'not_an_execution_platform')");
-
-    // Request the executionPlatforms.
-    SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfig);
-    EvaluationResult<RegisteredExecutionPlatformsValue> result =
-        requestExecutionPlatformsFromSkyframe(executionPlatformsKey);
-    assertThatEvaluationResult(result)
-        .hasErrorEntryForKeyThat(executionPlatformsKey)
-        .hasExceptionThat()
-        .hasMessageThat()
-        .contains(
-            "invalid registered execution platform '//error:not_an_execution_platform': "
-                + "target does not provide the PlatformInfo provider");
-  }
-
-  @Test
   public void testRegisteredExecutionPlatforms_reload() throws Exception {
     scratch.file(
         "platform/BUILD",
@@ -134,7 +115,7 @@
 
     rewriteWorkspace("register_execution_platforms('//platform:execution_platform_1')");
 
-    SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfig);
+    SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey);
     EvaluationResult<RegisteredExecutionPlatformsValue> result =
         requestExecutionPlatformsFromSkyframe(executionPlatformsKey);
     assertThatEvaluationResult(result).hasNoError();
@@ -144,7 +125,7 @@
     // Re-write the WORKSPACE.
     rewriteWorkspace("register_execution_platforms('//platform:execution_platform_2')");
 
-    executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfig);
+    executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey);
     result = requestExecutionPlatformsFromSkyframe(executionPlatformsKey);
     assertThatEvaluationResult(result).hasNoError();
     assertExecutionPlatformLabels(result.get(executionPlatformsKey))
@@ -154,21 +135,21 @@
   @Test
   public void testRegisteredExecutionPlatformsValue_equalsAndHashCode()
       throws DuplicateConstraintException {
-    PlatformInfo executionPlatform1 =
-        PlatformInfo.builder().setLabel(makeLabel("//test:executionPlatform")).build();
-    PlatformInfo executionPlatform2 =
-        PlatformInfo.builder().setLabel(makeLabel("//test:executionPlatform2")).build();
+    ConfiguredTargetKey executionPlatformKey1 =
+        ConfiguredTargetKey.of(makeLabel("//test:executionPlatform1"), null, false);
+    ConfiguredTargetKey executionPlatformKey2 =
+        ConfiguredTargetKey.of(makeLabel("//test:executionPlatform2"), null, false);
 
     new EqualsTester()
         .addEqualityGroup(
             RegisteredExecutionPlatformsValue.create(
-                ImmutableList.of(executionPlatform1, executionPlatform2)),
+                ImmutableList.of(executionPlatformKey1, executionPlatformKey2)),
             RegisteredExecutionPlatformsValue.create(
-                ImmutableList.of(executionPlatform1, executionPlatform2)))
+                ImmutableList.of(executionPlatformKey1, executionPlatformKey2)))
         .addEqualityGroup(
-            RegisteredExecutionPlatformsValue.create(ImmutableList.of(executionPlatform1)),
-            RegisteredExecutionPlatformsValue.create(ImmutableList.of(executionPlatform2)),
+            RegisteredExecutionPlatformsValue.create(ImmutableList.of(executionPlatformKey1)),
+            RegisteredExecutionPlatformsValue.create(ImmutableList.of(executionPlatformKey2)),
             RegisteredExecutionPlatformsValue.create(
-                ImmutableList.of(executionPlatform2, executionPlatform1)));
+                ImmutableList.of(executionPlatformKey2, executionPlatformKey1)));
   }
 }