Refactor WalkableGraph and BuildDriver interfaces

Remove WalkableGraph#isUpToDate and BuildDriver#alreadyEvaluated and delegate the
work to implementation.

RELNOTES: None
PiperOrigin-RevId: 185562370
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 0485f9d..e7ce0a3 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,26 +249,20 @@
       throws QueryException, InterruptedException {
     Set<SkyKey> roots = getGraphRootsFromExpression(expr);
 
-    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);
-      }
+    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 5677caa..a0245b7 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
@@ -1788,11 +1788,6 @@
     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 78c2479..d1f942e 100644
--- a/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java
+++ b/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java
@@ -37,13 +37,6 @@
   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 8a42189..51724cd 100644
--- a/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java
+++ b/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java
@@ -48,11 +48,6 @@
   }
 
   @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 b5b744f..a55bbc5 100644
--- a/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java
+++ b/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java
@@ -103,13 +103,6 @@
         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);
   }