diff options
author | Googler <noreply@google.com> | 2018-01-18 09:15:44 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-18 09:17:46 -0800 |
commit | ab0cdd55fc73b40f1c7462a2b95cc1ce7f930043 (patch) | |
tree | ccde4debb869a8180c1f8532d6a08023e0217e69 /src/main/java/com/google/devtools | |
parent | ee692d5fe03117fb3995c63ccb6b515adf375c88 (diff) |
Re-add WalkableGraph#isUpToDate and BuildDriver#alreadyEvaluated
RELNOTES: None
PiperOrigin-RevId: 182389876
Diffstat (limited to 'src/main/java/com/google/devtools')
5 files changed, 35 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java index 883047e1a6..03341de629 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java @@ -249,20 +249,26 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target> throws QueryException, InterruptedException { Set<SkyKey> roots = getGraphRootsFromExpression(expr); - EvaluationResult<SkyValue> result; - try (AutoProfiler p = AutoProfiler.logged("evaluation and walkable graph", logger)) { - result = graphFactory.prepareAndGet(roots, loadingPhaseThreads, universeEvalEventHandler); - } + if (graph == null || !graphFactory.isUpToDate(roots)) { + // If this environment is uninitialized or the graph factory needs to evaluate, do so. We + // assume here that this environment cannot be initialized-but-stale if the factory is up + // to date. + EvaluationResult<SkyValue> result; + try (AutoProfiler p = AutoProfiler.logged("evaluation and walkable graph", logger)) { + result = graphFactory.prepareAndGet(roots, loadingPhaseThreads, universeEvalEventHandler); + } - if (graph == null || graph != result.getWalkableGraph()) { checkEvaluationResult(roots, result); + packageSemaphore = makeFreshPackageMultisetSemaphore(); graph = result.getWalkableGraph(); blacklistPatternsSupplier = InterruptibleSupplier.Memoize.of(new BlacklistSupplier(graph)); + graphBackedRecursivePackageProvider = new GraphBackedRecursivePackageProvider(graph, universeTargetPatternKeys, pkgPath); } + if (executor == null) { executor = MoreExecutors.listeningDecorator( new ThreadPoolExecutor( diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java index 52687e2c43..58f557c96f 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java @@ -1762,6 +1762,11 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { return evaluationResult; } + @Override + public boolean isUpToDate(Set<SkyKey> roots) { + return buildDriver.alreadyEvaluated(roots); + } + /** * Get metadata related to the prepareAndGet() lookup. Resulting data is specific to the * underlying evaluation implementation. diff --git a/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java b/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java index d1f942e0c7..78c24793c6 100644 --- a/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java +++ b/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java @@ -37,6 +37,13 @@ public interface BuildDriver { String meta(Iterable<SkyKey> roots, OptionsClassProvider options) throws AbruptExitException, InterruptedException; + /** + * Returns true if this {@link BuildDriver} instance has already been used to {@link #evaluate} + * the given {@code roots} at the Version that would be passed along to the next call to {@link + * MemoizingEvaluator#evaluate} in {@link #evaluate}. + */ + boolean alreadyEvaluated(Iterable<SkyKey> roots); + MemoizingEvaluator getGraphForTesting(); @Nullable diff --git a/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java b/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java index 51724cdc05..8a42189407 100644 --- a/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java +++ b/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java @@ -48,6 +48,11 @@ public class SequentialBuildDriver implements BuildDriver { } @Override + public boolean alreadyEvaluated(Iterable<SkyKey> roots) { + return false; + } + + @Override public MemoizingEvaluator getGraphForTesting() { return memoizingEvaluator; } diff --git a/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java b/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java index a55bbc5415..b5b744f6af 100644 --- a/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java +++ b/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java @@ -103,6 +103,13 @@ public interface WalkableGraph { Set<SkyKey> roots, int numThreads, ExtendedEventHandler eventHandler) throws InterruptedException; + /** + * Returns true if this instance has already been used to {@link #prepareAndGet} {@code roots}. + * If so, cached results from {@link #prepareAndGet} can be re-used safely, potentially saving + * some processing time. + */ + boolean isUpToDate(Set<SkyKey> roots); + /** Returns the {@link SkyKey} that defines this universe. */ SkyKey getUniverseKey(Collection<String> roots, String offset); } |