Delete KeyedConfiguredTarget.

No longer needed since ConfiguredTargetKey is embedded in ConfiguredTarget.

PiperOrigin-RevId: 535908504
Change-Id: Id0b11ae876d32a94438c7409136c0c52dcadf1ad
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java b/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java
index 1dc1d94..3fea771 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java
@@ -14,11 +14,11 @@
 package com.google.devtools.build.lib.buildtool;
 
 import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.cmdline.TargetPattern;
 import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment.TopLevelConfigurations;
 import com.google.devtools.build.lib.query2.cquery.ConfiguredTargetQueryEnvironment;
 import com.google.devtools.build.lib.query2.cquery.CqueryOptions;
-import com.google.devtools.build.lib.query2.cquery.KeyedConfiguredTarget;
 import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction;
 import com.google.devtools.build.lib.query2.engine.QueryExpression;
 import com.google.devtools.build.lib.runtime.CommandEnvironment;
@@ -27,7 +27,7 @@
 import java.util.Collection;
 
 /** Performs {@code cquery} processing. */
-public final class CqueryProcessor extends PostAnalysisQueryProcessor<KeyedConfiguredTarget> {
+public final class CqueryProcessor extends PostAnalysisQueryProcessor<ConfiguredTarget> {
 
   public CqueryProcessor(
       QueryExpression queryExpression, TargetPattern.Parser mainRepoTargetParser) {
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java
index 0a8944f..515a0ab 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java
@@ -15,6 +15,7 @@
 package com.google.devtools.build.lib.query2.cquery;
 
 import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.configuredtargets.OutputFileConfiguredTarget;
 import com.google.devtools.build.lib.events.ExtendedEventHandler;
 import com.google.devtools.build.lib.packages.Attribute;
@@ -37,7 +38,7 @@
       CqueryOptions options,
       OutputStream out,
       SkyframeExecutor skyframeExecutor,
-      TargetAccessor<KeyedConfiguredTarget> accessor) {
+      TargetAccessor<ConfiguredTarget> accessor) {
     super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false);
   }
 
@@ -66,28 +67,28 @@
   }
 
   @Nullable
-  private ConfiguredAttributeMapper getAttributeMap(KeyedConfiguredTarget kct)
+  private ConfiguredAttributeMapper getAttributeMap(ConfiguredTarget kct)
       throws InterruptedException {
     Rule associatedRule = accessor.getTarget(kct).getAssociatedRule();
     if (associatedRule == null) {
       return null;
-    } else if (kct.getConfiguredTarget() instanceof OutputFileConfiguredTarget) {
+    } else if (kct instanceof OutputFileConfiguredTarget) {
       return ConfiguredAttributeMapper.of(
           associatedRule,
           accessor.getGeneratingConfiguredTarget(kct).getConfigConditions(),
-          kct.getConfigurationChecksum(),
-          /*alwaysSucceed=*/ false);
+          kct.getConfigurationKey().getOptionsChecksum(),
+          /* alwaysSucceed= */ false);
     } else {
       return ConfiguredAttributeMapper.of(
           associatedRule,
           kct.getConfigConditions(),
-          kct.getConfigurationChecksum(),
-          /*alwaysSucceed=*/ false);
+          kct.getConfigurationKey().getOptionsChecksum(),
+          /* alwaysSucceed= */ false);
     }
   }
 
   @Override
-  public void processOutput(Iterable<KeyedConfiguredTarget> partialResult)
+  public void processOutput(Iterable<ConfiguredTarget> partialResult)
       throws InterruptedException, IOException {
     BuildOutputFormatter.TargetOutputter outputter =
         new TargetOutputter(
@@ -98,7 +99,7 @@
             // and which path is chosen, which people may find even more informative.
             (rule, attr) -> false,
             System.lineSeparator());
-    for (KeyedConfiguredTarget configuredTarget : partialResult) {
+    for (ConfiguredTarget configuredTarget : partialResult) {
       Target target = accessor.getTarget(configuredTarget);
       outputter.output(target, new CqueryAttributeReader(getAttributeMap(configuredTarget)));
     }
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java
index 4aa1032..1b105be 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java
@@ -14,6 +14,7 @@
 package com.google.devtools.build.lib.query2.cquery;
 
 import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.query2.common.AbstractBlazeQueryEnvironment;
 import com.google.devtools.build.lib.query2.engine.Callback;
 import com.google.devtools.build.lib.query2.engine.QueryEnvironment;
@@ -58,7 +59,7 @@
 
   /**
    * This function is only viable with ConfiguredTargetQueryEnvironment which extends {@link
-   * AbstractBlazeQueryEnvironment <KeyedConfiguredTarget>}.
+   * AbstractBlazeQueryEnvironment <ConfiguredTarget>}.
    */
   @Override
   @SuppressWarnings("unchecked")
@@ -84,6 +85,6 @@
                 targetExpression.toString(),
                 targetsFuture,
                 configuration,
-                (Callback<KeyedConfiguredTarget>) callback));
+                (Callback<ConfiguredTarget>) callback));
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java
index 0698fd7..6a30dd3 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java
@@ -17,9 +17,9 @@
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableListMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Multimap;
 import com.google.common.collect.Multimaps;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.ConfiguredTargetValue;
@@ -57,7 +57,7 @@
  *
  * <p>Incomplete; we'll implement getVisibility when needed.
  */
