Skip to content

Commit

Permalink
Tighten the type of top-level aspect values to AspectValue to avoid…
Browse files Browse the repository at this point in the history
… unnecessary casting.

PiperOrigin-RevId: 489295592
Change-Id: I8e0fa5220ebd9cf08cec97f32b7f18415eab623c
  • Loading branch information
justinhorvitz authored and copybara-github committed Nov 17, 2022
1 parent 3b5eef5 commit bc75deb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.devtools.build.lib.actions.ActionExecutionStatusReporter;
import com.google.devtools.build.lib.actions.ActionLookupData;
import com.google.devtools.build.lib.actions.MiddlemanType;
import com.google.devtools.build.lib.analysis.AspectValue;
import com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog;
import com.google.devtools.build.lib.skyframe.AspectCompletionValue;
import com.google.devtools.build.lib.skyframe.AspectKeyCreator;
Expand Down Expand Up @@ -148,7 +147,7 @@ public void evaluated(
if (buildDriverKey.isTopLevelAspectDriver()) {
((TopLevelAspectsValue) buildDriverValue.getWrappedSkyValue())
.getTopLevelAspectsValues()
.forEach(x -> eventBus.post(AspectBuiltEvent.create(((AspectValue) x).getKey())));
.forEach(x -> eventBus.post(AspectBuiltEvent.create(x.getKey())));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,7 @@ java_library(
srcs = ["TopLevelAspectsValue.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//third_party:guava",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ private void announceAspectAnalysisDoneAndRequestExecution(
env.getListener().post(SomeExecutionStartedEvent.create());
ImmutableSet.Builder<Artifact> artifactsToBuild = ImmutableSet.builder();
List<SkyKey> aspectCompletionKeys = new ArrayList<>();
for (SkyValue value : topLevelAspectsValue.getTopLevelAspectsValues()) {
AspectValue aspectValue = (AspectValue) value;
for (AspectValue aspectValue : topLevelAspectsValue.getTopLevelAspectsValues()) {
AspectKey aspectKey = aspectValue.getKey();
ConfiguredAspect configuredAspect = aspectValue.getConfiguredAspect();
addExtraActionsIfRequested(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ public SkyframeAnalysisResult configureTargets(
// Skip aspects that couldn't be applied to targets.
continue;
}
for (SkyValue val : value.getTopLevelAspectsValues()) {
AspectValue aspectValue = (AspectValue) val;
for (AspectValue aspectValue : value.getTopLevelAspectsValues()) {
aspects.put(aspectValue.getKey(), aspectValue.getConfiguredAspect());
if (packages != null) {
packages.addTransitive(Preconditions.checkNotNull(aspectValue.getTransitivePackages()));
Expand Down Expand Up @@ -999,7 +998,7 @@ private ImmutableSet<AspectKey> getDerivedAspectKeysForConflictReporting(
skyframeExecutor.getDoneSkyValueForIntrospection(topLevelAspectsKey);
topLevelAspectsValue
.getTopLevelAspectsValues()
.forEach((aspectValue) -> aspectKeysBuilder.add(((AspectValue) aspectValue).getKey()));
.forEach(aspectValue -> aspectKeysBuilder.add(aspectValue.getKey()));
} catch (FailureToRetrieveIntrospectedValueException e) {
// It could happen that the analysis of TopLevelAspectKey wasn't complete: either its own
// analysis failed, or another error was raise in --nokeep_going mode. In that case, it
Expand Down Expand Up @@ -1054,8 +1053,7 @@ private static ImmutableMap<AspectKey, ConfiguredAspect> getSuccessfulAspectMap(
continue;
}
TopLevelAspectsValue topLevelAspectsValue = (TopLevelAspectsValue) value.getWrappedSkyValue();
for (SkyValue val : topLevelAspectsValue.getTopLevelAspectsValues()) {
AspectValue aspectValue = (AspectValue) val;
for (AspectValue aspectValue : topLevelAspectsValue.getTopLevelAspectsValues()) {
aspects.put(aspectValue.getKey(), aspectValue.getConfiguredAspect());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@

package com.google.devtools.build.lib.skyframe;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
import com.google.devtools.build.lib.actions.ActionLookupValue;
import com.google.devtools.build.skyframe.SkyValue;
import java.util.Collection;
import com.google.devtools.build.lib.analysis.AspectValue;

/**
* SkyValue for {@code TopLevelAspectsKey} wraps a list of the {@code AspectValue} of the top level
* aspects applied on the same top level target.
*/
public class TopLevelAspectsValue implements ActionLookupValue {
private final ImmutableList<SkyValue> topLevelAspectsValues;
public final class TopLevelAspectsValue implements ActionLookupValue {
private final ImmutableList<AspectValue> topLevelAspectsValues;

public TopLevelAspectsValue(Collection<SkyValue> topLevelAspectsValues) {
this.topLevelAspectsValues = ImmutableList.copyOf(topLevelAspectsValues);
public TopLevelAspectsValue(ImmutableList<AspectValue> topLevelAspectsValues) {
this.topLevelAspectsValues = checkNotNull(topLevelAspectsValues);
}

public ImmutableList<SkyValue> getTopLevelAspectsValues() {
public ImmutableList<AspectValue> getTopLevelAspectsValues() {
return topLevelAspectsValues;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.google.devtools.build.lib.skyframe;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.AspectValue;
import com.google.devtools.build.lib.packages.AspectDescriptor;
import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey;
import com.google.devtools.build.lib.skyframe.AspectKeyCreator.TopLevelAspectsKey;
Expand Down Expand Up @@ -68,10 +69,10 @@ public SkyValue compute(SkyKey skyKey, Environment env)
if (env.valuesMissing()) {
return null; // some aspects keys are not evaluated
}
ImmutableList.Builder<SkyValue> values =
ImmutableList.Builder<AspectValue> values =
ImmutableList.builderWithExpectedSize(aspectsKeys.size());
for (SkyKey aspectKey : aspectsKeys) {
SkyValue value = result.get(aspectKey);
AspectValue value = (AspectValue) result.get(aspectKey);
if (value == null) {
return null;
}
Expand Down

0 comments on commit bc75deb

Please sign in to comment.