From c51bcbd439414df9b2aae733eb01c62e2990b6f5 Mon Sep 17 00:00:00 2001 From: jhorvitz Date: Wed, 21 Apr 2021 07:05:45 -0700 Subject: [PATCH] Pass `ActionLookupData` to `TopDownActionCache`. PiperOrigin-RevId: 369647733 --- .../lib/skyframe/ActionExecutionFunction.java | 2 +- .../com/google/devtools/build/lib/skyframe/BUILD | 1 + .../build/lib/skyframe/TopDownActionCache.java | 10 ++++++++-- .../build/lib/skyframe/TopDownActionCacheTest.java | 14 +++++++------- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java index 9d31fd7f5d7a70..2b07945b3914e6 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java @@ -204,7 +204,7 @@ private SkyValue computeInternal(SkyKey skyKey, Environment env) if (sketch == null) { return null; } - ActionExecutionValue actionExecutionValue = topDownActionCache.get(sketch); + ActionExecutionValue actionExecutionValue = topDownActionCache.get(sketch, actionLookupData); if (actionExecutionValue != null) { return actionExecutionValue.transformForSharedAction(action.getOutputs()); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD index ca2c705c6c06f4..165cf989e68e34 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD @@ -2568,6 +2568,7 @@ java_library( srcs = ["TopDownActionCache.java"], deps = [ ":action_execution_value", + "//src/main/java/com/google/devtools/build/lib/actions:action_lookup_data", "//src/main/java/com/google/devtools/build/lib/actionsketch:action_sketch", "//third_party:jsr305", ], diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TopDownActionCache.java b/src/main/java/com/google/devtools/build/lib/skyframe/TopDownActionCache.java index a508e257b8804b..60fd2a7087e0ee 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TopDownActionCache.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TopDownActionCache.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; +import com.google.devtools.build.lib.actions.ActionLookupData; import com.google.devtools.build.lib.actionsketch.ActionSketch; import javax.annotation.Nullable; @@ -24,9 +25,14 @@ */ public interface TopDownActionCache { - /** Retrieves the cached value for the given action sketch, or null. */ + /** + * Retrieves the cached value for the given action sketch, or null. + * + *

The sketch alone is expected to suffice as the cache key, but the {@link ActionLookupData} + * is also provided for context. + */ @Nullable - ActionExecutionValue get(ActionSketch sketch); + ActionExecutionValue get(ActionSketch sketch, ActionLookupData action); /** Puts the sketch into the top-down cache. May complete asynchronously. */ void put(ActionSketch sketch, ActionExecutionValue value); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TopDownActionCacheTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TopDownActionCacheTest.java index d6301559820d3a..165bba09b544c4 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/TopDownActionCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/TopDownActionCacheTest.java @@ -19,6 +19,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.ActionKeyContext; +import com.google.devtools.build.lib.actions.ActionLookupData; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.util.TestAction; import com.google.devtools.build.lib.actionsketch.ActionSketch; @@ -34,7 +35,7 @@ /** Tests for top-down, transitive action caching. */ @RunWith(JUnit4.class) -public class TopDownActionCacheTest extends TimestampBuilderTestCase { +public final class TopDownActionCacheTest extends TimestampBuilderTestCase { @Override protected TopDownActionCache initTopDownActionCache() { @@ -177,7 +178,7 @@ private static class InMemoryTopDownActionCache implements TopDownActionCache { @Nullable @Override - public ActionExecutionValue get(ActionSketch sketch) { + public ActionExecutionValue get(ActionSketch sketch, ActionLookupData action) { return cache.getIfPresent(sketch); } @@ -187,11 +188,10 @@ public void put(ActionSketch sketch, ActionExecutionValue value) { } } - private static class MutableActionKeyAction extends TestAction { - + private static final class MutableActionKeyAction extends TestAction { private final ActionKeyButton button; - public MutableActionKeyAction( + MutableActionKeyAction( ActionKeyButton button, NestedSet inputs, ImmutableSet outputs) { super(button, inputs, outputs); this.button = button; @@ -207,10 +207,10 @@ protected void computeKey( } } - private static class ActionKeyButton extends Button { + private static final class ActionKeyButton extends Button { private final String key; - public ActionKeyButton(String key) { + ActionKeyButton(String key) { this.key = key; } }