Get rid of LabelAndConfiguration class: ConfiguredTargetKey contains the same information and is more useful, since it's practically a SkyKey.

PiperOrigin-RevId: 179727105
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
index 7ecdede..e47d0e3 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
@@ -301,11 +301,11 @@
   }
 
   /**
-   * Get the {@code LabelAndConfiguration} of the {@code ConfiguredTarget} that owns this artifact,
-   * if it was set. Otherwise, this should be a dummy value -- either {@link
-   * ArtifactOwner#NULL_OWNER} or a dummy owner set in tests. Such a dummy value should only occur
-   * for source artifacts if created without specifying the owner, or for special derived artifacts,
-   * such as target completion middleman artifacts, build info artifacts, and the like.
+   * Gets the {@code ActionLookupKey} of the {@code ConfiguredTarget} that owns this artifact, if it
+   * was set. Otherwise, this should be a dummy value -- either {@link ArtifactOwner#NULL_OWNER} or
+   * a dummy owner set in tests. Such a dummy value should only occur for source artifacts if
+   * created without specifying the owner, or for special derived artifacts, such as target
+   * completion middleman artifacts, build info artifacts, and the like.
    */
   public final ArtifactOwner getArtifactOwner() {
     return owner;
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java
index 94f2963..597893f 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java
@@ -17,23 +17,24 @@
 import com.google.devtools.build.lib.cmdline.Label;
 
 /**
- * An interface for {@code LabelAndConfiguration}, or at least for a {@link Label}. Only tests and
- * internal {@link Artifact}-generators should implement this interface -- otherwise,
- * {@code LabelAndConfiguration} should be the only implementation.
+ * An interface for {@code ActionLookupKey}, or at least for a {@link Label}. Only tests and
+ * internal {@link Artifact}-generators should implement this interface -- otherwise, {@code
+ * ActionLookupKey} and its subclasses should be the only implementation.
  */
 public interface ArtifactOwner {
   Label getLabel();
 
   @VisibleForTesting
-  public static final ArtifactOwner NULL_OWNER = new ArtifactOwner() {
-    @Override
-    public Label getLabel() {
-      return null;
-    }
+  ArtifactOwner NULL_OWNER =
+      new ArtifactOwner() {
+        @Override
+        public Label getLabel() {
+          return null;
+        }
 
-    @Override
-    public String toString() {
-      return "NULL_OWNER";
-    }
-  };
+        @Override
+        public String toString() {
+          return "NULL_OWNER";
+        }
+      };
 }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java
index 0bc37b7..0893a8e 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java
@@ -15,6 +15,7 @@
 package com.google.devtools.build.lib.analysis;
 
 import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 
 /**
  * This event is fired during the build, when it becomes known that the analysis
@@ -22,15 +23,15 @@
  * dependencies.
  */
 public class AnalysisFailureEvent {
-  private final LabelAndConfiguration failedTarget;
+  private final ConfiguredTargetKey failedTarget;
   private final Label failureReason;
 
-  public AnalysisFailureEvent(LabelAndConfiguration failedTarget, Label failureReason) {
+  public AnalysisFailureEvent(ConfiguredTargetKey failedTarget, Label failureReason) {
     this.failedTarget = failedTarget;
     this.failureReason = failureReason;
   }
 
-  public LabelAndConfiguration getFailedTarget() {
+  public ConfiguredTargetKey getFailedTarget() {
     return failedTarget;
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LabelAndConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/LabelAndConfiguration.java
deleted file mode 100644
index eb527f8..0000000
--- a/src/main/java/com/google/devtools/build/lib/analysis/LabelAndConfiguration.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2014 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.analysis;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
-import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
-import com.google.devtools.build.lib.cmdline.Label;
-import java.util.Objects;
-import javax.annotation.Nullable;
-
-/**
-* A (label,configuration) pair.
-*/
-public final class LabelAndConfiguration {
-  private final Label label;
-  @Nullable
-  private final BuildConfiguration configuration;
-
-  private LabelAndConfiguration(Label label, @Nullable BuildConfiguration configuration) {
-    this.label = Preconditions.checkNotNull(label);
-    this.configuration = configuration;
-  }
-
-  public Label getLabel() {
-    return label;
-  }
-
-  @Nullable
-  public BuildConfiguration getConfiguration() {
-    return configuration;
-  }
-
-  @Override
-  public int hashCode() {
-    int configVal = configuration == null ? 79 : configuration.hashCode();
-    return 31 * label.hashCode() + configVal;
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (this == obj) {
-      return true;
-    }
-    if (obj == null) {
-      return false;
-    }
-    if (!(obj instanceof LabelAndConfiguration)) {
-      return false;
-    }
-    LabelAndConfiguration other = (LabelAndConfiguration) obj;
-    return Objects.equals(label, other.label) && Objects.equals(configuration, other.configuration);
-  }
-
-  public static LabelAndConfiguration of(
-      Label label, @Nullable BuildConfiguration configuration) {
-    return new LabelAndConfiguration(label, configuration);
-  }
-
-  public static LabelAndConfiguration of(ConfiguredTarget configuredTarget) {
-    AliasProvider aliasProvider = configuredTarget.getProvider(AliasProvider.class);
-    Label label = aliasProvider != null
-        ? aliasProvider.getAliasChain().get(0)
-        : configuredTarget.getLabel();
-
-    return new LabelAndConfiguration(label, configuredTarget.getConfiguration());
-  }
-
-  @Override
-  public String toString() {
-    return MoreObjects.toStringHelper(this)
-        .add("label", label)
-        .add("configuration", configuration)
-        .toString();
-  }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Util.java b/src/main/java/com/google/devtools/build/lib/analysis/Util.java
index aa12b40..02d05b5 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Util.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Util.java
@@ -22,6 +22,7 @@
 import com.google.devtools.build.lib.collect.compacthashset.CompactHashSet;
 import com.google.devtools.build.lib.packages.AttributeMap;
 import com.google.devtools.build.lib.packages.Target;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import java.util.List;
 import java.util.Set;
@@ -77,10 +78,10 @@
    * build file and all toolchain deps.
    * note: nodes that are depended on both implicitly and explicitly are considered explicit.
    */
-  public static ImmutableSet<LabelAndConfiguration> findImplicitDeps(RuleContext ruleContext) {
+  public static ImmutableSet<ConfiguredTargetKey> findImplicitDeps(RuleContext ruleContext) {
     // (1) Consider rule attribute dependencies.
-    Set<LabelAndConfiguration> maybeImplicitDeps = CompactHashSet.create();
-    Set<LabelAndConfiguration> explicitDeps = CompactHashSet.create();
+    Set<ConfiguredTargetKey> maybeImplicitDeps = CompactHashSet.create();
+    Set<ConfiguredTargetKey> explicitDeps = CompactHashSet.create();
     AttributeMap attributes = ruleContext.attributes();
     ListMultimap<String, ? extends TransitiveInfoCollection> targetMap =
         ruleContext.getConfiguredTargetMap();
@@ -99,19 +100,19 @@
     if (toolchainContext != null) {
       BuildConfiguration config = ruleContext.getConfiguration();
       for (Label toolchain : toolchainContext.getResolvedToolchainLabels()) {
-        maybeImplicitDeps.add(LabelAndConfiguration.of(toolchain, config));
+        maybeImplicitDeps.add(ConfiguredTargetKey.of(toolchain, config));
       }
       maybeImplicitDeps.add(
-          LabelAndConfiguration.of(toolchainContext.getExecutionPlatform().label(), config));
+          ConfiguredTargetKey.of(toolchainContext.getExecutionPlatform().label(), config));
       maybeImplicitDeps.add(
-          LabelAndConfiguration.of(toolchainContext.getTargetPlatform().label(), config));
+          ConfiguredTargetKey.of(toolchainContext.getTargetPlatform().label(), config));
     }
     return ImmutableSet.copyOf(Sets.difference(maybeImplicitDeps, explicitDeps));
   }
 
   private static void addLabelsAndConfigs(
-      Set<LabelAndConfiguration> set, List<? extends TransitiveInfoCollection> deps) {
+      Set<ConfiguredTargetKey> set, List<? extends TransitiveInfoCollection> deps) {
     deps.forEach(
-        target -> set.add(LabelAndConfiguration.of(target.getLabel(), target.getConfiguration())));
+        target -> set.add(ConfiguredTargetKey.of(target.getLabel(), target.getConfiguration())));
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java
index d95c4d3..30959f7 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java
@@ -20,7 +20,6 @@
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.FileProvider;
 import com.google.devtools.build.lib.analysis.FilesToRunProvider;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.analysis.RunfilesProvider;
@@ -38,6 +37,7 @@
 import com.google.devtools.build.lib.packages.OutputFile;
 import com.google.devtools.build.lib.packages.Provider;
 import com.google.devtools.build.lib.packages.Rule;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
 import com.google.devtools.build.lib.syntax.Printer;
 import java.util.function.Consumer;
@@ -63,14 +63,14 @@
     DONT_CHECK
   }
   /** A set of this target's implicitDeps. */
-  private final ImmutableSet<LabelAndConfiguration> implicitDeps;
+  private final ImmutableSet<ConfiguredTargetKey> implicitDeps;
 
   /*
    * An interner for the implicitDeps set. {@link Util.findImplicitDeps} is called upon every
    * construction of a RuleConfiguredTarget and we expect many of these targets to contain the same
    * set of implicit deps so this reduces the memory load per build.
    */
-  private static final Interner<ImmutableSet<LabelAndConfiguration>> IMPLICIT_DEPS_INTERNER =
+  private static final Interner<ImmutableSet<ConfiguredTargetKey>> IMPLICIT_DEPS_INTERNER =
       BlazeInterners.newWeakInterner();
 
   private final TransitiveInfoProviderMap providers;
@@ -124,7 +124,7 @@
     return configConditions;
   }
 
-  public ImmutableSet<LabelAndConfiguration> getImplicitDeps() {
+  public ImmutableSet<ConfiguredTargetKey> getImplicitDeps() {
     return implicitDeps;
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java
index 73e253ec..f710867 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java
@@ -21,7 +21,6 @@
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
 import com.google.devtools.build.lib.cmdline.Label;
@@ -104,14 +103,14 @@
 
   private static final Function<ConfiguredTarget, SkyKey> CT_TO_SKYKEY =
       target -> ConfiguredTargetValue.key(target.getLabel(), target.getConfiguration());
-  private static final Function<SkyKey, LabelAndConfiguration> SKYKEY_TO_LANDC =
+  private static final Function<SkyKey, ConfiguredTargetKey> SKYKEY_TO_CTKEY =
       skyKey -> {
         ConfiguredTargetKey key = (ConfiguredTargetKey) skyKey.argument();
-        return LabelAndConfiguration.of(key.getLabel(), key.getConfiguration());
+        return ConfiguredTargetKey.of(key.getLabel(), key.getConfiguration());
       };
   private static final ImmutableList<TargetPatternKey> ALL_PATTERNS;
-  private static final KeyExtractor<ConfiguredTarget, LabelAndConfiguration>
-      CONFIGURED_TARGET_KEY_EXTRACTOR = LabelAndConfiguration::of;
+  private static final KeyExtractor<ConfiguredTarget, ConfiguredTargetKey>
+      CONFIGURED_TARGET_KEY_EXTRACTOR = ConfiguredTargetKey::of;
 
   static {
     TargetPattern targetPattern;
@@ -310,13 +309,13 @@
       }
     }
     if (settings.contains(Setting.NO_IMPLICIT_DEPS) && target instanceof RuleConfiguredTarget) {
-      Set<LabelAndConfiguration> implicitDeps = ((RuleConfiguredTarget) target).getImplicitDeps();
+      Set<ConfiguredTargetKey> implicitDeps = ((RuleConfiguredTarget) target).getImplicitDeps();
       deps =
           deps.stream()
               .filter(
                   dep ->
                       !implicitDeps.contains(
-                          LabelAndConfiguration.of(
+                          ConfiguredTargetKey.of(
                               dep.getTarget().getLabel(), dep.getConfiguration())))
               .collect(Collectors.toList());
     }
@@ -333,10 +332,10 @@
     Map<SkyKey, Collection<ConfiguredTarget>> directDeps =
         targetifyValues(graph.getDirectDeps(targetsByKey.keySet()));
     if (targetsByKey.keySet().size() != directDeps.keySet().size()) {
-      Iterable<LabelAndConfiguration> missingTargets =
+      Iterable<ConfiguredTargetKey> missingTargets =
           Sets.difference(targetsByKey.keySet(), directDeps.keySet())
               .stream()
-              .map(SKYKEY_TO_LANDC)
+              .map(SKYKEY_TO_CTKEY)
               .collect(Collectors.toList());
       eventHandler.handle(Event.warn("Targets were missing from graph: " + missingTargets));
     }
@@ -376,10 +375,10 @@
     Map<SkyKey, Collection<ConfiguredTarget>> reverseDepsByKey =
         targetifyValues(graph.getReverseDeps(targetsByKey.keySet()));
     if (targetsByKey.size() != reverseDepsByKey.size()) {
-      Iterable<LabelAndConfiguration> missingTargets =
+      Iterable<ConfiguredTargetKey> missingTargets =
           Sets.difference(targetsByKey.keySet(), reverseDepsByKey.keySet())
               .stream()
-              .map(SKYKEY_TO_LANDC)
+              .map(SKYKEY_TO_CTKEY)
               .collect(Collectors.toList());
       eventHandler.handle(Event.warn("Targets were missing from graph: " + missingTargets));
     }
@@ -407,7 +406,7 @@
   @Override
   public ImmutableList<ConfiguredTarget> getNodesOnPath(ConfiguredTarget from, ConfiguredTarget to)
       throws InterruptedException {
-    return SkyQueryUtils.getNodesOnPath(from, to, this::getFwdDeps, LabelAndConfiguration::of);
+    return SkyQueryUtils.getNodesOnPath(from, to, this::getFwdDeps, ConfiguredTargetKey::of);
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/AggregatingTestListener.java b/src/main/java/com/google/devtools/build/lib/runtime/AggregatingTestListener.java
index a4a77c4..b5ec577 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/AggregatingTestListener.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/AggregatingTestListener.java
@@ -30,7 +30,6 @@
 import com.google.devtools.build.lib.analysis.AliasProvider;
 import com.google.devtools.build.lib.analysis.AnalysisFailureEvent;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.TargetCompleteEvent;
 import com.google.devtools.build.lib.analysis.test.TestProvider;
 import com.google.devtools.build.lib.analysis.test.TestResult;
@@ -40,6 +39,7 @@
 import com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent;
 import com.google.devtools.build.lib.concurrent.ThreadSafety;
 import com.google.devtools.build.lib.rules.test.TestAttempt;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus;
 import java.util.Collection;
 import java.util.Collections;
@@ -61,8 +61,8 @@
 
   // summaryLock guards concurrent access to these two collections, which should be kept
   // synchronized with each other.
-  private final Map<LabelAndConfiguration, TestSummary.Builder> summaries;
-  private final Multimap<LabelAndConfiguration, Artifact> remainingRuns;
+  private final Map<ConfiguredTargetKey, TestSummary.Builder> summaries;
+  private final Multimap<ConfiguredTargetKey, Artifact> remainingRuns;
   private final Object summaryLock = new Object();
 
   public AggregatingTestListener(TestResultAnalyzer analyzer, EventBus eventBus) {
@@ -122,8 +122,8 @@
         "Duplicate result reported for an individual test shard");
 
     ActionOwner testOwner = result.getTestAction().getOwner();
-    LabelAndConfiguration targetLabel = LabelAndConfiguration.of(
-        testOwner.getLabel(), result.getTestAction().getConfiguration());
+    ConfiguredTargetKey targetLabel =
+        ConfiguredTargetKey.of(testOwner.getLabel(), result.getTestAction().getConfiguration());
 
     // If a test result was cached, then no attempts for that test were actually
     // executed. Hence report that fact as a cached attempt.
@@ -155,17 +155,17 @@
     }
   }
 
-  private void targetFailure(LabelAndConfiguration label) {
+  private void targetFailure(ConfiguredTargetKey configuredTargetKey) {
     TestSummary finalSummary;
     synchronized (summaryLock) {
-      if (!remainingRuns.containsKey(label)) {
+      if (!remainingRuns.containsKey(configuredTargetKey)) {
         // Blaze does not guarantee that BuildResult.getSuccessfulTargets() and posted TestResult
         // events are in sync. Thus, it is possible that a test event was posted, but the target is
         // not present in the set of successful targets.
         return;
       }
 
-      TestSummary.Builder summary = summaries.get(label);
+      TestSummary.Builder summary = summaries.get(configuredTargetKey);
       if (summary == null) {
         // Not a test target; nothing to do.
         return;
@@ -176,7 +176,7 @@
               .build();
 
       // These are never going to run; removing them marks the target complete.
-      remainingRuns.removeAll(label);
+      remainingRuns.removeAll(configuredTargetKey);
     }
     eventBus.post(finalSummary);
   }
@@ -222,7 +222,7 @@
   @AllowConcurrentEvents
   public void targetComplete(TargetCompleteEvent event) {
     if (event.failed()) {
-      targetFailure(LabelAndConfiguration.of(event.getTarget()));
+      targetFailure(ConfiguredTargetKey.of(event.getTarget()));
     }
   }
 
@@ -261,8 +261,8 @@
     return analyzer;
   }
 
-  private LabelAndConfiguration asKey(ConfiguredTarget target) {
-    return LabelAndConfiguration.of(
+  private ConfiguredTargetKey asKey(ConfiguredTarget target) {
+    return ConfiguredTargetKey.of(
         AliasProvider.getDependencyLabel(target), target.getConfiguration());
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionArtifactCycleReporter.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionArtifactCycleReporter.java
index 8808252..8c49441f 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionArtifactCycleReporter.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionArtifactCycleReporter.java
@@ -54,10 +54,10 @@
       return "action from: " + arg;
     } else if (arg instanceof TargetCompletionKey
         && skyFunctionName.equals(SkyFunctions.TARGET_COMPLETION)) {
-      return "configured target: " + ((TargetCompletionKey) arg).labelAndConfiguration().getLabel();
+      return "configured target: " + ((TargetCompletionKey) arg).configuredTargetKey().getLabel();
     } else if (arg instanceof TestCompletionKey
         && skyFunctionName.equals(SkyFunctions.TEST_COMPLETION)) {
-      return  "test target: " + ((TestCompletionKey) arg).labelAndConfiguration().getLabel();
+      return "test target: " + ((TestCompletionKey) arg).configuredTargetKey().getLabel();
     }
     throw new IllegalStateException(
         "Argument is not Action, TargetCompletion, TestCompletion or OwnedArtifact: " + arg);
@@ -72,10 +72,10 @@
       return ((ActionLookupData) arg).getLabelForErrors();
     } else if (arg instanceof TargetCompletionKey
         && key.functionName().equals(SkyFunctions.TARGET_COMPLETION)) {
-      return ((TargetCompletionKey) arg).labelAndConfiguration().getLabel();
+      return ((TargetCompletionKey) arg).configuredTargetKey().getLabel();
     } else if (arg instanceof TestCompletionKey
         && key.functionName().equals(SkyFunctions.TEST_COMPLETION)) {
-      return  ((TestCompletionKey) arg).labelAndConfiguration().getLabel();
+      return ((TestCompletionKey) arg).configuredTargetKey().getLabel();
     }
     throw new IllegalStateException(
         "Argument is not Action, TargetCompletion, TestCompletion or OwnedArtifact: " + arg);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java
index 6853398..103fd73 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java
@@ -19,7 +19,6 @@
 import com.google.devtools.build.lib.actions.MissingInputFileException;
 import com.google.devtools.build.lib.analysis.AspectCompleteEvent;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.TargetCompleteEvent;
 import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
 import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper;
@@ -101,7 +100,7 @@
     public ConfiguredTargetValue getValueFromSkyKey(SkyKey skyKey, Environment env)
         throws InterruptedException {
       TargetCompletionKey tcKey = (TargetCompletionKey) skyKey.argument();
-      LabelAndConfiguration lac = tcKey.labelAndConfiguration();
+      ConfiguredTargetKey lac = tcKey.configuredTargetKey();
       return (ConfiguredTargetValue)
           env.getValue(ConfiguredTargetValue.key(lac.getLabel(), lac.getConfiguration()));
     }
@@ -151,7 +150,7 @@
     @Override
     public String extractTag(SkyKey skyKey) {
       return Label.print(
-          ((TargetCompletionKey) skyKey.argument()).labelAndConfiguration().getLabel());
+          ((TargetCompletionKey) skyKey.argument()).configuredTargetKey().getLabel());
     }
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
index 51584f2..af83e3c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
@@ -30,7 +30,6 @@
 import com.google.devtools.build.lib.analysis.ConfiguredTargetFactory;
 import com.google.devtools.build.lib.analysis.Dependency;
 import com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.TargetAndConfiguration;
 import com.google.devtools.build.lib.analysis.ToolchainContext;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -141,13 +140,12 @@
         storeTransitivePackagesForPackageRootResolution ? NestedSetBuilder.stableOrder() : null;
     NestedSetBuilder<Label> transitiveLoadingRootCauses = NestedSetBuilder.stableOrder();
     ConfiguredTargetKey configuredTargetKey = (ConfiguredTargetKey) key.argument();
-    LabelAndConfiguration lc = LabelAndConfiguration.of(
-        configuredTargetKey.getLabel(), configuredTargetKey.getConfiguration());
+    Label label = configuredTargetKey.getLabel();
 
-    BuildConfiguration configuration = lc.getConfiguration();
+    BuildConfiguration configuration = configuredTargetKey.getConfiguration();
 
     PackageValue packageValue =
-        (PackageValue) env.getValue(PackageValue.key(lc.getLabel().getPackageIdentifier()));
+        (PackageValue) env.getValue(PackageValue.key(label.getPackageIdentifier()));
     if (packageValue == null) {
       return null;
     }
@@ -157,13 +155,13 @@
     Package pkg = packageValue.getPackage();
     Target target;
     try {
-      target = pkg.getTarget(lc.getLabel().getName());
+      target = pkg.getTarget(label.getName());
     } catch (NoSuchTargetException e) {
       throw new ConfiguredTargetFunctionException(
-          new ConfiguredValueCreationException(e.getMessage(), lc.getLabel()));
+          new ConfiguredValueCreationException(e.getMessage(), label));
     }
     if (pkg.containsErrors()) {
-      transitiveLoadingRootCauses.add(lc.getLabel());
+      transitiveLoadingRootCauses.add(label);
     }
     if (transitivePackagesForPackageRootResolution != null) {
       transitivePackagesForPackageRootResolution.add(pkg);
@@ -181,8 +179,9 @@
     // associates the corresponding error with this target, as expected. Without this line,
     // the first TransitiveTargetValue call happens on its dep (in trimConfigurations), so Bazel
     // associates the error with the dep, which is misleading.
-    if (configuration != null && configuration.trimConfigurations()
-        && env.getValue(TransitiveTargetKey.of(lc.getLabel())) == null) {
+    if (configuration != null
+        && configuration.trimConfigurations()
+        && env.getValue(TransitiveTargetKey.of(label)) == null) {
       return null;
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java
index 7be2757..c02fd99 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java
@@ -14,8 +14,10 @@
 
 package com.google.devtools.build.lib.skyframe;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey;
+import com.google.devtools.build.lib.analysis.AliasProvider;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.cmdline.Label;
@@ -39,10 +41,22 @@
     this.configuration = configuration;
   }
 
+  @VisibleForTesting
   public ConfiguredTargetKey(ConfiguredTarget rule) {
     this(rule.getTarget().getLabel(), rule.getConfiguration());
   }
 
+  public static ConfiguredTargetKey of(ConfiguredTarget configuredTarget) {
+    AliasProvider aliasProvider = configuredTarget.getProvider(AliasProvider.class);
+    Label label =
+        aliasProvider != null ? aliasProvider.getAliasChain().get(0) : configuredTarget.getLabel();
+    return of(label, configuredTarget.getConfiguration());
+  }
+
+  public static ConfiguredTargetKey of(Label label, @Nullable BuildConfiguration configuration) {
+    return new ConfiguredTargetKey(label, configuration);
+  }
+
   @Override
   public Label getLabel() {
     return label;
@@ -94,5 +108,4 @@
         System.identityHashCode(this),
         (configuration == null ? "null" : System.identityHashCode(configuration)));
   }
-
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
index c3c7d6b..779dbaa 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
@@ -21,7 +21,6 @@
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.Dependency;
 import com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.TargetAndConfiguration;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
@@ -167,7 +166,7 @@
   @Nullable
   @Override
   public String extractTag(SkyKey skyKey) {
-    return Label.print(((LabelAndConfiguration) skyKey.argument()).getLabel());
+    return Label.print(((ConfiguredTargetKey) skyKey.argument()).getLabel());
   }
 
   private static class ActionConflictFunctionException extends SkyFunctionException {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
index 74c1cba..a62d501 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
@@ -40,7 +40,6 @@
 import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.ConfiguredTargetFactory;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.ToolchainContext;
 import com.google.devtools.build.lib.analysis.ViewCreationFailedException;
 import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory;
@@ -348,8 +347,10 @@
           Event.warn("errors encountered while analyzing target '"
               + topLevelLabel + "': it will not be built"));
       if (analysisRootCause != null) {
-        eventBus.post(new AnalysisFailureEvent(
-            LabelAndConfiguration.of(topLevelLabel, label.getConfiguration()), analysisRootCause));
+        eventBus.post(
+            new AnalysisFailureEvent(
+                ConfiguredTargetKey.of(topLevelLabel, label.getConfiguration()),
+                analysisRootCause));
       }
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetCompletionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetCompletionValue.java
index 476f69d..c08f5a6 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetCompletionValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetCompletionValue.java
@@ -17,7 +17,6 @@
 import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
 import com.google.devtools.build.skyframe.LegacySkyKey;
 import com.google.devtools.build.skyframe.SkyKey;
@@ -39,11 +38,10 @@
   }
 
   public static SkyKey key(
-      LabelAndConfiguration labelAndConfiguration,
-      TopLevelArtifactContext topLevelArtifactContext) {
+      ConfiguredTargetKey configuredTargetKey, TopLevelArtifactContext topLevelArtifactContext) {
     return LegacySkyKey.create(
         SkyFunctions.TARGET_COMPLETION,
-        TargetCompletionKey.create(labelAndConfiguration, topLevelArtifactContext));
+        TargetCompletionKey.create(configuredTargetKey, topLevelArtifactContext));
   }
 
   public static Iterable<SkyKey> keys(Collection<ConfiguredTarget> targets,
@@ -55,7 +53,7 @@
           public SkyKey apply(ConfiguredTarget ct) {
             return LegacySkyKey.create(
                 SkyFunctions.TARGET_COMPLETION,
-                TargetCompletionKey.create(LabelAndConfiguration.of(ct), ctx));
+                TargetCompletionKey.create(ConfiguredTargetKey.of(ct), ctx));
           }
         });
   }
@@ -63,13 +61,13 @@
   @AutoValue
   abstract static class TargetCompletionKey {
     public static TargetCompletionKey create(
-        LabelAndConfiguration labelAndConfiguration,
-        TopLevelArtifactContext topLevelArtifactContext) {
+        ConfiguredTargetKey configuredTargetKey, TopLevelArtifactContext topLevelArtifactContext) {
       return new AutoValue_TargetCompletionValue_TargetCompletionKey(
-          labelAndConfiguration, topLevelArtifactContext);
+          configuredTargetKey, topLevelArtifactContext);
     }
 
-    public abstract LabelAndConfiguration labelAndConfiguration();
+    abstract ConfiguredTargetKey configuredTargetKey();
+
     public abstract TopLevelArtifactContext topLevelArtifactContext();
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java
index dcdf47e..d476098 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java
@@ -15,7 +15,6 @@
 
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
 import com.google.devtools.build.lib.analysis.test.TestProvider;
 import com.google.devtools.build.lib.cmdline.Label;
@@ -33,7 +32,7 @@
   public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
     TestCompletionValue.TestCompletionKey key =
         (TestCompletionValue.TestCompletionKey) skyKey.argument();
-    LabelAndConfiguration lac = key.labelAndConfiguration();
+    ConfiguredTargetKey lac = key.configuredTargetKey();
     TopLevelArtifactContext ctx = key.topLevelArtifactContext();
     if (env.getValue(TargetCompletionValue.key(lac, ctx)) == null) {
       return null;
@@ -64,6 +63,6 @@
 
   @Override
   public String extractTag(SkyKey skyKey) {
-    return Label.print(((LabelAndConfiguration) skyKey.argument()).getLabel());
+    return Label.print(((ConfiguredTargetKey) skyKey.argument()).getLabel());
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java
index 68e09f2..b435720 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java
@@ -17,7 +17,6 @@
 import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
 import com.google.devtools.build.skyframe.LegacySkyKey;
 import com.google.devtools.build.skyframe.SkyKey;
@@ -34,7 +33,7 @@
   private TestCompletionValue() { }
 
   public static SkyKey key(
-      LabelAndConfiguration lac,
+      ConfiguredTargetKey lac,
       final TopLevelArtifactContext topLevelArtifactContext,
       final boolean exclusiveTesting) {
     return LegacySkyKey.create(
@@ -53,7 +52,7 @@
             return LegacySkyKey.create(
                 SkyFunctions.TEST_COMPLETION,
                 TestCompletionKey.create(
-                    LabelAndConfiguration.of(ct), topLevelArtifactContext, exclusiveTesting));
+                    ConfiguredTargetKey.of(ct), topLevelArtifactContext, exclusiveTesting));
           }
         });
   }
