Add residual signature to disassemble output

Bug: b/221855899
Change-Id: I05b5a5d5500cd71508cf146240c672c85c311cb8
diff --git a/src/main/java/com/android/tools/r8/graph/AssemblyWriter.java b/src/main/java/com/android/tools/r8/graph/AssemblyWriter.java
index b117cce..43ee151 100644
--- a/src/main/java/com/android/tools/r8/graph/AssemblyWriter.java
+++ b/src/main/java/com/android/tools/r8/graph/AssemblyWriter.java
@@ -152,6 +152,9 @@
     ps.println("# Method: '" + retracer.toSourceString(definition.getReference()) + "':");
     writeAnnotations(null, definition.annotations(), ps);
     ps.println("# " + definition.accessFlags);
+    if (!retracer.isEmpty()) {
+      ps.println("# Residual: '" + definition.getReference().toSourceString());
+    }
     ps.println("#");
     ps.println();
     if (!writeCode) {
diff --git a/src/main/java/com/android/tools/r8/graph/DexCode.java b/src/main/java/com/android/tools/r8/graph/DexCode.java
index 3d7892f..7e55f8e 100644
--- a/src/main/java/com/android/tools/r8/graph/DexCode.java
+++ b/src/main/java/com/android/tools/r8/graph/DexCode.java
@@ -456,7 +456,7 @@
   public String toString(DexEncodedMethod method, RetracerForCodePrinting retracer) {
     StringBuilder builder = new StringBuilder();
     if (method != null) {
-      builder.append(method.toSourceString()).append("\n");
+      builder.append(retracer.toSourceString(method.getReference())).append("\n");
     }
     builder.append("registers: ").append(registerSize);
     builder.append(", inputs: ").append(incomingRegisterSize);
diff --git a/src/main/java/com/android/tools/r8/utils/RetracerForCodePrinting.java b/src/main/java/com/android/tools/r8/utils/RetracerForCodePrinting.java
index 821be94..1c5f9b3 100644
--- a/src/main/java/com/android/tools/r8/utils/RetracerForCodePrinting.java
+++ b/src/main/java/com/android/tools/r8/utils/RetracerForCodePrinting.java
@@ -15,9 +15,8 @@
 import com.android.tools.r8.references.MethodReference;
 import com.android.tools.r8.retrace.RetraceClassElement;
 import com.android.tools.r8.retrace.RetraceElement;
-import com.android.tools.r8.retrace.RetraceFrameResult;
+import com.android.tools.r8.retrace.RetraceMethodResult;
 import com.android.tools.r8.retrace.RetraceResult;
-import com.android.tools.r8.retrace.RetraceStackTraceContext;
 import com.android.tools.r8.retrace.RetracedFieldReference;
 import com.android.tools.r8.retrace.RetracedFieldReference.KnownRetracedFieldReference;
 import com.android.tools.r8.retrace.RetracedMethodReference;
@@ -25,7 +24,6 @@
 import com.android.tools.r8.retrace.Retracer;
 import com.android.tools.r8.retrace.internal.MappingSupplierInternalImpl;
 import com.android.tools.r8.retrace.internal.RetracerImpl;
-import java.util.OptionalInt;
 import java.util.function.Function;
 
 public class RetracerForCodePrinting {
@@ -85,18 +83,17 @@
     }
     // TODO(b/169953605): Use retracer.retraceMethod() when we have enough information.
     MethodReference methodReference = method.asMethodReference();
-    RetraceFrameResult retraceFrameResult =
+    RetraceMethodResult retraceMethodResult =
         retracer
             .retraceClass(methodReference.getHolderClass())
-            .lookupMethod(methodReference.getMethodName())
-            .narrowByPosition(RetraceStackTraceContext.empty(), OptionalInt.of(1));
+            .lookupMethod(methodReference.getMethodName());
     return joinAmbiguousResults(
-        retraceFrameResult,
+        retraceMethodResult,
         element -> {
           if (element.isUnknown()) {
-            return unknownToString.apply(element.getTopFrame());
+            return unknownToString.apply(element.getRetracedMethod());
           } else {
-            return knownToString.apply(element.getTopFrame().asKnown());
+            return knownToString.apply(element.getRetracedMethod().asKnown());
           }
         });
   }
@@ -107,7 +104,7 @@
         DexMethod::toSourceString,
         knownRetracedMethodReference ->
             knownRetracedMethodReference.getMethodReference().toSourceString(),
-        unknown -> unknown.getHolderClass().getDescriptor() + " " + unknown.getMethodName());
+        unknown -> unknown.getHolderClass().getTypeName() + " " + unknown.getMethodName());
   }
 
   public String toDescriptor(DexMethod method) {
@@ -172,4 +169,8 @@
     return ((DexReference) item)
         .apply(this::toSourceString, this::toSourceString, this::toSourceString);
   }
+
+  public boolean isEmpty() {
+    return this == EMPTY;
+  }
 }