Always take AppView/Info when computing subtype info.

Bug: 149167169
Change-Id: I34b0134b220bae2d2681a181819693891b397f32
diff --git a/src/main/java/com/android/tools/r8/GenerateMainDexList.java b/src/main/java/com/android/tools/r8/GenerateMainDexList.java
index fcda77d..4b32cd3 100644
--- a/src/main/java/com/android/tools/r8/GenerateMainDexList.java
+++ b/src/main/java/com/android/tools/r8/GenerateMainDexList.java
@@ -54,7 +54,7 @@
 
       MainDexListBuilder.checkForAssumedLibraryTypes(appView.appInfo());
 
-      SubtypingInfo subtypingInfo = new SubtypingInfo(application.allClasses(), application);
+      SubtypingInfo subtypingInfo = new SubtypingInfo(appView);
 
       RootSet mainDexRootSet =
           new RootSetBuilder(appView, subtypingInfo, options.mainDexKeepRules).run(executor);
diff --git a/src/main/java/com/android/tools/r8/PrintSeeds.java b/src/main/java/com/android/tools/r8/PrintSeeds.java
index a948df7..b8a426c 100644
--- a/src/main/java/com/android/tools/r8/PrintSeeds.java
+++ b/src/main/java/com/android/tools/r8/PrintSeeds.java
@@ -89,7 +89,7 @@
           new ApplicationReader(command.getInputApp(), options, timing).read(executor).toDirect();
       AppView<AppInfoWithClassHierarchy> appView = AppView.createForR8(application);
       appView.setAppServices(AppServices.builder(appView).build());
-      SubtypingInfo subtypingInfo = new SubtypingInfo(application.allClasses(), application);
+      SubtypingInfo subtypingInfo = new SubtypingInfo(appView);
       RootSet rootSet =
           new RootSetBuilder(appView, subtypingInfo, options.getProguardConfiguration().getRules())
               .run(executor);
diff --git a/src/main/java/com/android/tools/r8/R8.java b/src/main/java/com/android/tools/r8/R8.java
index 0a033a3..d04ad46 100644
--- a/src/main/java/com/android/tools/r8/R8.java
+++ b/src/main/java/com/android/tools/r8/R8.java
@@ -325,8 +325,7 @@
       Set<DexType> missingClasses = null;
       try {
         // TODO(b/154849103): Find a better way to determine missing classes.
-        missingClasses =
-            new SubtypingInfo(getDirectApp(appView).allClasses(), appView).getMissingClasses();
+        missingClasses = new SubtypingInfo(appView).getMissingClasses();
         missingClasses = filterMissingClasses(
             missingClasses, options.getProguardConfiguration().getDontWarnPatterns());
         if (!missingClasses.isEmpty()) {
@@ -359,8 +358,7 @@
                     options.itemFactory, AndroidApiLevel.getAndroidApiLevel(options.minApiLevel)));
           }
         }