@@ -62,14 +61,15 @@
   abstract static class TestCompletionKey {
 
     public static TestCompletionKey create(
-        LabelAndConfiguration labelAndConfiguration,
+        ConfiguredTargetKey configuredTargetKey,
         TopLevelArtifactContext topLevelArtifactContext,
         boolean exclusiveTesting) {
       return new AutoValue_TestCompletionValue_TestCompletionKey(
-          labelAndConfiguration, topLevelArtifactContext, exclusiveTesting);
+          configuredTargetKey, topLevelArtifactContext, exclusiveTesting);
     }
 
-    public abstract LabelAndConfiguration labelAndConfiguration();
+    abstract ConfiguredTargetKey configuredTargetKey();
+
     public abstract TopLevelArtifactContext topLevelArtifactContext();
     public abstract boolean exclusiveTesting();
   }
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
index ba1641b..aae20bb 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
@@ -56,7 +56,6 @@
 import com.google.devtools.build.lib.analysis.ExtraActionArtifactsProvider;
 import com.google.devtools.build.lib.analysis.FileProvider;
 import com.google.devtools.build.lib.analysis.FilesToRunProvider;
-import com.google.devtools.build.lib.analysis.LabelAndConfiguration;
 import com.google.devtools.build.lib.analysis.OutputGroupInfo;
 import com.google.devtools.build.lib.analysis.PseudoAction;
 import com.google.devtools.build.lib.analysis.RuleContext;
