Remove lookupSuper from AppInfo

Bug:147578480
Change-Id: Iced34eb0e2c7ff21a3416f9872e6a10cba581791
diff --git a/src/main/java/com/android/tools/r8/graph/AppInfo.java b/src/main/java/com/android/tools/r8/graph/AppInfo.java
index dcad411..7997cea 100644
--- a/src/main/java/com/android/tools/r8/graph/AppInfo.java
+++ b/src/main/java/com/android/tools/r8/graph/AppInfo.java
@@ -278,30 +278,6 @@
   }
 
   /**
-   * Lookup super method following the super chain from the holder of {@code method}.
-   *
-   * <p>This method will resolve the method on the holder of {@code method} and only return a
-   * non-null value if the result of resolution was an instance (i.e. non-static) method.
-   *
-   * @param method the method to lookup
-   * @param invocationContext the class the invoke is contained in, i.e., the holder of the caller.
-   * @return The actual target for {@code method} or {@code null} if none found.
-   */
-  @Deprecated // TODO(b/147578480): Remove
-  public DexEncodedMethod lookupSuperTarget(DexMethod method, DexType invocationContext) {
-    assert checkIfObsolete();
-    assert invocationContext.isClassType();
-    DexClass context = definitionFor(invocationContext);
-    return context == null ? null : lookupSuperTarget(method, context);
-  }
-
-  @Deprecated // TODO(b/147578480): Remove
-  public DexEncodedMethod lookupSuperTarget(DexMethod method, DexClass invocationContext) {
-    assert checkIfObsolete();
-    return resolveMethod(method.holder, method).lookupInvokeSuperTarget(invocationContext, this);
-  }
-
-  /**
    * Lookup direct method following the super chain from the holder of {@code method}.
    *
    * <p>This method will lookup private and constructor methods.
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java
index 1d9c597..584bfc4 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java
@@ -141,6 +141,7 @@
         DexEncodedMethod dexEncodedMethod =
             appView
                 .appInfo()
+                .withClassHierarchy()
                 .lookupSuperTarget(invoke.getInvokedMethod(), code.method.method.holder);
         // Final methods can be rewritten as a normal invoke.
         if (dexEncodedMethod != null && !dexEncodedMethod.isFinal()) {
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/InterfaceMethodRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/InterfaceMethodRewriter.java
index bcae8e7..ab215b6 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/InterfaceMethodRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/InterfaceMethodRewriter.java
@@ -280,6 +280,7 @@
               DexEncodedMethod dexEncodedMethod =
                   appView
                       .appInfo()
+                      .withClassHierarchy()
                       .lookupSuperTarget(invokeSuper.getInvokedMethod(), code.method.method.holder);
               if (dexEncodedMethod != null) {
                 DexClass dexClass = appView.definitionFor(dexEncodedMethod.method.holder);
diff --git a/src/main/java/com/android/tools/r8/shaking/VerticalClassMerger.java b/src/main/java/com/android/tools/r8/shaking/VerticalClassMerger.java
index ae8eb7e..69b77cd 100644
--- a/src/main/java/com/android/tools/r8/shaking/VerticalClassMerger.java
+++ b/src/main/java/com/android/tools/r8/shaking/VerticalClassMerger.java
@@ -864,15 +864,15 @@
 
     private static final String CONSTRUCTOR_NAME = "constructor";
 
-    private final DexClass source;
-    private final DexClass target;
+    private final DexProgramClass source;
+    private final DexProgramClass target;
     private final VerticalClassMergerGraphLense.Builder deferredRenamings =
         new VerticalClassMergerGraphLense.Builder(appView.dexItemFactory());
     private final List<SynthesizedBridgeCode> synthesizedBridges = new ArrayList<>();
 
     private boolean abortMerge = false;
 
-    private ClassMerger(DexClass source, DexClass target) {
+    private ClassMerger(DexProgramClass source, DexProgramClass target) {
       this.source = source;
       this.target = target;
     }
@@ -1122,7 +1122,7 @@
         // a superclass of B), which also needs to be rewritten to "invoke-direct C.m$B()".
         //
         // We handle this by adding a mapping for [target] and all of its supertypes.
-        DexClass holder = target;
+        DexProgramClass holder = target;
         while (holder != null && holder.isProgramClass()) {
           DexMethod signatureInHolder =
               application.dexItemFactory.createMethod(holder.type, oldTarget.proto, oldTarget.name);
@@ -1158,7 +1158,10 @@
               }
             }
           }
-          holder = holder.superType != null ? appInfo.definitionFor(holder.superType) : null;
+          holder =
+              holder.superType != null
+                  ? appInfo.definitionFor(holder.superType).asProgramClass()
+                  : null;
         }
       }
     }
diff --git a/src/test/java/com/android/tools/r8/TestBase.java b/src/test/java/com/android/tools/r8/TestBase.java
index 00d991a..203a07b 100644
--- a/src/test/java/com/android/tools/r8/TestBase.java
+++ b/src/test/java/com/android/tools/r8/TestBase.java
@@ -21,6 +21,7 @@
 import com.android.tools.r8.dex.ApplicationReader;
 import com.android.tools.r8.errors.Unreachable;
 import com.android.tools.r8.graph.AppInfo;
+import com.android.tools.r8.graph.AppInfoWithClassHierarchy;
 import com.android.tools.r8.graph.AppInfoWithSubtyping;
 import com.android.tools.r8.graph.AppServices;
 import com.android.tools.r8.graph.AppView;
@@ -555,11 +556,11 @@
     return newJar;
   }
 
-  protected AppInfo getAppInfo(AndroidApp application) {
+  protected static AppInfo computeAppInfo(AndroidApp application) {
     try {
       DexApplication dexApplication =
           new ApplicationReader(
-                  application, new InternalOptions(), new Timing("TestBase.getAppInfo"))
+                  application, new InternalOptions(), new Timing("TestBase.computeAppInfo"))
               .read();
       return new AppInfo(dexApplication);
     } catch (IOException | ExecutionException e) {
@@ -567,6 +568,17 @@
     }
   }
 
+  protected static AppInfoWithClassHierarchy computeAppInfoWithClassHierarchy(
+      AndroidApp application) {
+    try {
+      DexApplication dexApplication =
+          new ApplicationReader(application, new InternalOptions(), new Timing()).read();
+      return new AppInfoWithClassHierarchy(dexApplication);
+    } catch (IOException | ExecutionException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
   protected static AppView<AppInfoWithSubtyping> computeAppViewWithSubtyping(AndroidApp app)
       throws Exception {
     Timing timing = new Timing();
diff --git a/src/test/java/com/android/tools/r8/graph/TargetLookupTest.java b/src/test/java/com/android/tools/r8/graph/TargetLookupTest.java
index 289a0ba..e49d9a5 100644
--- a/src/test/java/com/android/tools/r8/graph/TargetLookupTest.java
+++ b/src/test/java/com/android/tools/r8/graph/TargetLookupTest.java
@@ -77,7 +77,7 @@
     );
 
     AndroidApp application = buildApplication(builder);
-    AppInfo appInfo = getAppInfo(application);
+    AppInfo appInfo = computeAppInfo(application);
     CodeInspector inspector = new CodeInspector(appInfo.app());
     DexEncodedMethod method = getMethod(inspector, DEFAULT_CLASS_NAME, "int", "x",
         ImmutableList.of());
@@ -147,7 +147,7 @@
     );
 
     AndroidApp application = buildApplication(builder);
-    AppInfo appInfo = getAppInfo(application);
+    AppInfo appInfo = computeAppInfo(application);
     CodeInspector inspector = new CodeInspector(appInfo.app());
 
     DexMethod methodXOnTestSuper =
@@ -197,7 +197,7 @@
     );
 
     AndroidApp application = buildApplication(builder);
-    AppInfo appInfo = getAppInfo(application);
+    AppInfo appInfo = computeAppInfo(application);
     DexItemFactory factory = appInfo.dexItemFactory();
 
     DexField aFieldOnSubClass = factory
@@ -229,7 +229,7 @@
       builder.addLibraryFiles(ToolHelper.getDefaultAndroidJar());
     }
     AndroidApp application = builder.build();
-    AppInfo appInfo = getAppInfo(application);
+    AppInfoWithClassHierarchy appInfo = computeAppInfoWithClassHierarchy(application);
     DexItemFactory factory = appInfo.dexItemFactory();
 
     DexType i0 = factory.createType("L" + pkg + "/I0;");