Make forwarding methods synthetic when desugaring

When desugaring a default method of an interface, we create a
forwarding method in every "implementation" class. This forwarding
method then calls into the companion class that contains the code of
the default method.

If a debugger is attached to a program that has been desugared and
steps into the call to the default method, it will actually suspend
in the forwarding method. Thus it requires an extra single step to
reach the code of the default method (in the companion class).

By making the forward method synthetic, we allow debuggers (like
IntelliJ) to automatically skip such method during single step.
Therefore we better match the behavior when running the same program
without desugaring by reaching the code of the default method in only
one step.

Bug: 77634519
Change-Id: I1b9879509bd21e461ac249ec11638920fce4f26a
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/ClassProcessor.java b/src/main/java/com/android/tools/r8/ir/desugar/ClassProcessor.java
index 2152364..7befc69 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/ClassProcessor.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/ClassProcessor.java
@@ -108,6 +108,8 @@
     // default method, including bridge flag.
     DexMethod newMethod = rewriter.factory.createMethod(clazz.type, method.proto, method.name);
     MethodAccessFlags newFlags = defaultMethod.accessFlags.copy();
+    // Some debuggers (like IntelliJ) automatically skip synthetic methods on single step.
+    newFlags.setSynthetic();
     return new DexEncodedMethod(newMethod, newFlags,
         defaultMethod.annotations, defaultMethod.parameterAnnotations,
         new SynthesizedCode(new ForwardMethodSourceCode(
diff --git a/src/test/java/com/android/tools/r8/debug/InterfaceMethodTest.java b/src/test/java/com/android/tools/r8/debug/InterfaceMethodTest.java
index 26d3d5c..6ecdca7 100644
--- a/src/test/java/com/android/tools/r8/debug/InterfaceMethodTest.java
+++ b/src/test/java/com/android/tools/r8/debug/InterfaceMethodTest.java
@@ -48,14 +48,8 @@
     commands.add(run());
     commands.add(checkMethod(debuggeeClass, "testDefaultMethod"));
     commands.add(checkLine(SOURCE_FILE, 31));
-    if (!supportsDefaultMethod(config)) {
-      // We desugared default method. This means we're going to step through an extra (forward)
-      // method first.
-      commands.add(stepInto(INTELLIJ_FILTER));
-    }
     commands.add(stepInto(INTELLIJ_FILTER));
     commands.add(checkLine(SOURCE_FILE, 9));
-    // TODO(shertz) we should see the local variable this even when desugaring.
     if (supportsDefaultMethod(config)) {
       commands.add(checkLocal("this"));
     } else {