@@ -982,12 +981,12 @@
 
   /**
    * Gets a derived artifact, creating it if necessary. {@code ArtifactOwner} should be a genuine
-   * {@link LabelAndConfiguration} corresponding to a {@link ConfiguredTarget}. If called from a
-   * test that does not exercise the analysis phase, the convenience methods {@link
+   * {@link ConfiguredTargetKey} corresponding to a {@link ConfiguredTarget}. If called from a test
+   * that does not exercise the analysis phase, the convenience methods {@link
    * #getBinArtifactWithNoOwner} or {@link #getGenfilesArtifactWithNoOwner} should be used instead.
    */
-  protected Artifact getDerivedArtifact(PathFragment rootRelativePath, Root root,
-      ArtifactOwner owner) {
+  protected Artifact getDerivedArtifact(
+      PathFragment rootRelativePath, Root root, ArtifactOwner owner) {
     return view.getArtifactFactory().getDerivedArtifact(rootRelativePath, root, owner);
   }
 
@@ -1023,7 +1022,7 @@
    * be "foo.o".
    */
   protected Artifact getBinArtifact(String packageRelativePath, String owner) {
-    ConfiguredTargetKey config = makeLabelAndConfiguration(owner);
+    ConfiguredTargetKey config = makeConfiguredTargetKey(owner);
     return getPackageRelativeDerivedArtifact(
         packageRelativePath,
         config.getConfiguration().getBinDirectory(RepositoryName.MAIN),
@@ -1102,7 +1101,7 @@
    * just be "foo.o".
    */
   protected Artifact getGenfilesArtifact(String packageRelativePath, String owner) {
-    ConfiguredTargetKey configKey = makeLabelAndConfiguration(owner);
+    ConfiguredTargetKey configKey = makeConfiguredTargetKey(owner);
     return getGenfilesArtifact(packageRelativePath, configKey, configKey.getConfiguration());
   }
 
@@ -1180,7 +1179,7 @@
    * just be "foo.h".
    */
   protected Artifact getIncludeArtifact(String packageRelativePath, String owner) {
-    return getIncludeArtifact(packageRelativePath, makeLabelAndConfiguration(owner));
+    return getIncludeArtifact(packageRelativePath, makeConfiguredTargetKey(owner));
   }
 
   /**
@@ -1294,7 +1293,7 @@
     }
   }
 
-  private ConfiguredTargetKey makeLabelAndConfiguration(String label) {
+  private ConfiguredTargetKey makeConfiguredTargetKey(String label) {
     BuildConfiguration config;
     try {
       config = getConfiguredTarget(label).getConfiguration();