Add experimental flag, that partially disables loading phase (pattern evaluation, test_suite expansion and configuration creation is still there). Also remove some unused code.

--
MOS_MIGRATED_REVID=103177839
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index bf94236..65c4a05 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -154,25 +154,25 @@
             abbrev = 'k',
             defaultValue = "false",
             category = "strategy",
-            help = "Continue as much as possible after an error.  While the "
-            + "target that failed, and those that depend on it, cannot be "
-            + "analyzed (or built), the other prerequisites of these "
-            + "targets can be analyzed (or built) all the same.")
+            help = "Continue as much as possible after an error.  While the"
+                + " target that failed, and those that depend on it, cannot be"
+                + " analyzed (or built), the other prerequisites of these"
+                + " targets can be analyzed (or built) all the same.")
     public boolean keepGoing;
 
     @Option(name = "analysis_warnings_as_errors",
             deprecationWarning = "analysis_warnings_as_errors is now a no-op and will be removed in"
-                + " an upcoming Blaze release",
+                              + " an upcoming Blaze release",
             defaultValue = "false",
             category = "strategy",
             help = "Treat visible analysis warnings as errors.")
     public boolean analysisWarningsAsErrors;
 
     @Option(name = "discard_analysis_cache",
-        defaultValue = "false",
-        category = "strategy",
-        help = "Discard the analysis cache immediately after the analysis phase completes. "
-        + "Reduces memory usage by ~10%, but makes further incremental builds slower.")
+            defaultValue = "false",
+            category = "strategy",
+            help = "Discard the analysis cache immediately after the analysis phase completes."
+                + " Reduces memory usage by ~10%, but makes further incremental builds slower.")
     public boolean discardAnalysisCache;
 
     @Option(name = "experimental_extra_action_filter",
@@ -188,6 +188,13 @@
             help = "Only schedules extra_actions for top level targets.")
     public boolean extraActionTopLevelOnly;
 
+    @Option(name = "experimental_interleave_loading_and_analysis",
+            defaultValue = "false",
+            category = "experimental",
+            help = "Interleave loading and analysis phases, so that one target may be analyzed at"
+                + " the same time as an unrelated target is loaded.")
+    public boolean interleaveLoadingAndAnalysis;
+
     @Option(name = "version_window_for_dirty_node_gc",
             defaultValue = "0",
             category = "undocumented",
@@ -455,7 +462,8 @@
             ImmutableList.<Artifact>of(),
             ImmutableList.<ConfiguredTarget>of(),
             ImmutableList.<ConfiguredTarget>of(),
-            null);
+            null,
+            ImmutableMap.<PackageIdentifier, Path>of());
 
     private final ImmutableList<ConfiguredTarget> targetsToBuild;
     @Nullable private final ImmutableList<ConfiguredTarget> targetsToTest;
@@ -466,6 +474,7 @@
     private final ImmutableSet<ConfiguredTarget> exclusiveTests;
     @Nullable private final TopLevelArtifactContext topLevelContext;
     private final ImmutableList<AspectValue> aspects;
+    private final ImmutableMap<PackageIdentifier, Path> packageRoots;
 
     private AnalysisResult(
         Collection<ConfiguredTarget> targetsToBuild,
@@ -476,7 +485,8 @@
         Collection<Artifact> artifactsToBuild,
         Collection<ConfiguredTarget> parallelTests,
         Collection<ConfiguredTarget> exclusiveTests,
-        TopLevelArtifactContext topLevelContext) {
+        TopLevelArtifactContext topLevelContext,
+        ImmutableMap<PackageIdentifier, Path> packageRoots) {
       this.targetsToBuild = ImmutableList.copyOf(targetsToBuild);
       this.aspects = ImmutableList.copyOf(aspects);
       this.targetsToTest = targetsToTest == null ? null : ImmutableList.copyOf(targetsToTest);
@@ -486,6 +496,7 @@
       this.parallelTests = ImmutableSet.copyOf(parallelTests);
       this.exclusiveTests = ImmutableSet.copyOf(exclusiveTests);
       this.topLevelContext = topLevelContext;
+      this.packageRoots = packageRoots;
     }
 
     /**
@@ -496,6 +507,14 @@
     }
 
     /**
+     * The map from package names to the package root where each package was found; this is used to
+     * set up the symlink tree.
+     */
+    public ImmutableMap<PackageIdentifier, Path> getPackageRoots() {
+      return packageRoots;
+    }
+
+    /**
      * Returns aspects of configured targets to build.
      *
      * <p>If this list is empty, build the targets returned by {@code getTargetsToBuild()}.
@@ -581,7 +600,8 @@
       Options viewOptions,
       TopLevelArtifactContext topLevelOptions,
       EventHandler eventHandler,
-      EventBus eventBus)
+      EventBus eventBus,
+      boolean loadingEnabled)
       throws ViewCreationFailedException, InterruptedException {
     LOG.info("Starting analysis");
     pollInterruptedStatus();
@@ -609,10 +629,9 @@
       clear();
     }
     skyframeAnalysisWasDiscarded = false;
-    ImmutableMap<PackageIdentifier, Path> packageRoots = loadingResult.getPackageRoots();
     this.configurations = configurations;
     skyframeBuildView.setTopLevelHostConfiguration(this.configurations.getHostConfiguration());
-    setArtifactRoots(packageRoots);
+
     // Determine the configurations.
     List<TargetAndConfiguration> nodes = nodesForTargets(targets);
 
@@ -641,6 +660,12 @@
       }
     }
 
+    // Configuration of some BuildConfiguration.Fragments may require information about
+    // artifactRoots, so we need to set them before calling prepareToBuild. In that case loading
+    // phase has to be enabled.
+    if (loadingEnabled) {
+      setArtifactRoots(loadingResult.getPackageRoots());
+    }
     prepareToBuild(new SkyframePackageRootResolver(skyframeExecutor));
     skyframeExecutor.injectWorkspaceStatusData();
     SkyframeAnalysisResult skyframeAnalysisResult;
@@ -648,6 +673,7 @@
       skyframeAnalysisResult =
           skyframeBuildView.configureTargets(
               targetSpecs, aspectKeys, eventBus, viewOptions.keepGoing);
+      setArtifactRoots(skyframeAnalysisResult.getPackageRoots());
     } finally {
       skyframeBuildView.clearInvalidatedConfiguredTargets();
     }
@@ -670,6 +696,7 @@
             skyframeAnalysisResult.getConfiguredTargets(),
             skyframeAnalysisResult.getAspects(),
             skyframeAnalysisResult.getWalkableGraph(),
+            skyframeAnalysisResult.getPackageRoots(),
             analysisSuccessful);
     LOG.info("Finished analysis");
     return result;
@@ -682,6 +709,7 @@
       Collection<ConfiguredTarget> configuredTargets,
       Collection<AspectValue> aspects,
       final WalkableGraph graph,
+      ImmutableMap<PackageIdentifier, Path> packageRoots,
       boolean analysisSuccessful)
       throws InterruptedException {
     Collection<Target> testsToRun = loadingResult.getTestsToRun();
@@ -752,7 +780,8 @@
         artifactsToBuild,
         parallelTests,
         exclusiveTests,
-        topLevelOptions);
+        topLevelOptions,
+        packageRoots);
   }
 
   private static NestedSet<Artifact> getBaselineCoverageArtifacts(