-public class ConfiguredTargetAccessor implements TargetAccessor<KeyedConfiguredTarget> {
+public class ConfiguredTargetAccessor implements TargetAccessor<ConfiguredTarget> {
 
   private final WalkableGraph walkableGraph;
   private final ConfiguredTargetQueryEnvironment queryEnvironment;
@@ -69,55 +69,56 @@
   }
 
   @Override
-  public String getTargetKind(KeyedConfiguredTarget target) {
+  public String getTargetKind(ConfiguredTarget target) {
     Target actualTarget = getTarget(target);
     return actualTarget.getTargetKind();
   }
 
   @Override
-  public String getLabel(KeyedConfiguredTarget target) {
-    return target.getLabel().toString();
+  public String getLabel(ConfiguredTarget target) {
+    return target.getOriginalLabel().toString();
   }
 
   @Override
-  public String getPackage(KeyedConfiguredTarget target) {
-    return target.getLabel().getPackageIdentifier().getPackageFragment().toString();
+  public String getPackage(ConfiguredTarget target) {
+    return target.getOriginalLabel().getPackageIdentifier().getPackageFragment().toString();
   }
 
   @Override
-  public boolean isRule(KeyedConfiguredTarget target) {
+  public boolean isRule(ConfiguredTarget target) {
     Target actualTarget = getTarget(target);
     return actualTarget instanceof Rule;
   }
 
   @Override
-  public boolean isTestRule(KeyedConfiguredTarget target) {
+  public boolean isTestRule(ConfiguredTarget target) {
     Target actualTarget = getTarget(target);
     return TargetUtils.isTestRule(actualTarget);
   }
 
   @Override
-  public boolean isTestSuite(KeyedConfiguredTarget target) {
+  public boolean isTestSuite(ConfiguredTarget target) {
     Target actualTarget = getTarget(target);
     return TargetUtils.isTestSuiteRule(actualTarget);
   }
 
   @Override
-  public List<KeyedConfiguredTarget> getPrerequisites(
+  public List<ConfiguredTarget> getPrerequisites(
       QueryExpression caller,
-      KeyedConfiguredTarget keyedConfiguredTarget,
+      ConfiguredTarget keyedConfiguredTarget,
       String attrName,
       String errorMsgPrefix)
       throws QueryException, InterruptedException {
     // Process aliases.
-    KeyedConfiguredTarget actual = keyedConfiguredTarget.getActual();
+    ConfiguredTarget actual = keyedConfiguredTarget.getActual();
 
     Preconditions.checkArgument(
         isRule(actual), "%s %s is not a rule configured target", errorMsgPrefix, getLabel(actual));
 
-    Multimap<Label, KeyedConfiguredTarget> depsByLabel =
+    ImmutableListMultimap<Label, ConfiguredTarget> depsByLabel =
         Multimaps.index(
-            queryEnvironment.getFwdDeps(ImmutableList.of(actual)), KeyedConfiguredTarget::getLabel);
+            queryEnvironment.getFwdDeps(ImmutableList.of(actual)),
+            ConfiguredTarget::getOriginalLabel);
 
     Rule rule = (Rule) getTarget(actual);
     ImmutableMap<Label, ConfigMatchingProvider> configConditions = actual.getConfigConditions();
@@ -135,41 +136,41 @@
               errorMsgPrefix, rule.getRuleClass(), attrName),
           ConfigurableQuery.Code.ATTRIBUTE_MISSING);
     }
-    ImmutableList.Builder<KeyedConfiguredTarget> toReturn = ImmutableList.builder();
+    ImmutableList.Builder<ConfiguredTarget> toReturn = ImmutableList.builder();
     attributeMapper.visitLabels(attrName, label -> toReturn.addAll(depsByLabel.get(label)));
     return toReturn.build();
   }
 
   @Override
-  public List<String> getStringListAttr(KeyedConfiguredTarget target, String attrName) {
+  public List<String> getStringListAttr(ConfiguredTarget target, String attrName) {
     Target actualTarget = getTarget(target);
     return TargetUtils.getStringListAttr(actualTarget, attrName);
   }
 
   @Override
-  public String getStringAttr(KeyedConfiguredTarget target, String attrName) {
+  public String getStringAttr(ConfiguredTarget target, String attrName) {
     Target actualTarget = getTarget(target);
     return TargetUtils.getStringAttr(actualTarget, attrName);
   }
 
   @Override
-  public Iterable<String> getAttrAsString(KeyedConfiguredTarget target, String attrName) {
+  public Iterable<String> getAttrAsString(ConfiguredTarget target, String attrName) {
     Target actualTarget = getTarget(target);
     return TargetUtils.getAttrAsString(actualTarget, attrName);
   }
 
   @Override
-  public ImmutableSet<QueryVisibility<KeyedConfiguredTarget>> getVisibility(
-      QueryExpression caller, KeyedConfiguredTarget from) throws QueryException {
+  public ImmutableSet<QueryVisibility<ConfiguredTarget>> getVisibility(
+      QueryExpression caller, ConfiguredTarget from) throws QueryException {
     // TODO(bazel-team): implement this if needed.
     throw new QueryException(
         "visible() is not supported on configured targets",
         ConfigurableQuery.Code.VISIBLE_FUNCTION_NOT_SUPPORTED);
   }
 
-  public Target getTarget(KeyedConfiguredTarget keyedConfiguredTarget) {
+  public Target getTarget(ConfiguredTarget configuredTarget) {
     // Dereference any aliases that might be present.
-    Label label = keyedConfiguredTarget.getConfiguredTarget().getOriginalLabel();
+    Label label = configuredTarget.getOriginalLabel();
     try {
       return queryEnvironment.getTarget(label);
     } catch (InterruptedException e) {
@@ -180,18 +181,15 @@
   }
 
   /** Returns the rule that generates the given output file. */
-  RuleConfiguredTarget getGeneratingConfiguredTarget(KeyedConfiguredTarget kct)
+  RuleConfiguredTarget getGeneratingConfiguredTarget(ConfiguredTarget kct)
       throws InterruptedException {
-    Preconditions.checkArgument(kct.getConfiguredTarget() instanceof OutputFileConfiguredTarget);
+    Preconditions.checkArgument(kct instanceof OutputFileConfiguredTarget);
     return (RuleConfiguredTarget)
         ((ConfiguredTargetValue)
                 walkableGraph.getValue(
                     ConfiguredTargetKey.builder()
-                        .setLabel(
-                            ((OutputFileConfiguredTarget) kct.getConfiguredTarget())
-                                .getGeneratingRule()
-                                .getLabel())
-                        .setConfiguration(queryEnvironment.getConfiguration(kct))
+                        .setLabel(((OutputFileConfiguredTarget) kct).getGeneratingRule().getLabel())
+                        .setConfigurationKey(kct.getConfigurationKey())
                         .build()
                         .toKey()))
             .getConfiguredTarget();
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java
index 1beeae8..40393df 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java
@@ -72,7 +72,7 @@
  * comments on {@link PostAnalysisQueryEnvironment#targetifyValues} and b/163052263 for details.
  */
 public class ConfiguredTargetQueryEnvironment
-    extends PostAnalysisQueryEnvironment<KeyedConfiguredTarget> {
+    extends PostAnalysisQueryEnvironment<ConfiguredTarget> {
   /** Common query functions and cquery specific functions. */
   public static final ImmutableList<QueryFunction> FUNCTIONS = populateFunctions();
   /** Cquery specific functions. */
@@ -82,8 +82,7 @@
 
   private final TopLevelArtifactContext topLevelArtifactContext;
 
-  private final KeyExtractor<KeyedConfiguredTarget, ConfiguredTargetKey>
-      configuredTargetKeyExtractor;
+  private final KeyExtractor<ConfiguredTarget, ConfiguredTargetKey> configuredTargetKeyExtractor;
 
   private final ConfiguredTargetAccessor accessor;
 
@@ -105,8 +104,7 @@
   private final ImmutableMap<String, BuildConfigurationValue> transitiveConfigurations;
 
   @Override
-  protected KeyExtractor<KeyedConfiguredTarget, ConfiguredTargetKey>
-      getConfiguredTargetKeyExtractor() {
+  protected KeyExtractor<ConfiguredTarget, ConfiguredTargetKey> getConfiguredTargetKeyExtractor() {
     return configuredTargetKeyExtractor;
   }
 
@@ -132,7 +130,7 @@
         walkableGraphSupplier,
         settings);
     this.accessor = new ConfiguredTargetAccessor(walkableGraphSupplier.get(), this);
-    this.configuredTargetKeyExtractor = KeyedConfiguredTarget::getConfiguredTargetKey;
+    this.configuredTargetKeyExtractor = ConfiguredTargetKey::fromConfiguredTarget;
     this.transitiveConfigurations =
         getTransitiveConfigurations(transitiveConfigurationKeys, walkableGraphSupplier.get());
     this.topLevelArtifactContext = topLevelArtifactContext;
@@ -187,9 +185,9 @@
   }
 
   @Override
-  public ImmutableList<NamedThreadSafeOutputFormatterCallback<KeyedConfiguredTarget>>
+  public ImmutableList<NamedThreadSafeOutputFormatterCallback<ConfiguredTarget>>
       getDefaultOutputFormatters(
-          TargetAccessor<KeyedConfiguredTarget> accessor,
+          TargetAccessor<ConfiguredTarget> accessor,
           ExtendedEventHandler eventHandler,
           OutputStream out,
           SkyframeExecutor skyframeExecutor,
@@ -278,7 +276,7 @@
 
   @Override
   public QueryTaskFuture<Void> getTargetsMatchingPattern(
-      QueryExpression owner, String pattern, Callback<KeyedConfiguredTarget> callback) {
+      QueryExpression owner, String pattern, Callback<ConfiguredTarget> callback) {
     TargetPattern patternToEval;
     try {
       patternToEval = getPattern(pattern);
@@ -304,7 +302,7 @@
                 /* excludedSubdirectories= */ ImmutableSet.of(),
                 (Callback<Target>)
                     partialResult -> {
-                      List<KeyedConfiguredTarget> transformedResult = new ArrayList<>();
+                      List<ConfiguredTarget> transformedResult = new ArrayList<>();
                       for (Target target : partialResult) {
                         transformedResult.addAll(
                             getConfiguredTargetsForConfigFunction(target.getLabel()));
@@ -322,8 +320,8 @@
    * null.
    */
   @Nullable
-  private KeyedConfiguredTarget getConfiguredTarget(
-      Label label, BuildConfigurationValue configuration) throws InterruptedException {
+  private ConfiguredTarget getConfiguredTarget(Label label, BuildConfigurationValue configuration)
+      throws InterruptedException {
     return getValueFromKey(
         ConfiguredTargetKey.builder()
             .setLabel(label)
@@ -334,11 +332,9 @@
 
   @Override
   @Nullable
-  protected KeyedConfiguredTarget getValueFromKey(SkyKey key) throws InterruptedException {
+  protected ConfiguredTarget getValueFromKey(SkyKey key) throws InterruptedException {
     ConfiguredTargetValue value = getConfiguredTargetValue(key);
-    return value == null
-        ? null
-        : KeyedConfiguredTarget.create((ConfiguredTargetKey) key, value.getConfiguredTarget());
+    return value == null ? null : value.getConfiguredTarget();
   }
 
   /**
@@ -346,16 +342,16 @@
    *
    * <p>If there are no matches, returns an empty list.
    */
-  private List<KeyedConfiguredTarget> getConfiguredTargetsForConfigFunction(Label label)
+  private ImmutableList<ConfiguredTarget> getConfiguredTargetsForConfigFunction(Label label)
       throws InterruptedException {
-    ImmutableList.Builder<KeyedConfiguredTarget> ans = ImmutableList.builder();
+    ImmutableList.Builder<ConfiguredTarget> ans = ImmutableList.builder();
     for (BuildConfigurationValue config : transitiveConfigurations.values()) {
-      KeyedConfiguredTarget kct = getConfiguredTarget(label, config);
+      ConfiguredTarget kct = getConfiguredTarget(label, config);
       if (kct != null) {
         ans.add(kct);
       }
     }
-    KeyedConfiguredTarget nullConfiguredTarget = getNullConfiguredTarget(label);
+    ConfiguredTarget nullConfiguredTarget = getNullConfiguredTarget(label);
     if (nullConfiguredTarget != null) {
       ans.add(nullConfiguredTarget);
     }
@@ -380,19 +376,19 @@
       String pattern,
       QueryTaskFuture<ThreadSafeMutableSet<T>> targetsFuture,
       String configPrefix,
-      Callback<KeyedConfiguredTarget> callback) {
+      Callback<ConfiguredTarget> callback) {
     // There's no technical reason other callers beside ConfigFunction can't call this. But they'd
     // need to adjust the error messaging below to not make it config()-specific. Please don't just
     // remove that line: the counter-priority is making error messages as clear, precise, and
     // actionable as possible.
     return () -> {
-      ThreadSafeMutableSet<KeyedConfiguredTarget> targets =
-          (ThreadSafeMutableSet<KeyedConfiguredTarget>) targetsFuture.getIfSuccessful();
-      List<KeyedConfiguredTarget> transformedResult = new ArrayList<>();
+      ThreadSafeMutableSet<ConfiguredTarget> targets =
+          (ThreadSafeMutableSet<ConfiguredTarget>) targetsFuture.getIfSuccessful();
+      List<ConfiguredTarget> transformedResult = new ArrayList<>();
       boolean userFriendlyConfigName = true;
-      for (KeyedConfiguredTarget target : targets) {
+      for (ConfiguredTarget target : targets) {
         Label label = getCorrectLabel(target);
-        KeyedConfiguredTarget keyedConfiguredTarget;
+        ConfiguredTarget keyedConfiguredTarget;
         switch (configPrefix) {
           case "host":
             throw new QueryException(
@@ -467,20 +463,19 @@
    * the "actual" target instead of the alias target. Grr.
    */
   @Override
-  public Label getCorrectLabel(KeyedConfiguredTarget target) {
+  public Label getCorrectLabel(ConfiguredTarget target) {
     // Dereference any aliases that might be present.
-    return target.getConfiguredTarget().getOriginalLabel();
+    return target.getOriginalLabel();
   }
 
   @Nullable
   @Override
-  protected KeyedConfiguredTarget getTargetConfiguredTarget(Label label)
-      throws InterruptedException {
+  protected ConfiguredTarget getTargetConfiguredTarget(Label label) throws InterruptedException {
     if (topLevelConfigurations.isTopLevelTarget(label)) {
       return getConfiguredTarget(
           label, topLevelConfigurations.getConfigurationForTopLevelTarget(label));
     } else {
-      KeyedConfiguredTarget toReturn;
+      ConfiguredTarget toReturn;
       for (BuildConfigurationValue configuration : topLevelConfigurations.getConfigurations()) {
         toReturn = getConfiguredTarget(label, configuration);
         if (toReturn != null) {
@@ -493,22 +488,22 @@
 
   @Nullable
   @Override
-  protected KeyedConfiguredTarget getNullConfiguredTarget(Label label) throws InterruptedException {
+  protected ConfiguredTarget getNullConfiguredTarget(Label label) throws InterruptedException {
     return getConfiguredTarget(label, null);
   }
 
   @Nullable
   @Override
-  protected RuleConfiguredTarget getRuleConfiguredTarget(KeyedConfiguredTarget configuredTarget) {
-    if (configuredTarget.getConfiguredTarget() instanceof RuleConfiguredTarget) {
-      return (RuleConfiguredTarget) configuredTarget.getConfiguredTarget();
+  protected RuleConfiguredTarget getRuleConfiguredTarget(ConfiguredTarget configuredTarget) {
+    if (configuredTarget instanceof RuleConfiguredTarget) {
+      return (RuleConfiguredTarget) configuredTarget;
     }
     return null;
   }
 
   @Nullable
   @Override
-  protected BuildConfigurationValue getConfiguration(KeyedConfiguredTarget target) {
+  protected BuildConfigurationValue getConfiguration(ConfiguredTarget target) {
     try {
       return target.getConfigurationKey() == null
           ? null
@@ -519,15 +514,15 @@
   }
 
   @Override
-  protected ConfiguredTargetKey getConfiguredTargetKey(KeyedConfiguredTarget target) {
-    return target.getConfiguredTargetKey();
+  protected ConfiguredTargetKey getConfiguredTargetKey(ConfiguredTarget target) {
+    return ConfiguredTargetKey.fromConfiguredTarget(target);
   }
 
   @Override
-  public ThreadSafeMutableSet<KeyedConfiguredTarget> createThreadSafeMutableSet() {
+  public ThreadSafeMutableSet<ConfiguredTarget> createThreadSafeMutableSet() {
     return new ThreadSafeMutableKeyExtractorBackedSetImpl<>(
         configuredTargetKeyExtractor,
-        KeyedConfiguredTarget.class,
+        ConfiguredTarget.class,
         SkyQueryEnvironment.DEFAULT_THREAD_COUNT);
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java
index af55999..bc8c3f7 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java
@@ -13,9 +13,9 @@
 // limitations under the License.
 package com.google.devtools.build.lib.query2.cquery;
 
-
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
 import com.google.devtools.build.lib.events.ExtendedEventHandler;
 import com.google.devtools.build.lib.query2.NamedThreadSafeOutputFormatterCallback;
@@ -42,7 +42,7 @@
  * focused on completeness, should output full configuration checksums.
  */
 public abstract class CqueryThreadsafeCallback
-    extends NamedThreadSafeOutputFormatterCallback<KeyedConfiguredTarget> {
+    extends NamedThreadSafeOutputFormatterCallback<ConfiguredTarget> {
 
   protected final ExtendedEventHandler eventHandler;
   protected final CqueryOptions options;
@@ -64,7 +64,7 @@
       CqueryOptions options,
       OutputStream out,
       SkyframeExecutor skyframeExecutor,
-      TargetAccessor<KeyedConfiguredTarget> accessor,
+      TargetAccessor<ConfiguredTarget> accessor,
       boolean uniquifyResults) {
     this.eventHandler = eventHandler;
     this.options = options;
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java
index 64de8ac..951baa0 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java
@@ -18,6 +18,7 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.DependencyKey;
 import com.google.devtools.build.lib.analysis.DependencyKind;
 import com.google.devtools.build.lib.analysis.DependencyKind.NonAttributeDependencyKind;
@@ -110,17 +111,17 @@
   }
 
   /**
-   * Return the set of dependencies of a KeyedConfiguredTarget, including information about the
+   * Return the set of dependencies of a ConfiguredTarget, including information about the
    * configuration transitions applied to the dependencies.
    *
    * @see ResolvedTransition for more details.
    * @param keyedConfiguredTarget the configured target whose dependencies are being looked up.
    */
-  public ImmutableSet<ResolvedTransition> dependencies(KeyedConfiguredTarget keyedConfiguredTarget)
+  public ImmutableSet<ResolvedTransition> dependencies(ConfiguredTarget keyedConfiguredTarget)
       throws DependencyResolver.Failure, InconsistentAspectOrderException, InterruptedException {
     ImmutableSet.Builder<ResolvedTransition> resolved = new ImmutableSet.Builder<>();
 
-    if (!(keyedConfiguredTarget.getConfiguredTarget() instanceof RuleConfiguredTarget)) {
+    if (!(keyedConfiguredTarget instanceof RuleConfiguredTarget)) {
       return resolved.build();
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java
index e4d94b9..f873120 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java
@@ -36,7 +36,7 @@
       CqueryOptions options,
       OutputStream out,
       SkyframeExecutor skyframeExecutor,
-      TargetAccessor<KeyedConfiguredTarget> accessor,
+      TargetAccessor<ConfiguredTarget> accessor,
       TopLevelArtifactContext topLevelArtifactContext) {
     // Different targets may provide the same artifact, so we deduplicate the collection of all
     // results at the end.
@@ -50,10 +50,9 @@
   }
 
   @Override
-  public void processOutput(Iterable<KeyedConfiguredTarget> partialResult)
+  public void processOutput(Iterable<ConfiguredTarget> partialResult)
       throws IOException, InterruptedException {
-    for (KeyedConfiguredTarget keyedTarget : partialResult) {
-      ConfiguredTarget target = keyedTarget.getConfiguredTarget();
+    for (ConfiguredTarget target : partialResult) {
       if (!TopLevelArtifactHelper.shouldConsiderForDisplay(target)
           && !(target instanceof InputFileConfiguredTarget)) {
         continue;
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java
index 009fcd4..a8e3dff 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java
@@ -15,6 +15,7 @@
 package com.google.devtools.build.lib.query2.cquery;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.RepositoryMapping;
 import com.google.devtools.build.lib.events.ExtendedEventHandler;
@@ -37,20 +38,19 @@
   /** Interface for finding a configured target's direct dependencies. */
   @FunctionalInterface
   public interface DepsRetriever {
-    Iterable<KeyedConfiguredTarget> getDirectDeps(KeyedConfiguredTarget target)
-        throws InterruptedException;
+    Iterable<ConfiguredTarget> getDirectDeps(ConfiguredTarget target) throws InterruptedException;
   }
 
   private final DepsRetriever depsRetriever;
 
-  private final GraphOutputWriter.NodeReader<KeyedConfiguredTarget> nodeReader =
-      new NodeReader<KeyedConfiguredTarget>() {
+  private final GraphOutputWriter.NodeReader<ConfiguredTarget> nodeReader =
+      new NodeReader<ConfiguredTarget>() {
 
-        private final Comparator<KeyedConfiguredTarget> configuredTargetOrdering =
+        private final Comparator<ConfiguredTarget> configuredTargetOrdering =
             (ct1, ct2) -> {
               // Order graph output first by target label, then by configuration hash.
-              Label label1 = ct1.getLabel();
-              Label label2 = ct2.getLabel();
+              Label label1 = ct1.getOriginalLabel();
+              Label label2 = ct2.getOriginalLabel();
               if (!label1.equals(label2)) {
                 return label1.compareTo(label2);
               }
@@ -67,18 +67,18 @@
 
         @Override
         public String getLabel(
-            Node<KeyedConfiguredTarget> node, RepositoryMapping mainRepositoryMapping) {
+            Node<ConfiguredTarget> node, RepositoryMapping mainRepositoryMapping) {
           // Node payloads are ConfiguredTargets. Output node labels are target labels + config
           // hashes.
-          KeyedConfiguredTarget kct = node.getLabel();
+          ConfiguredTarget kct = node.getLabel();
           return String.format(
               "%s (%s)",
-              kct.getLabel().getDisplayForm(mainRepositoryMapping),
+              kct.getOriginalLabel().getDisplayForm(mainRepositoryMapping),
               shortId(getConfiguration(kct.getConfigurationKey())));
         }
 
         @Override
-        public Comparator<KeyedConfiguredTarget> comparator() {
+        public Comparator<ConfiguredTarget> comparator() {
           return configuredTargetOrdering;
         }
       };
@@ -90,7 +90,7 @@
       CqueryOptions options,
       OutputStream out,
       SkyframeExecutor skyframeExecutor,
-      TargetAccessor<KeyedConfiguredTarget> accessor,
+      TargetAccessor<ConfiguredTarget> accessor,
       DepsRetriever depsRetriever,
       RepositoryMapping mainRepoMapping) {
     super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false);
@@ -99,32 +99,31 @@
   }
 
   @Override
-  public void processOutput(Iterable<KeyedConfiguredTarget> partialResult)
-      throws InterruptedException {
+  public void processOutput(Iterable<ConfiguredTarget> partialResult) throws InterruptedException {
     // Transform the cquery-backed graph into a Digraph to make it suitable for GraphOutputWriter.
     // Note that this involves an extra iteration over the entire query result subgraph. We could
     // conceptually merge transformation and output writing into the same iteration if needed.
-    Digraph<KeyedConfiguredTarget> graph = new Digraph<>();
-    ImmutableSet<KeyedConfiguredTarget> allNodes = ImmutableSet.copyOf(partialResult);
-    for (KeyedConfiguredTarget configuredTarget : partialResult) {
-      Node<KeyedConfiguredTarget> node = graph.createNode(configuredTarget);
-      for (KeyedConfiguredTarget dep : depsRetriever.getDirectDeps(configuredTarget)) {
+    Digraph<ConfiguredTarget> graph = new Digraph<>();
+    ImmutableSet<ConfiguredTarget> allNodes = ImmutableSet.copyOf(partialResult);
+    for (ConfiguredTarget configuredTarget : partialResult) {
+      Node<ConfiguredTarget> node = graph.createNode(configuredTarget);
+      for (ConfiguredTarget dep : depsRetriever.getDirectDeps(configuredTarget)) {
         if (allNodes.contains(dep)) {
-          Node<KeyedConfiguredTarget> depNode = graph.createNode(dep);
+          Node<ConfiguredTarget> depNode = graph.createNode(dep);
           graph.addEdge(node, depNode);
         }
       }
     }
 
-    GraphOutputWriter<KeyedConfiguredTarget> graphWriter =
+    GraphOutputWriter<ConfiguredTarget> graphWriter =
         new GraphOutputWriter<>(
             nodeReader,
             options.getLineTerminator(),
-            /*sortLabels=*/ true,
+            /* sortLabels= */ true,
             options.graphNodeStringLimit,
             // select() conditions don't matter for cquery because cquery operates post-analysis
             // phase, when select()s have been resolved and removed from the graph.
-            /*maxConditionalEdges=*/ 0,
+            /* maxConditionalEdges= */ 0,
             options.graphFactored,
             mainRepoMapping);
     graphWriter.write(graph, /*conditionalEdges=*/ null, outputStream);
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/KeyedConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/KeyedConfiguredTarget.java
deleted file mode 100644
index fb14222..0000000
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/KeyedConfiguredTarget.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// 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.query2.cquery;
-
-import com.google.auto.value.AutoValue;
-import com.google.common.collect.ImmutableMap;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.skyframe.BuildConfigurationKey;
-import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
-import javax.annotation.Nullable;
-
-/**
- * A representation of a ConfiguredTargetKey and the ConfiguredTarget that it points to, for use in
- * configured target queries.
- */
-@AutoValue
-public abstract class KeyedConfiguredTarget {
-
-  /** Returns a new KeyedConfiguredTarget for the given data. */
-  public static KeyedConfiguredTarget create(
-      ConfiguredTargetKey configuredTargetKey, ConfiguredTarget configuredTarget) {
-    return new AutoValue_KeyedConfiguredTarget(configuredTargetKey, configuredTarget);
-  }
-
-  /** Returns the key for this KeyedConfiguredTarget. */
-  @Nullable
-  public abstract ConfiguredTargetKey getConfiguredTargetKey();
-
-  /** Returns the ConfiguredTarget for this KeyedConfiguredTarget. */
-  public abstract ConfiguredTarget getConfiguredTarget();
-
-  /** Returns the original (pre-alias) label for the underlying ConfiguredTarget. */
-  public Label getLabel() {
-    return getConfiguredTarget().getOriginalLabel();
-  }
-
-  /** Returns the configuration key used for this KeyedConfiguredTarget. */
-  @Nullable
-  public BuildConfigurationKey getConfigurationKey() {
-    return getConfiguredTarget().getConfigurationKey();
-  }
-
-  /** Returns the configuration checksum in use for this KeyedConfiguredTarget. */
-  @Nullable
-  public String getConfigurationChecksum() {
-    return getConfigurationKey() == null ? null : getConfigurationKey().getOptions().checksum();
-  }
-
-  /**
-   * The configuration conditions that trigger this configured target's configurable attributes. For
-   * targets that do not support configurable attributes, this will be an empty map.
-   */
-  public ImmutableMap<Label, ConfigMatchingProvider> getConfigConditions() {
-    return getConfiguredTarget().getConfigConditions();
-  }
-
-  /** Returns a KeyedConfiguredTarget instance that resolves aliases. */
-  public KeyedConfiguredTarget getActual() {
-    ConfiguredTarget actual = getConfiguredTarget().getActual();
-    // Use old values for unchanged fields, like toolchain ctx, if possible.
-    ConfiguredTargetKey.Builder oldKey =
-        (this.getConfiguredTargetKey() == null
-            ? ConfiguredTargetKey.builder()
-            : this.getConfiguredTargetKey().toBuilder());
-
-    ConfiguredTargetKey actualKey =
-        oldKey
-            .setLabel(actual.getLabel())
-            .setConfigurationKey(actual.getConfigurationKey())
-            .build();
-    return KeyedConfiguredTarget.create(actualKey, actual);
-  }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java
index 73bfd9c..533408f 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java
@@ -15,6 +15,7 @@
 
 import com.google.common.collect.ImmutableSortedSet;
 import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.RequiredConfigFragmentsProvider;
 import com.google.devtools.build.lib.analysis.config.CoreOptions.IncludeConfigFragmentsEnum;
 import com.google.devtools.build.lib.cmdline.Label;
@@ -36,7 +37,7 @@
       CqueryOptions options,
       OutputStream out,
       SkyframeExecutor skyframeExecutor,
-      TargetAccessor<KeyedConfiguredTarget> accessor,
+      TargetAccessor<ConfiguredTarget> accessor,
       boolean showKind,
       RepositoryMapping mainRepoMapping) {
     super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false);
@@ -50,8 +51,8 @@
   }
 
   @Override
-  public void processOutput(Iterable<KeyedConfiguredTarget> partialResult) {
-    for (KeyedConfiguredTarget keyedConfiguredTarget : partialResult) {
+  public void processOutput(Iterable<ConfiguredTarget> partialResult) {
+    for (ConfiguredTarget keyedConfiguredTarget : partialResult) {
       StringBuilder output = new StringBuilder();
       if (showKind) {
         Target actualTarget = accessor.getTarget(keyedConfiguredTarget);
@@ -59,7 +60,7 @@
       }
       output =
           output
-              .append(keyedConfiguredTarget.getLabel().getDisplayForm(mainRepoMapping))
+              .append(keyedConfiguredTarget.getOriginalLabel().getDisplayForm(mainRepoMapping))
               .append(" (")
               .append(shortId(getConfiguration(keyedConfiguredTarget.getConfigurationKey())))
               .append(")");
@@ -73,10 +74,9 @@
   }
 
   private static ImmutableSortedSet<String> requiredFragmentStrings(
-      KeyedConfiguredTarget keyedConfiguredTarget) {
+      ConfiguredTarget keyedConfiguredTarget) {
     RequiredConfigFragmentsProvider requiredFragments =
         keyedConfiguredTarget
-            .getConfiguredTarget()
             .getProvider(RequiredConfigFragmentsProvider.class);
     if (requiredFragments == null) {
       return ImmutableSortedSet.of();
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java
index 16e5ea2..9ffc8d4 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java
@@ -23,6 +23,7 @@
 import com.google.devtools.build.lib.actions.BuildConfigurationEvent;
 import com.google.devtools.build.lib.analysis.AnalysisProtosV2;
 import com.google.devtools.build.lib.analysis.AnalysisProtosV2.Configuration;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.DependencyResolver;
 import com.google.devtools.build.lib.analysis.InconsistentAspectOrderException;
 import com.google.devtools.build.lib.analysis.config.BuildOptions;
@@ -114,14 +115,14 @@
   private AnalysisProtosV2.CqueryResult.Builder protoResult;
 
   private final Map<Label, Target> partialResultMap;
-  private KeyedConfiguredTarget currentTarget;
+  private ConfiguredTarget currentTarget;
 
   ProtoOutputFormatterCallback(
       ExtendedEventHandler eventHandler,
       CqueryOptions options,
       OutputStream out,
       SkyframeExecutor skyframeExecutor,
-      TargetAccessor<KeyedConfiguredTarget> accessor,
+      TargetAccessor<ConfiguredTarget> accessor,
       AspectResolver resolver,
       OutputType outputType,
       @Nullable TransitionFactory<RuleTransitionData> trimmingTransitionFactory) {
@@ -184,9 +185,9 @@
   }
 
   @Override
-  public void processOutput(Iterable<KeyedConfiguredTarget> partialResult)
-      throws InterruptedException {
-    partialResult.forEach(kct -> partialResultMap.put(kct.getLabel(), accessor.getTarget(kct)));
+  public void processOutput(Iterable<ConfiguredTarget> partialResult) throws InterruptedException {
+    partialResult.forEach(
+        kct -> partialResultMap.put(kct.getOriginalLabel(), accessor.getTarget(kct)));
 
     KnownTargetsDependencyResolver knownTargetsDependencyResolver =
         new KnownTargetsDependencyResolver(partialResultMap);
@@ -201,7 +202,7 @@
 
     ConfiguredProtoOutputFormatter formatter = new ConfiguredProtoOutputFormatter();
     formatter.setOptions(options, resolver, skyframeExecutor.getDigestFunction().getHashFunction());
-    for (KeyedConfiguredTarget keyedConfiguredTarget : partialResult) {
+    for (ConfiguredTarget keyedConfiguredTarget : partialResult) {
       AnalysisProtosV2.ConfiguredTarget.Builder builder =
           AnalysisProtosV2.ConfiguredTarget.newBuilder();
 
@@ -251,7 +252,7 @@
         builder.setConfiguration(
             AnalysisProtosV2.Configuration.newBuilder().setChecksum(String.valueOf(checksum)));
 
-        ConfiguredTargetKey configuredTargetKey = keyedConfiguredTarget.getConfiguredTargetKey();
+        var configuredTargetKey = ConfiguredTargetKey.fromConfiguredTarget(keyedConfiguredTarget);
         // Some targets don't have a configuration, e.g. InputFileConfiguredTarget
         if (configuredTargetKey != null) {
           BuildConfigurationKey configurationKey = configuredTargetKey.getConfigurationKey();
@@ -277,13 +278,13 @@
       // because this method is only triggered in ProtoOutputFormatter.toTargetProtoBuffer when
       // the target in currentTarget is an instanceof Rule.
       ImmutableMap<Label, ConfigMatchingProvider> configConditions =
-          currentTarget.getConfiguredTarget().getConfigConditions();
+          currentTarget.getConfigConditions();
       ConfiguredAttributeMapper attributeMapper =
           ConfiguredAttributeMapper.of(
               rule,
               configConditions,
-              currentTarget.getConfigurationChecksum(),
-              /*alwaysSucceed=*/ false);
+              currentTarget.getConfigurationKey().getOptionsChecksum(),
+              /* alwaysSucceed= */ false);
       for (Attribute attr : sortAttributes(rule.getAttributes())) {
         if (!shouldIncludeAttribute(rule, attr)) {
           continue;
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java
index 92a0ca1..6edba92 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java
@@ -137,7 +137,7 @@
       CqueryOptions options,
       OutputStream out,
       SkyframeExecutor skyframeExecutor,
-      TargetAccessor<KeyedConfiguredTarget> accessor)
+      TargetAccessor<ConfiguredTarget> accessor)
       throws QueryException, InterruptedException {
     super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false);
 
@@ -224,18 +224,15 @@
   }
 
   @Override
-  public void processOutput(Iterable<KeyedConfiguredTarget> partialResult)
-      throws InterruptedException {
-    for (KeyedConfiguredTarget target : partialResult) {
+  public void processOutput(Iterable<ConfiguredTarget> partialResult) throws InterruptedException {
+    for (ConfiguredTarget target : partialResult) {
       try {
         StarlarkThread thread =
             new StarlarkThread(Mutability.create("cquery evaluation"), StarlarkSemantics.DEFAULT);
         thread.setMaxExecutionSteps(500_000L);
 
         // Invoke formatFn with `target` argument.
-        Object result =
-            Starlark.fastcall(
-                thread, this.formatFn, new Object[] {target.getConfiguredTarget()}, NO_ARGS);
+        Object result = Starlark.fastcall(thread, this.formatFn, new Object[] {target}, NO_ARGS);
 
         addResult(Starlark.str(result, thread.getSemantics()));
       } catch (EvalException ex) {
@@ -243,7 +240,7 @@
             Event.error(
                 String.format(
                     "Starlark evaluation error for %s: %s",
-                    target.getLabel(), ex.getMessageWithStack())));
+                    target.getOriginalLabel(), ex.getMessageWithStack())));
         continue;
       }
     }
diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java
index 6e5b12f..9cb0d1d 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java
@@ -62,7 +62,7 @@
       CqueryOptions options,
       OutputStream out,
       SkyframeExecutor skyframeExecutor,
-      TargetAccessor<KeyedConfiguredTarget> accessor,
+      TargetAccessor<ConfiguredTarget> accessor,
       @Nullable TransitionFactory<RuleTransitionData> trimmingTransitionFactory,
       RepositoryMapping mainRepoMapping) {
     super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false);
@@ -72,8 +72,7 @@
   }
 
   @Override
-  public void processOutput(Iterable<KeyedConfiguredTarget> partialResult)
-      throws InterruptedException {
+  public void processOutput(Iterable<ConfiguredTarget> partialResult) throws InterruptedException {
     CqueryOptions.Transitions verbosity = options.transitions;
     if (verbosity.equals(CqueryOptions.Transitions.NONE)) {
       eventHandler.handle(
@@ -82,19 +81,17 @@
                   + " flag explicitly to 'lite' or 'full'"));
       return;
     }
-    partialResult.forEach(kct -> partialResultMap.put(kct.getLabel(), accessor.getTarget(kct)));
-    for (KeyedConfiguredTarget keyedConfiguredTarget : partialResult) {
-      Target target = partialResultMap.get(keyedConfiguredTarget.getLabel());
+    partialResult.forEach(
+        kct -> partialResultMap.put(kct.getOriginalLabel(), accessor.getTarget(kct)));
+    for (ConfiguredTarget keyedConfiguredTarget : partialResult) {
+      Target target = partialResultMap.get(keyedConfiguredTarget.getOriginalLabel());
       BuildConfigurationValue config =
           getConfiguration(keyedConfiguredTarget.getConfigurationKey());
       addResult(
-          getRuleClassTransition(keyedConfiguredTarget.getConfiguredTarget(), target)
+          getRuleClassTransition(keyedConfiguredTarget, target)
               + String.format(
                   "%s (%s)",
-                  keyedConfiguredTarget
-                      .getConfiguredTarget()
-                      .getOriginalLabel()
-                      .getDisplayForm(mainRepoMapping),
+                  keyedConfiguredTarget.getOriginalLabel().getDisplayForm(mainRepoMapping),
                   shortId(config)));
       KnownTargetsDependencyResolver knownTargetsDependencyResolver =
           new KnownTargetsDependencyResolver(partialResultMap);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java
index 19f338c..7facee8 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java
@@ -72,6 +72,10 @@
     return SkyFunctions.BUILD_CONFIGURATION;
   }
 
+  public String getOptionsChecksum() {
+    return options.checksum();
+  }
+
   @Override
   public boolean equals(Object o) {
     if (this == o) {
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD b/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD
index 0b9d60f..c9378ab 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD
@@ -19,6 +19,7 @@
     deps = [
         ":configured_target_query_helper",
         ":configured_target_query_test",
+        "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
         "//src/main/java/com/google/devtools/build/lib/events",
         "//src/main/java/com/google/devtools/build/lib/packages",
         "//src/main/java/com/google/devtools/build/lib/query2",
@@ -40,6 +41,7 @@
     deps = [
         ":configured_target_query_helper",
         ":configured_target_query_test",
+        "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
         "//src/main/java/com/google/devtools/build/lib/cmdline",
         "//src/main/java/com/google/devtools/build/lib/events",
         "//src/main/java/com/google/devtools/build/lib/query2",
@@ -63,11 +65,11 @@
         "//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options",
         "//src/main/java/com/google/devtools/build/lib/analysis:config/transition_factories",
         "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/patch_transition",
+        "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
         "//src/main/java/com/google/devtools/build/lib/analysis:test/test_configuration",
         "//src/main/java/com/google/devtools/build/lib/cmdline",
         "//src/main/java/com/google/devtools/build/lib/events",
         "//src/main/java/com/google/devtools/build/lib/packages",
-        "//src/main/java/com/google/devtools/build/lib/query2",
         "//src/main/java/com/google/devtools/build/lib/query2/engine",
         "//src/main/java/com/google/devtools/build/lib/util:filetype",
         "//src/main/java/com/google/devtools/build/lib/vfs",
@@ -85,6 +87,7 @@
     testonly = 1,
     srcs = ["ConfiguredTargetQueryHelper.java"],
     deps = [
+        "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
         "//src/main/java/com/google/devtools/build/lib/query2",
         "//src/main/java/com/google/devtools/build/lib/query2/engine",
         "//src/main/java/com/google/devtools/build/skyframe",
@@ -105,6 +108,7 @@
         "//src/main/java/com/google/devtools/build/lib/analysis:config/build_options",
         "//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options",
         "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/split_transition",
+        "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
         "//src/main/java/com/google/devtools/build/lib/events",
         "//src/main/java/com/google/devtools/build/lib/query2",
         "//src/main/java/com/google/devtools/build/lib/query2/engine",
@@ -125,6 +129,7 @@
         ":configured_target_query_helper",
         ":configured_target_query_test",
         "//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
+        "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
         "//src/main/java/com/google/devtools/build/lib/events",
         "//src/main/java/com/google/devtools/build/lib/packages",
         "//src/main/java/com/google/devtools/build/lib/query2",
@@ -152,6 +157,7 @@
         "//src/main/java/com/google/devtools/build/lib/analysis:config/transition_factories",
         "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/no_transition",
         "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/transition_factory",
+        "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
         "//src/main/java/com/google/devtools/build/lib/cmdline",
         "//src/main/java/com/google/devtools/build/lib/events",
         "//src/main/java/com/google/devtools/build/lib/packages",
@@ -175,6 +181,7 @@
         ":configured_target_query_helper",
         ":configured_target_query_test",
         "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
+        "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
         "//src/main/java/com/google/devtools/build/lib/analysis:top_level_artifact_context",
         "//src/main/java/com/google/devtools/build/lib/events",
         "//src/main/java/com/google/devtools/build/lib/query2",
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java
index 949eaa3..6009318 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java
@@ -19,6 +19,7 @@
 import static com.google.devtools.build.lib.packages.BuildType.OUTPUT;
 
 import com.google.common.eventbus.EventBus;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.util.MockRule;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.Reporter;
@@ -73,7 +74,7 @@
     Set<String> targetPatternSet = new LinkedHashSet<>();
     expression.collectTargetPatterns(targetPatternSet);
     helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS);
-    PostAnalysisQueryEnvironment<KeyedConfiguredTarget> env =
+    PostAnalysisQueryEnvironment<ConfiguredTarget> env =
         ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet);
 
     ByteArrayOutputStream output = new ByteArrayOutputStream();
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java
index a713d59..3953238 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java
@@ -14,6 +14,7 @@
 package com.google.devtools.build.lib.query2.cquery;
 
 import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
 import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment.TopLevelConfigurations;
 import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction;
@@ -30,7 +31,7 @@
  * AnalysisTestCase} must be run manually. @BeforeClass and @AfterClass are completely ignored for
  * now.
  */
-public class ConfiguredTargetQueryHelper extends PostAnalysisQueryHelper<KeyedConfiguredTarget> {
+public class ConfiguredTargetQueryHelper extends PostAnalysisQueryHelper<ConfiguredTarget> {
   @Override
   protected ConfiguredTargetQueryEnvironment getPostAnalysisQueryEnvironment(
       WalkableGraph walkableGraph,
@@ -53,7 +54,7 @@
   }
 
   @Override
-  public String getLabel(KeyedConfiguredTarget target) {
-    return target.getConfiguredTarget().getLabel().toString();
+  public String getLabel(ConfiguredTarget target) {
+    return target.getOriginalLabel().toString();
   }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java
index 1a2534d..2fb6bed 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java
@@ -23,6 +23,7 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
 import com.google.devtools.build.lib.analysis.config.BuildOptions;
 import com.google.devtools.build.lib.analysis.config.BuildOptionsView;
@@ -45,7 +46,6 @@
 import com.google.devtools.build.lib.server.FailureDetails.Query.Code;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.vfs.Path;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -121,9 +121,9 @@
     setUpLabelsFunctionTests();
 
     // Test that this retrieves the correctly configured version(s) of the dep(s).
-    KeyedConfiguredTarget patchDep =
+    ConfiguredTarget patchDep =
         Iterables.getOnlyElement(eval("labels('patch_dep', //test:my_rule)"));
-    KeyedConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
+    ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
     String targetConfiguration = myRule.getConfigurationChecksum();
     assertThat(patchDep.getConfigurationChecksum()).doesNotMatch(targetConfiguration);
   }
@@ -132,12 +132,12 @@
   public void testLabelsFunction_splitTransitionAttribute() throws Exception {
     setUpLabelsFunctionTests();
 
-    KeyedConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
+    ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
     String targetConfiguration = myRule.getConfigurationChecksum();
 
-    Collection<KeyedConfiguredTarget> splitDeps = eval("labels('split_dep', //test:my_rule)");
+    Set<ConfiguredTarget> splitDeps = eval("labels('split_dep', //test:my_rule)");
     assertThat(splitDeps).hasSize(2);
-    for (KeyedConfiguredTarget kct : splitDeps) {
+    for (ConfiguredTarget kct : splitDeps) {
       assertThat(kct.getConfigurationChecksum()).doesNotMatch(targetConfiguration);
     }
   }
@@ -146,13 +146,13 @@
   public void testLabelsFunction_labelListAttribute() throws Exception {
     setUpLabelsFunctionTests();
 
-    KeyedConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
+    ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
     String targetConfiguration = myRule.getConfigurationChecksum();
 
     // Test that this works for label_lists as well.
-    Set<KeyedConfiguredTarget> deps = eval("labels('patch_dep_list', //test:my_rule)");
+    Set<ConfiguredTarget> deps = eval("labels('patch_dep_list', //test:my_rule)");
     assertThat(deps).hasSize(2);
-    for (KeyedConfiguredTarget kct : deps) {
+    for (ConfiguredTarget kct : deps) {
       assertThat(kct.getConfigurationChecksum()).doesNotMatch(targetConfiguration);
     }
   }
@@ -195,7 +195,7 @@
         "rule_with_dep(name = 'actual', dep = ':dep')",
         "rule_with_dep(name = 'dep')");
 
-    KeyedConfiguredTarget dep = Iterables.getOnlyElement(eval("labels('dep', '//test:alias')"));
+    ConfiguredTarget dep = Iterables.getOnlyElement(eval("labels('dep', '//test:alias')"));
     assertThat(dep.getLabel()).isEqualTo(Label.parseCanonicalUnchecked("//test:dep"));
   }
 
@@ -223,12 +223,11 @@
         "alias(name = 'other_impl_dep', actual = 'impl_dep')",
         "simple_rule(name='impl_dep')");
 
-    KeyedConfiguredTarget other = Iterables.getOnlyElement(eval("//test:other_my_rule"));
-    KeyedConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
-    // Note: {@link KeyedConfiguredTarget#getLabel} returns the label of the "actual" value not the
+    ConfiguredTarget other = Iterables.getOnlyElement(eval("//test:other_my_rule"));
+    ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
+    // Note: {@link ConfiguredTarget#getLabel} returns the label of the "actual" value not the
     // label of the alias, so we need to check the underlying label.
-    assertThat(other.getConfiguredTarget().getLabel())
-        .isEqualTo(myRule.getConfiguredTarget().getLabel());
+    assertThat(other.getLabel()).isEqualTo(myRule.getLabel());
 
     // Regression test for b/73496081 in which alias-ed configured targets were skipping filtering.
     helper.setQuerySettings(Setting.ONLY_TARGET_DEPS, Setting.NO_IMPLICIT_DEPS);
@@ -249,7 +248,7 @@
 
     writeFile("test/BUILD", "rule_class_transition(name='rule_class')");
 
-    Set<KeyedConfiguredTarget> ruleClass = eval("//test:rule_class");
+    Set<ConfiguredTarget> ruleClass = eval("//test:rule_class");
     DummyTestOptions testOptions =
         getConfiguration(Iterables.getOnlyElement(ruleClass))
             .getOptions()
@@ -376,10 +375,10 @@
     // setting --universe_scope we ensure only the transitioned version exists.
     helper.setUniverseScope("//test:buildme");
     helper.setQuerySettings(Setting.ONLY_TARGET_DEPS, Setting.NO_IMPLICIT_DEPS);
-    Set<KeyedConfiguredTarget> result = eval("deps(//test:buildme, 1)");
+    Set<ConfiguredTarget> result = eval("deps(//test:buildme, 1)");
     assertThat(result).hasSize(2);
 
-    ImmutableList<KeyedConfiguredTarget> stableOrderList = ImmutableList.copyOf(result);
+    ImmutableList<ConfiguredTarget> stableOrderList = ImmutableList.copyOf(result);
     int myDepIndex = stableOrderList.get(0).getLabel().toString().equals("//test:mydep") ? 0 : 1;
     BuildConfigurationValue myDepConfig = getConfiguration(stableOrderList.get(myDepIndex));
     BuildConfigurationValue stringFlagConfig =
@@ -404,12 +403,11 @@
     createConfigRulesAndBuild();
     writeFile("mytest/BUILD", "simple_rule(name = 'mytarget')");
 
-    Set<KeyedConfiguredTarget> result = eval("//mytest:mytarget");
+    Set<ConfiguredTarget> result = eval("//mytest:mytarget");
     String configHash = getConfiguration(Iterables.getOnlyElement(result)).checksum();
     String hashPrefix = configHash.substring(0, configHash.length() / 2);
 
-    Set<KeyedConfiguredTarget> resultFromPrefix =
-        eval("config(//mytest:mytarget," + hashPrefix + ")");
+    Set<ConfiguredTarget> resultFromPrefix = eval("config(//mytest:mytarget," + hashPrefix + ")");
     assertThat(resultFromPrefix).containsExactlyElementsIn(result);
   }
 
@@ -418,7 +416,7 @@
     createConfigRulesAndBuild();
     writeFile("mytest/BUILD", "simple_rule(name = 'mytarget')");
 
-    Set<KeyedConfiguredTarget> result = eval("//mytest:mytarget");
+    Set<ConfiguredTarget> result = eval("//mytest:mytarget");
     String configHash = getConfiguration(Iterables.getOnlyElement(result)).checksum();
     String rightPrefix = configHash.substring(0, configHash.length() / 2);
     char lastChar = rightPrefix.charAt(rightPrefix.length() - 1);
@@ -504,12 +502,12 @@
   public void testMultipleTopLevelConfigurations_nullConfigs() throws Exception {
     writeFile("test/BUILD", "java_library(name='my_java',", "  srcs = ['foo.java'],", ")");
 
-    Set<KeyedConfiguredTarget> result = eval("//test:my_java+//test:foo.java");
+    Set<ConfiguredTarget> result = eval("//test:my_java+//test:foo.java");
 
     assertThat(result).hasSize(2);
 
-    Iterator<KeyedConfiguredTarget> resultIterator = result.iterator();
-    KeyedConfiguredTarget first = resultIterator.next();
+    Iterator<ConfiguredTarget> resultIterator = result.iterator();
+    ConfiguredTarget first = resultIterator.next();
     if (first.getLabel().toString().equals("//test:foo.java")) {
       assertThat(getConfiguration(first)).isNull();
       assertThat(getConfiguration(resultIterator.next())).isNotNull();
@@ -539,7 +537,7 @@
     // cases cquery prefers the top-level configured one, which won't produce a match since that's
     // not the one down this dependency path.
     helper.setUniverseScope("//test:buildme");
-    Set<KeyedConfiguredTarget> result = eval("somepath(//test:buildme, //test:mydep)");
+    Set<ConfiguredTarget> result = eval("somepath(//test:buildme, //test:mydep)");
     assertThat(result.stream().map(kct -> kct.getLabel().toString()).collect(Collectors.toList()))
         .contains("//test:mydep");
   }
@@ -585,7 +583,7 @@
         "simple_rule(name='foo', deps = [':bar'])",
         "simple_rule(name='bar')");
 
-    Set<KeyedConfiguredTarget> result =
+    Set<ConfiguredTarget> result =
         eval("somepath(//test:top, filter(//test:bar, deps(//test:top)))");
     assertThat(result).isNotEmpty();
   }
@@ -605,7 +603,7 @@
         "simple_rule(name = 'simple')");
 
     helper.setUniverseScope("//test:transitioner,//test:simple");
-    Set<KeyedConfiguredTarget> result = eval("//test:simple");
+    Set<ConfiguredTarget> result = eval("//test:simple");
     assertThat(result.size()).isEqualTo(2);
   }
 
@@ -627,7 +625,7 @@
         "simple_rule(name = 'simple')");
 
     helper.setUniverseScope("//test:transitioner,//test:simple");
-    Set<KeyedConfiguredTarget> result = eval("config(//test:simple, target)");
+    Set<ConfiguredTarget> result = eval("config(//test:simple, target)");
     assertThat(result.size()).isEqualTo(1);
   }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java
index fe7f602..7517601 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java
@@ -18,6 +18,7 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
 import com.google.devtools.build.lib.analysis.config.BuildOptions;
 import com.google.devtools.build.lib.analysis.config.BuildOptionsView;
@@ -37,11 +38,10 @@
 
 /** Tests for {@link ConfiguredTargetQueryEnvironment}. */
 @RunWith(JUnit4.class)
-public abstract class ConfiguredTargetQueryTest
-    extends PostAnalysisQueryTest<KeyedConfiguredTarget> {
+public abstract class ConfiguredTargetQueryTest extends PostAnalysisQueryTest<ConfiguredTarget> {
 
   @Override
-  protected QueryHelper<KeyedConfiguredTarget> createQueryHelper() {
+  protected QueryHelper<ConfiguredTarget> createQueryHelper() {
     return new ConfiguredTargetQueryHelper();
   }
 
@@ -57,7 +57,7 @@
   }
 
   @Override
-  protected final BuildConfigurationValue getConfiguration(KeyedConfiguredTarget kct) {
+  protected final BuildConfigurationValue getConfiguration(ConfiguredTarget kct) {
     return getHelper()
         .getSkyframeExecutor()
         .getConfiguration(getHelper().getReporter(), kct.getConfigurationKey());
@@ -93,12 +93,12 @@
   public void testMultipleTopLevelConfigurations_nullConfigs() throws Exception {
     writeFile("test/BUILD", "java_library(name='my_java',", "  srcs = ['foo.java'],", ")");
 
-    Set<KeyedConfiguredTarget> result = eval("//test:my_java+//test:foo.java");
+    Set<ConfiguredTarget> result = eval("//test:my_java+//test:foo.java");
 
     assertThat(result).hasSize(2);
 
-    Iterator<KeyedConfiguredTarget> resultIterator = result.iterator();
-    KeyedConfiguredTarget first = resultIterator.next();
+    Iterator<ConfiguredTarget> resultIterator = result.iterator();
+    ConfiguredTarget first = resultIterator.next();
     if (first.getLabel().toString().equals("//test:foo.java")) {
       assertThat(getConfiguration(first)).isNull();
       assertThat(getConfiguration(resultIterator.next())).isNotNull();
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java
index 63fc09e..89c17b6 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java
@@ -18,6 +18,7 @@
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.eventbus.EventBus;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.OutputGroupInfo;
 import com.google.devtools.build.lib.analysis.OutputGroupInfo.ValidationMode;
 import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
@@ -111,7 +112,7 @@
     QueryExpression expression = QueryParser.parse(queryExpression, getDefaultFunctions());
     Set<String> targetPatternSet = new LinkedHashSet<>();
     expression.collectTargetPatterns(targetPatternSet);
-    PostAnalysisQueryEnvironment<KeyedConfiguredTarget> env =
+    PostAnalysisQueryEnvironment<ConfiguredTarget> env =
         ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet);
 
     ByteArrayOutputStream output = new ByteArrayOutputStream();
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java
index 2e96a44..aeaa272 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java
@@ -17,6 +17,7 @@
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.eventbus.EventBus;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.cmdline.RepositoryMapping;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.Reporter;
@@ -70,7 +71,7 @@
     Set<String> targetPatternSet = new LinkedHashSet<>();
     expression.collectTargetPatterns(targetPatternSet);
     helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS);
-    PostAnalysisQueryEnvironment<KeyedConfiguredTarget> env =
+    PostAnalysisQueryEnvironment<ConfiguredTarget> env =
         ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet);
 
     ByteArrayOutputStream output = new ByteArrayOutputStream();
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java
index 8b8cf65..70166d5 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java
@@ -22,7 +22,7 @@
 import com.google.common.eventbus.EventBus;
 import com.google.devtools.build.lib.analysis.AnalysisProtosV2;
 import com.google.devtools.build.lib.analysis.AnalysisProtosV2.Configuration;
-import com.google.devtools.build.lib.analysis.AnalysisProtosV2.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
 import com.google.devtools.build.lib.analysis.util.MockRule;
 import com.google.devtools.build.lib.events.Event;
@@ -160,12 +160,13 @@
     List<Configuration> configurations = cqueryResult.getConfigurationsList();
     assertThat(configurations).hasSize(2);
 
-    List<ConfiguredTarget> resultsList = cqueryResult.getResultsList();
+    List<AnalysisProtosV2.ConfiguredTarget> resultsList = cqueryResult.getResultsList();
 
-    ConfiguredTarget parentRuleProto = getRuleProtoByName(resultsList, "//test:parent_rule");
-    Set<KeyedConfiguredTarget> keyedTargets = eval("deps(//test:parent_rule)");
+    AnalysisProtosV2.ConfiguredTarget parentRuleProto =
+        getRuleProtoByName(resultsList, "//test:parent_rule");
+    Set<ConfiguredTarget> keyedTargets = eval("deps(//test:parent_rule)");
 
-    KeyedConfiguredTarget parentRule = getKeyedTargetByLabel(keyedTargets, "//test:parent_rule");
+    ConfiguredTarget parentRule = getKeyedTargetByLabel(keyedTargets, "//test:parent_rule");
     assertThat(parentRuleProto.getConfiguration().getChecksum())
         .isEqualTo(parentRule.getConfigurationChecksum());
 
@@ -183,10 +184,9 @@
                 .setIsTool(false)
                 .build());
 
-    ConfiguredTarget transitionRuleProto =
+    AnalysisProtosV2.ConfiguredTarget transitionRuleProto =
         getRuleProtoByName(resultsList, "//test:transition_rule");
-    KeyedConfiguredTarget transitionRule =
-        getKeyedTargetByLabel(keyedTargets, "//test:transition_rule");
+    ConfiguredTarget transitionRule = getKeyedTargetByLabel(keyedTargets, "//test:transition_rule");
     assertThat(transitionRuleProto.getConfiguration().getChecksum())
         .isEqualTo(transitionRule.getConfigurationChecksum());
 
@@ -195,14 +195,14 @@
     assertThat(transitionConfiguration.getChecksum())
         .isEqualTo(transitionRule.getConfigurationChecksum());
 
-    ConfiguredTarget depRuleProto = getRuleProtoByName(resultsList, "//test:dep");
+    AnalysisProtosV2.ConfiguredTarget depRuleProto = getRuleProtoByName(resultsList, "//test:dep");
     Configuration depRuleConfiguration =
         getConfigurationForId(configurations, depRuleProto.getConfigurationId());
     assertThat(depRuleConfiguration.getPlatformName()).isEqualTo("k8");
     assertThat(depRuleConfiguration.getMnemonic()).matches("k8-opt-exec-.*");
     assertThat(depRuleConfiguration.getIsTool()).isTrue();
 
-    KeyedConfiguredTarget depRule = getKeyedTargetByLabel(keyedTargets, "//test:dep");
+    ConfiguredTarget depRule = getKeyedTargetByLabel(keyedTargets, "//test:dep");
 
     assertThat(depRuleProto.getConfiguration().getChecksum())
         .isEqualTo(depRule.getConfigurationChecksum());
@@ -211,7 +211,7 @@
     assertThat(depRuleConfiguration.getChecksum())
         .isNotEqualTo(transitionConfiguration.getChecksum());
     // Targets without a configuration have a configuration_id of 0.
-    ConfiguredTarget fileTargetProto =
+    AnalysisProtosV2.ConfiguredTarget fileTargetProto =
         resultsList.stream()
             .filter(result -> "//test:patched".equals(result.getTarget().getSourceFile().getName()))
             .findAny()
@@ -238,11 +238,10 @@
         .containsExactly(patchedConfiguredRuleInput, depConfiguredRuleInput);
   }
 
-  private KeyedConfiguredTarget getKeyedTargetByLabel(
-      Set<KeyedConfiguredTarget> keyedTargets, String label) {
+  private ConfiguredTarget getKeyedTargetByLabel(Set<ConfiguredTarget> keyedTargets, String label) {
     return Iterables.getOnlyElement(
         keyedTargets.stream()
-            .filter(t -> label.equals(t.getConfiguredTarget().getLabel().getCanonicalForm()))
+            .filter(t -> label.equals(t.getLabel().getCanonicalForm()))
             .collect(Collectors.toSet()));
   }
 
@@ -250,7 +249,8 @@
     return configurations.stream().filter(c -> c.getId() == id).findAny().orElseThrow();
   }
 
-  private ConfiguredTarget getRuleProtoByName(List<ConfiguredTarget> resultsList, String s) {
+  private AnalysisProtosV2.ConfiguredTarget getRuleProtoByName(
+      List<AnalysisProtosV2.ConfiguredTarget> resultsList, String s) {
     return resultsList.stream()
         .filter(result -> s.equals(result.getTarget().getRule().getName()))
         .findAny()
@@ -316,7 +316,7 @@
     Set<String> targetPatternSet = new LinkedHashSet<>();
     expression.collectTargetPatterns(targetPatternSet);
     helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS);
-    PostAnalysisQueryEnvironment<KeyedConfiguredTarget> env =
+    PostAnalysisQueryEnvironment<ConfiguredTarget> env =
         ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet);
 
     ProtoOutputFormatterCallback callback =
diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java
index 75183e5..7b15a79 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java
@@ -20,6 +20,7 @@
 
 import com.google.common.eventbus.EventBus;
 import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.config.TransitionFactories;
 import com.google.devtools.build.lib.analysis.config.transitions.NoTransition;
 import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory;
@@ -234,7 +235,7 @@
     Set<String> targetPatternSet = new LinkedHashSet<>();
     expression.collectTargetPatterns(targetPatternSet);
     helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS);
-    PostAnalysisQueryEnvironment<KeyedConfiguredTarget> env =
+    PostAnalysisQueryEnvironment<ConfiguredTarget> env =
         ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet);
     options.transitions = verbosity;
     // TODO(blaze-configurability): Test late-bound attributes.