-        SubtypingInfo subtypingInfo =
-            new SubtypingInfo(getDirectApp(appView).allClasses(), appView);
+        SubtypingInfo subtypingInfo = new SubtypingInfo(appView);
         appView.setRootSet(
             new RootSetBuilder(
                     appView,
@@ -445,8 +443,7 @@
       if (!options.mainDexKeepRules.isEmpty()) {
         assert appView.graphLens().isIdentityLens();
         // Find classes which may have code executed before secondary dex files installation.
-        SubtypingInfo subtypingInfo =
-            new SubtypingInfo(getDirectApp(appView).allClasses(), appView);
+        SubtypingInfo subtypingInfo = new SubtypingInfo(appView);
         mainDexRootSet =
             new RootSetBuilder(appView, subtypingInfo, options.mainDexKeepRules)
                 .run(executorService);
@@ -624,7 +621,7 @@
       // graph lens entirely, though, since it is needed for mapping all field and method signatures
       // back to the original program.
       timing.begin("AppliedGraphLens construction");
-      appView.setGraphLens(new AppliedGraphLens(appView, appView.appInfo().app().classes()));
+      appView.setGraphLens(new AppliedGraphLens(appView));
       timing.end();
 
       if (options.printCfg) {
@@ -651,9 +648,7 @@
 
         Enqueuer enqueuer =
             EnqueuerFactory.createForMainDexTracing(
-                appView,
-                new SubtypingInfo(getDirectApp(appView).allClasses(), appView),
-                mainDexKeptGraphConsumer);
+                appView, new SubtypingInfo(appView), mainDexKeptGraphConsumer);
         // Find classes which may have code executed before secondary dex files installation.
         // Live types is the tracing result.
         Set<DexProgramClass> mainDexBaseClasses =
@@ -702,7 +697,7 @@
           Enqueuer enqueuer =
               EnqueuerFactory.createForFinalTreeShaking(
                   appView,
-                  new SubtypingInfo(getDirectApp(appView).allClasses(), appView),
+                  new SubtypingInfo(appView),
                   keptGraphConsumer,
                   missingClasses,
                   prunedTypes);
@@ -1051,8 +1046,7 @@
     // If there is no kept-graph info, re-run the enqueueing to compute it.
     if (whyAreYouKeepingConsumer == null) {
       whyAreYouKeepingConsumer = new WhyAreYouKeepingConsumer(null);
-      SubtypingInfo subtypingInfo =
-          new SubtypingInfo(appView.appInfo().app().asDirect().allClasses(), appView);
+      SubtypingInfo subtypingInfo = new SubtypingInfo(appView);
       if (forMainDex) {
         enqueuer =
             EnqueuerFactory.createForMainDexTracing(
diff --git a/src/main/java/com/android/tools/r8/graph/AppliedGraphLens.java b/src/main/java/com/android/tools/r8/graph/AppliedGraphLens.java
index b602135..90b940a 100644
--- a/src/main/java/com/android/tools/r8/graph/AppliedGraphLens.java
+++ b/src/main/java/com/android/tools/r8/graph/AppliedGraphLens.java
@@ -27,11 +27,10 @@
   private final Map<DexMethod, DexMethod> originalMethodSignaturesForBridges =
       new IdentityHashMap<>();
 
-  public AppliedGraphLens(
-      AppView<? extends AppInfoWithClassHierarchy> appView, Iterable<DexProgramClass> classes) {
+  public AppliedGraphLens(AppView<? extends AppInfoWithClassHierarchy> appView) {
     this.appView = appView;
 
-    for (DexProgramClass clazz : classes) {
+    for (DexProgramClass clazz : appView.appInfo().classes()) {
       // Record original type names.
       {
         DexType type = clazz.type;
diff --git a/src/main/java/com/android/tools/r8/graph/SubtypingInfo.java b/src/main/java/com/android/tools/r8/graph/SubtypingInfo.java
index 662ccb0..b73d2bc 100644
--- a/src/main/java/com/android/tools/r8/graph/SubtypingInfo.java
+++ b/src/main/java/com/android/tools/r8/graph/SubtypingInfo.java
@@ -41,7 +41,15 @@
   // Set of missing classes, discovered during subtypeMap computation.
   private final Set<DexType> missingClasses = Sets.newIdentityHashSet();
 
-  public SubtypingInfo(Collection<DexClass> classes, DexDefinitionSupplier definitions) {
+  public SubtypingInfo(AppView<? extends AppInfoWithClassHierarchy> appView) {
+    this(appView.appInfo());
+  }
+
+  public SubtypingInfo(AppInfoWithClassHierarchy appInfo) {
+    this(appInfo.app().asDirect().allClasses(), appInfo);
+  }
+
+  private SubtypingInfo(Collection<DexClass> classes, DexDefinitionSupplier definitions) {
     factory = definitions.dexItemFactory();
     // Recompute subtype map if we have modified the graph.
     populateSubtypeMap(classes, definitions::definitionFor, factory);
diff --git a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
index e9d4c27..3197121 100644
--- a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
+++ b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
@@ -1363,7 +1363,7 @@
   }
 
   public SubtypingInfo computeSubtypingInfo() {
-    return new SubtypingInfo(app().asDirect().allClasses(), this);
+    return new SubtypingInfo(this);
   }
 
   public boolean mayHaveFinalizeMethodDirectlyOrIndirectly(ClassTypeElement type) {
diff --git a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
index 449be4a..0c2b74b 100644
--- a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
+++ b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
@@ -2907,8 +2907,7 @@
               return appBuilder.build();
             });
     appView.setAppInfo(appInfo);
-    subtypingInfo =
-        new SubtypingInfo(appInfo.app().asDirect().allClasses(), appInfo.app().asDirect());
+    subtypingInfo = new SubtypingInfo(appView);
 
     // Finally once all synthesized items "exist" it is now safe to continue tracing. The new work
     // items are enqueued and the fixed point will continue once this subroutine returns.
diff --git a/src/test/java/com/android/tools/r8/TestBase.java b/src/test/java/com/android/tools/r8/TestBase.java
index 3b2d394..545ab13 100644
--- a/src/test/java/com/android/tools/r8/TestBase.java
+++ b/src/test/java/com/android/tools/r8/TestBase.java
@@ -32,7 +32,6 @@
 import com.android.tools.r8.graph.DexMethod;
 import com.android.tools.r8.graph.DexProto;
 import com.android.tools.r8.graph.DexType;
-import com.android.tools.r8.graph.DirectMappedDexApplication;
 import com.android.tools.r8.graph.ProgramMethod;
 import com.android.tools.r8.graph.SmaliWriter;
 import com.android.tools.r8.graph.SubtypingInfo;
@@ -640,16 +639,15 @@
     AppView<AppInfoWithClassHierarchy> appView = computeAppViewWithSubtyping(app, keepConfig);
     // Run the tree shaker to compute an instance of AppInfoWithLiveness.
     ExecutorService executor = Executors.newSingleThreadExecutor();
-    DirectMappedDexApplication application = appView.appInfo().app().asDirect();
-    SubtypingInfo subtypingInfo = new SubtypingInfo(application.allClasses(), application);
+    SubtypingInfo subtypingInfo = new SubtypingInfo(appView);
     RootSet rootSet =
         new RootSetBuilder(
-                appView, subtypingInfo, application.options.getProguardConfiguration().getRules())
+                appView, subtypingInfo, appView.options().getProguardConfiguration().getRules())
             .run(executor);
     appView.setRootSet(rootSet);
     AppInfoWithLiveness appInfoWithLiveness =
         EnqueuerFactory.createForInitialTreeShaking(appView, subtypingInfo)
-            .traceApplication(rootSet, ProguardClassFilter.empty(), executor, application.timing);
+            .traceApplication(rootSet, ProguardClassFilter.empty(), executor, Timing.empty());
     // We do not run the tree pruner to ensure that the hierarchy is as designed and not modified
     // due to liveness.
     return appView.setAppInfo(appInfoWithLiveness);
diff --git a/src/test/java/com/android/tools/r8/internal/R8GMSCoreLookupTest.java b/src/test/java/com/android/tools/r8/internal/R8GMSCoreLookupTest.java
index d1bc124..82f21d4 100644
--- a/src/test/java/com/android/tools/r8/internal/R8GMSCoreLookupTest.java
+++ b/src/test/java/com/android/tools/r8/internal/R8GMSCoreLookupTest.java
@@ -61,7 +61,7 @@
             .toDirect();
     appView = AppView.createForR8(program);
     appView.setAppServices(AppServices.builder(appView).build());
-    subtypingInfo = new SubtypingInfo(program.allClasses(), program);
+    subtypingInfo = new SubtypingInfo(appView);
   }
 
   private AppInfoWithClassHierarchy appInfo() {
diff --git a/src/test/java/com/android/tools/r8/ir/InlineTest.java b/src/test/java/com/android/tools/r8/ir/InlineTest.java
index 1ca31a9..cb48232 100644
--- a/src/test/java/com/android/tools/r8/ir/InlineTest.java
+++ b/src/test/java/com/android/tools/r8/ir/InlineTest.java
@@ -14,7 +14,6 @@
 import com.android.tools.r8.graph.AppView;
 import com.android.tools.r8.graph.DexApplication;
 import com.android.tools.r8.graph.DexItemFactory;
-import com.android.tools.r8.graph.DirectMappedDexApplication;
 import com.android.tools.r8.graph.SubtypingInfo;
 import com.android.tools.r8.ir.code.BasicBlock;
 import com.android.tools.r8.ir.code.IRCode;
@@ -65,11 +64,10 @@
       MethodSubject method,
       List<IRCode> additionalCode)
       throws ExecutionException {
-    DirectMappedDexApplication directApp = application.asDirect();
-    AppView<AppInfoWithClassHierarchy> appView = AppView.createForR8(directApp);
+    AppView<AppInfoWithClassHierarchy> appView = AppView.createForR8(application.asDirect());
     appView.setAppServices(AppServices.builder(appView).build());
     ExecutorService executorService = ThreadUtils.getExecutorService(options);
-    SubtypingInfo subtypingInfo = new SubtypingInfo(directApp.allClasses(), directApp);
+    SubtypingInfo subtypingInfo = new SubtypingInfo(appView);
     appView.setRootSet(
         new RootSetBuilder(
                 appView,
diff --git a/src/test/java/com/android/tools/r8/shaking/R8Shaking2LookupTest.java b/src/test/java/com/android/tools/r8/shaking/R8Shaking2LookupTest.java
index 038ceb2..0040143 100644
--- a/src/test/java/com/android/tools/r8/shaking/R8Shaking2LookupTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/R8Shaking2LookupTest.java
@@ -32,8 +32,9 @@
   public void readApp() throws IOException, ExecutionException {
     program = ToolHelper.buildApplication(ImmutableList.of(APP_FILE_NAME));
     dexItemFactory = program.dexItemFactory;
-    appInfo = AppView.createForR8(program).appInfo();
-    subtypingInfo = new SubtypingInfo(program.allClasses(), program);
+    AppView<AppInfoWithClassHierarchy> appView = AppView.createForR8(program);
+    appInfo = appView.appInfo();
+    subtypingInfo = new SubtypingInfo(appView);
   }
 
   private void validateSubtype(DexType super_type, DexType sub_type) {