Make is-method-merged a computed property

Change-Id: I897f1b2413c25e4a20f7bc005b397769d3b1e2f8
diff --git a/src/main/java/com/android/tools/r8/verticalclassmerging/ClassMerger.java b/src/main/java/com/android/tools/r8/verticalclassmerging/ClassMerger.java
index 2fdda52..f4e1b95 100644
--- a/src/main/java/com/android/tools/r8/verticalclassmerging/ClassMerger.java
+++ b/src/main/java/com/android/tools/r8/verticalclassmerging/ClassMerger.java
@@ -185,7 +185,6 @@
           DexEncodedMethod movedMethod = moveDirectMethod(method, availableMethodSignatures);
           directMethods.put(movedMethod, movedMethod);
           lensBuilder.recordMove(method, movedMethod);
-          blockRedirectionOfSuperCalls(movedMethod);
         });
 
     for (DexEncodedMethod abstractMethod : source.virtualMethods(DexEncodedMethod::isAbstract)) {
@@ -512,26 +511,6 @@
         type -> true);
   }
 
-  private void blockRedirectionOfSuperCalls(DexEncodedMethod method) {
-    // We are merging a class B into C. The methods from B are being moved into C, and then we
-    // subsequently rewrite the invoke-super instructions in C that hit a method in B, such that
-    // they use an invoke-direct instruction instead. In this process, we need to avoid rewriting
-    // the invoke-super instructions that originally was in the superclass B.
-    //
-    // Example:
-    //   class A {
-    //     public void m() {}
-    //   }
-    //   class B extends A {
-    //     public void m() { super.m(); } <- invoke must not be rewritten to invoke-direct
-    //                                       (this would lead to an infinite loop)
-    //   }
-    //   class C extends B {
-    //     public void m() { super.m(); } <- invoke needs to be rewritten to invoke-direct
-    //   }
-    lensBuilder.markMethodAsMerged(method);
-  }
-
   private DexEncodedMethod buildBridgeMethod(
       DexEncodedMethod method, DexEncodedMethod invocationTarget) {
     DexMethod newMethod = method.getReference().withHolder(target, dexItemFactory);
diff --git a/src/main/java/com/android/tools/r8/verticalclassmerging/VerticalClassMergerGraphLens.java b/src/main/java/com/android/tools/r8/verticalclassmerging/VerticalClassMergerGraphLens.java
index fcbf5eb..ead346d 100644
--- a/src/main/java/com/android/tools/r8/verticalclassmerging/VerticalClassMergerGraphLens.java
+++ b/src/main/java/com/android/tools/r8/verticalclassmerging/VerticalClassMergerGraphLens.java
@@ -75,7 +75,6 @@
   private final Map<DexType, Map<DexMethod, DexMethod>> contextualSuperToImplementationInContexts;
   private final BidirectionalOneToOneMap<DexMethod, DexMethod> extraNewMethodSignatures;
 
-  private final Set<DexMethod> mergedMethods;
   private final Set<DexMethod> staticizedMethods;
 
   private VerticalClassMergerGraphLens(
@@ -85,7 +84,6 @@
       Map<DexType, Map<DexMethod, DexMethod>> contextualSuperToImplementationInContexts,
       BidirectionalManyToOneRepresentativeMap<DexMethod, DexMethod> newMethodSignatures,
       BidirectionalOneToOneMap<DexMethod, DexMethod> extraNewMethodSignatures,
-      Set<DexMethod> mergedMethods,
       Set<DexMethod> staticizedMethods) {
     super(
         appView,
@@ -96,7 +94,6 @@
     this.mergedClasses = mergedClasses;
     this.contextualSuperToImplementationInContexts = contextualSuperToImplementationInContexts;
     this.extraNewMethodSignatures = extraNewMethodSignatures;
-    this.mergedMethods = mergedMethods;
     this.staticizedMethods = staticizedMethods;
   }
 
@@ -105,7 +102,8 @@
   }
 
   private boolean isMerged(DexMethod method) {
-    return mergedMethods.contains(method);
+    DexMethod previousMethod = getPreviousMethodSignature(method);
+    return mergedClasses.hasBeenMergedIntoSubtype(previousMethod.getHolderType());
   }
 
   private boolean isStaticized(DexMethod method) {
@@ -365,9 +363,6 @@
     private final Map<DexMethod, DexMethod> pendingExtraNewMethodSignatureUpdates =
         new IdentityHashMap<>();
 
-    private final Set<DexMethod> mergedMethods = Sets.newIdentityHashSet();
-    private final Map<DexMethod, DexMethod> pendingMergedMethodUpdates = new IdentityHashMap<>();
-
     private final Set<DexMethod> staticizedMethods = Sets.newIdentityHashSet();
     private final Map<DexMethod, DexMethod> pendingStaticizedMethodUpdates =
         new IdentityHashMap<>();
@@ -422,11 +417,6 @@
       extraNewMethodSignatures.putAll(pendingExtraNewMethodSignatureUpdates);
       pendingExtraNewMethodSignatureUpdates.clear();
 
-      // Commit merged methods.
-      mergedMethods.removeAll(pendingMergedMethodUpdates.keySet());
-      mergedMethods.addAll(pendingMergedMethodUpdates.values());
-      pendingMergedMethodUpdates.clear();
-
       // Commit staticized methods.
       staticizedMethods.removeAll(pendingStaticizedMethodUpdates.keySet());
       staticizedMethods.addAll(pendingStaticizedMethodUpdates.values());
@@ -449,10 +439,6 @@
         pendingNewMethodSignatureUpdates.put(oldMethodSignature, newMethodSignature);
       }
 
-      if (mergedMethods.contains(oldMethodSignature)) {
-        pendingMergedMethodUpdates.put(oldMethodSignature, newMethodSignature);
-      }
-
       if (staticizedMethods.contains(oldMethodSignature)) {
         pendingStaticizedMethodUpdates.put(oldMethodSignature, newMethodSignature);
       }
@@ -500,14 +486,9 @@
           contextualSuperToImplementationInContexts,
           newMethodSignatures,
           extraNewMethodSignatures,
-          mergedMethods,
           staticizedMethods);
     }
 
-    public void markMethodAsMerged(DexEncodedMethod method) {
-      mergedMethods.add(method.getReference());
-    }
-
     public void recordMove(DexEncodedField from, DexEncodedField to) {
       newFieldSignatures.put(from.getReference(), to.getReference());
     }
@@ -537,7 +518,6 @@
       }
 
       extraNewMethodSignatures.put(from.getReference(), implementation.getReference());
-      mergedMethods.add(implementation.getReference());
 
       if (implementation.isStatic()) {
         staticizedMethods.add(implementation.getReference());
@@ -553,7 +533,6 @@
 
     public void merge(VerticalClassMergerGraphLens.Builder builder) {
       newFieldSignatures.putAll(builder.newFieldSignatures);
-      mergedMethods.addAll(builder.mergedMethods);
       builder.newMethodSignatures.forEachManyToOneMapping(
           (keys, value, representative) -> {
             boolean isRemapping =