Add assertion message for diagnosing b/278524993

Bug: b/278524993
Change-Id: I5927041869031f9d07c5f92093440992f47600f2
diff --git a/src/main/java/com/android/tools/r8/profile/rewriting/ProfileAdditions.java b/src/main/java/com/android/tools/r8/profile/rewriting/ProfileAdditions.java
index 1005bcd..bf4b3eb 100644
--- a/src/main/java/com/android/tools/r8/profile/rewriting/ProfileAdditions.java
+++ b/src/main/java/com/android/tools/r8/profile/rewriting/ProfileAdditions.java
@@ -17,6 +17,7 @@
 import com.android.tools.r8.profile.AbstractProfileClassRule;
 import com.android.tools.r8.profile.AbstractProfileMethodRule;
 import com.android.tools.r8.profile.AbstractProfileRule;
+import com.android.tools.r8.utils.SetUtils;
 import com.android.tools.r8.utils.WorkList;
 import com.google.common.collect.Sets;
 import java.util.ArrayList;
@@ -316,7 +317,8 @@
           // If this assertion fails, that means we have synthetics with multiple
           // synthesizing contexts, which are not guaranteed to be processed before the
           // synthetic itself. In that case this assertion should simply be removed.
-          assert successorMethodRuleBuilder.isGreaterThanOrEqualTo(methodRuleBuilder);
+          assert successorMethodRuleBuilder.isGreaterThanOrEqualTo(methodRuleBuilder)
+              : getGraphString(methodRuleAdditions, method, successor);
           successorMethodRuleBuilder.join(methodRuleBuilder);
           // Note: no need to addIgnoringSeenSet() since the graph will not have cycles. Indeed, it
           // should never be the case that a method m2(), which is synthesized from method context
@@ -325,5 +327,35 @@
         }
       }
     }
+
+    // Return a string representation of the graph for diagnosing b/278524993.
+    private String getGraphString(
+        Map<DexMethod, MethodRuleBuilder> methodRuleAdditions,
+        DexMethod context,
+        DexMethod method) {
+      StringBuilder builder =
+          new StringBuilder("Error at edge: ")
+              .append(context.toSourceString())
+              .append(" -> ")
+              .append(method.toSourceString());
+      Set<DexMethod> nodes =
+          SetUtils.unionIdentityHashSet(predecessors.keySet(), successors.keySet());
+      for (DexMethod node : nodes) {
+        builder
+            .append(System.lineSeparator())
+            .append(System.lineSeparator())
+            .append(node.toSourceString());
+        for (DexMethod predecessor : predecessors.getOrDefault(node, Collections.emptySet())) {
+          builder
+              .append(System.lineSeparator())
+              .append("  <- ")
+              .append(predecessor.toSourceString());
+        }
+        for (DexMethod successor : successors.getOrDefault(node, Collections.emptySet())) {
+          builder.append(System.lineSeparator()).append("  -> ").append(successor.toSourceString());
+        }
+      }
+      return builder.toString();
+    }
   }
 }