Add a predicate for alpha-renamed items and use it to "move" synthetics.

Bug: 171032440
Change-Id: If6b0e3296c6390c8c4babe106591af5919665d63
diff --git a/src/main/java/com/android/tools/r8/graph/GraphLens.java b/src/main/java/com/android/tools/r8/graph/GraphLens.java
index b3f5d14..ac9b854 100644
--- a/src/main/java/com/android/tools/r8/graph/GraphLens.java
+++ b/src/main/java/com/android/tools/r8/graph/GraphLens.java
@@ -321,6 +321,13 @@
     return newMethod.lookupOnProgramClass(holder);
   }
 
+  // Predicate indicating if a rewritten type is a simple renaming, meaning the move from type to
+  // rewritten is just a renaming of the type to another. In other words, the content of the
+  // definition, including the definition of all of its members is the same modulo the renaming.
+  public boolean isSimpleRenaming(DexType from, DexType to) {
+    return false;
+  }
+
   public abstract DexType lookupClassType(DexType type);
 
   public abstract DexType lookupType(DexType type);
diff --git a/src/main/java/com/android/tools/r8/relocator/RelocatorCommand.java b/src/main/java/com/android/tools/r8/relocator/RelocatorCommand.java
index 7da1116..aea3e82 100644
--- a/src/main/java/com/android/tools/r8/relocator/RelocatorCommand.java
+++ b/src/main/java/com/android/tools/r8/relocator/RelocatorCommand.java
@@ -149,7 +149,6 @@
                 .addAdaptResourceFilenames(ProguardPathList.builder().addFileName("**").build())
                 .build(),
             getReporter());
-    assert options.threadCount == ThreadUtils.NOT_SPECIFIED;
     options.relocatorCompilation = true;
     options.threadCount = getThreadCount();
     options.programConsumer = consumer;
diff --git a/src/main/java/com/android/tools/r8/repackaging/RepackagingLens.java b/src/main/java/com/android/tools/r8/repackaging/RepackagingLens.java
index a0f6645..d3ceea5 100644
--- a/src/main/java/com/android/tools/r8/repackaging/RepackagingLens.java
+++ b/src/main/java/com/android/tools/r8/repackaging/RepackagingLens.java
@@ -39,6 +39,11 @@
     return getPrevious().getOriginalType(previous);
   }
 
+  @Override
+  public boolean isSimpleRenaming(DexType from, DexType to) {
+    return originalTypes.get(to) == from || super.isSimpleRenaming(from, to);
+  }
+
   public static class Builder {
 
     protected final BiMap<DexType, DexType> originalTypes = HashBiMap.create();
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
index 1ffd59f..2872d1c 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
@@ -252,6 +252,7 @@
 
     for (DexProgramClass clazz : appView.appInfo().classes()) {
       if (!isSyntheticType.test(clazz.type)) {
+        assert SyntheticItems.verifyNotInternalSynthetic(clazz.type);
         normalClasses.add(clazz);
       }
     }
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
index b200c0a..c6726e1 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
@@ -308,14 +308,8 @@
     ImmutableMap.Builder<DexType, SyntheticReference> rewrittenItems = ImmutableMap.builder();
     for (SyntheticReference reference : nonLecacySyntheticItems.values()) {
       SyntheticReference rewritten = reference.rewrite(lens);
-      // If the reference has been rewritten the compiler has changed it and we drop it from the
-      // set of synthetics. The context may or may not have changed.
-      if (reference.getReference() == rewritten.getReference()) {
+      if (rewritten != null) {
         rewrittenItems.put(rewritten.getHolder(), rewritten);
-      } else {
-        // If the referenced item is rewritten, it should be moved to another holder as the
-        // synthetic holder is no longer part of the synthetic collection.
-        assert reference.getHolder() != rewritten.getHolder();
       }
     }
     // No pending item should need rewriting.
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticMethodReference.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticMethodReference.java
index 5470d53..28913d0 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticMethodReference.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticMethodReference.java
@@ -47,8 +47,17 @@
 
   @Override
   SyntheticReference rewrite(NonIdentityGraphLens lens) {
-    SynthesizingContext context = getContext().rewrite(lens);
     DexMethod rewritten = lens.lookupMethod(method);
+    // If the reference has been non-trivially rewritten the compiler has changed it and it can no
+    // longer be considered a synthetic. The context may or may not have changed.
+    if (method != rewritten && !lens.isSimpleRenaming(method.holder, rewritten.holder)) {
+      // If the referenced item is rewritten, it should be moved to another holder as the
+      // synthetic holder is no longer part of the synthetic collection.
+      assert method.holder != rewritten.holder;
+      assert SyntheticItems.verifyNotInternalSynthetic(rewritten.holder);
+      return null;
+    }
+    SynthesizingContext context = getContext().rewrite(lens);
     return context == getContext() && rewritten == method
         ? this
         : new SyntheticMethodReference(context, rewritten);