Change `getValuesOrThrow` method to `getValuesAndExceptions` in Aspect-related files.
Instead of a `Map`, use `SkyframeLookupResult` for lookups. This custom class creates less garbage.
PiperOrigin-RevId: 430979101
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
index 1bb4214..4cc39af 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
@@ -87,8 +87,7 @@
import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
-import com.google.devtools.build.skyframe.ValueOrException2;
-import com.google.devtools.build.skyframe.ValueOrUntypedException;
+import com.google.devtools.build.skyframe.SkyframeLookupResult;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -434,12 +433,7 @@
if (bzlLoadKey != null) {
initialKeys.add(bzlLoadKey);
}
- Map<SkyKey, ValueOrException2<BzlLoadFailedException, ConfiguredValueCreationException>>
- initialValues =
- env.getValuesOrThrow(
- initialKeys.build(),
- BzlLoadFailedException.class,
- ConfiguredValueCreationException.class);
+ SkyframeLookupResult initialValues = env.getValuesAndExceptions(initialKeys.build());
if (env.valuesMissing()) {
return null;
}
@@ -447,9 +441,21 @@
if (starlarkAspectClass != null) {
StarlarkDefinedAspect starlarkAspect;
try {
- starlarkAspect =
- Preconditions.checkNotNull(
- loadStarlarkAspect(starlarkAspectClass, initialValues.get(bzlLoadKey)));
+ BzlLoadValue bzlLoadvalue;
+ try {
+ bzlLoadvalue =
+ (BzlLoadValue) initialValues.getOrThrow(bzlLoadKey, BzlLoadFailedException.class);
+ if (bzlLoadvalue == null) {
+ BugReport.sendBugReport(
+ new IllegalStateException(
+ "bzlLoadValue " + bzlLoadKey + " was missing, this should never happen"));
+ return null;
+ }
+ } catch (BzlLoadFailedException e) {
+ throw new AspectCreationException(
+ e.getMessage(), starlarkAspectClass.getExtensionLabel(), e.getDetailedExitCode());
+ }
+ starlarkAspect = loadAspectFromBzl(starlarkAspectClass, bzlLoadvalue);
} catch (AspectCreationException e) {
env.getListener().handle(Event.error(e.getMessage()));
throw new AspectFunctionException(e);
@@ -463,7 +469,7 @@
}
// Keep this in sync with the same code in ConfiguredTargetFunction.
- PackageValue aspectPackage = (PackageValue) initialValues.get(aspectPackageKey).getUnchecked();
+ PackageValue aspectPackage = (PackageValue) initialValues.get(aspectPackageKey);
if (aspectPackage.getPackage().containsErrors()) {
throw new AspectFunctionException(
new BuildFileContainsErrorsException(key.getLabel().getPackageIdentifier()));
@@ -472,23 +478,21 @@
ConfiguredTargetValue baseConfiguredTargetValue;
try {
baseConfiguredTargetValue =
- (ConfiguredTargetValue) initialValues.get(baseConfiguredTargetKey).get();
+ (ConfiguredTargetValue)
+ initialValues.getOrThrow(
+ baseConfiguredTargetKey, ConfiguredValueCreationException.class);
+ if (baseConfiguredTargetValue == null) {
+ BugReport.sendBugReport(
+ new IllegalStateException(
+ "BzlLoadFailedException should have been processed by ConfiguredTargetFunction for "
+ + baseConfiguredTargetKey
+ + " and "
+ + key));
+ return null;
+ }
} catch (ConfiguredValueCreationException e) {
throw new AspectFunctionException(
new AspectCreationException(e.getMessage(), e.getRootCauses(), e.getDetailedExitCode()));
- } catch (BzlLoadFailedException e) {
- BugReport.sendBugReport(
- new IllegalStateException(
- "BzlLoadFailedException should have been processed by ConfiguredTargetFunction for "
- + baseConfiguredTargetKey
- + " and "
- + key,
- e));
- throw new AspectFunctionException(
- new AspectCreationException(
- e.getMessage(),
- NestedSetBuilder.emptySet(Order.STABLE_ORDER),
- e.getDetailedExitCode()));
}
ConfiguredTarget associatedTarget = baseConfiguredTargetValue.getConfiguredTarget();
@@ -501,9 +505,9 @@
BuildConfigurationValue configuration =
configurationKey == null
? null
- : (BuildConfigurationValue) initialValues.get(configurationKey).getUnchecked();
+ : (BuildConfigurationValue) initialValues.get(configurationKey);
- PackageValue basePackage = (PackageValue) initialValues.get(basePackageKey).getUnchecked();
+ PackageValue basePackage = (PackageValue) initialValues.get(basePackageKey);
Target target;
try {
target = basePackage.getPackage().getTarget(associatedTarget.getOriginalLabel().getName());
@@ -537,24 +541,6 @@
}
@Nullable
- private static StarlarkDefinedAspect loadStarlarkAspect(
- StarlarkAspectClass starlarkAspectClass, ValueOrUntypedException bzlLoadValueOrException)
- throws AspectCreationException {
- BzlLoadValue bzlLoadValue;
- try {
- bzlLoadValue =
- (BzlLoadValue) bzlLoadValueOrException.getOrThrow(BzlLoadFailedException.class);
- } catch (BzlLoadFailedException e) {
- throw new AspectCreationException(
- e.getMessage(), starlarkAspectClass.getExtensionLabel(), e.getDetailedExitCode());
- }
- if (bzlLoadValue == null) {
- return null;
- }
- return loadAspectFromBzl(starlarkAspectClass, bzlLoadValue);
- }
-
- @Nullable
private static UnloadedToolchainContext getUnloadedToolchainContext(
Environment env,
AspectKey key,