Remove dead code for legacy dispatch classes.
Bug: 158159959
Change-Id: I06febfaceba15213a6ebeac7d89ecb2f3b096cb0
diff --git a/src/main/java/com/android/tools/r8/graph/DexType.java b/src/main/java/com/android/tools/r8/graph/DexType.java
index fa4b01d..fe1ba9a 100644
--- a/src/main/java/com/android/tools/r8/graph/DexType.java
+++ b/src/main/java/com/android/tools/r8/graph/DexType.java
@@ -7,7 +7,6 @@
import static com.android.tools.r8.ir.desugar.DesugaredLibraryWrapperSynthesizer.TYPE_WRAPPER_SUFFIX;
import static com.android.tools.r8.ir.desugar.DesugaredLibraryWrapperSynthesizer.VIVIFIED_TYPE_WRAPPER_SUFFIX;
import static com.android.tools.r8.ir.desugar.InterfaceMethodRewriter.COMPANION_CLASS_NAME_SUFFIX;
-import static com.android.tools.r8.ir.desugar.InterfaceMethodRewriter.DISPATCH_CLASS_NAME_SUFFIX;
import static com.android.tools.r8.ir.desugar.InterfaceMethodRewriter.EMULATE_LIBRARY_CLASS_NAME_SUFFIX;
import static com.android.tools.r8.ir.desugar.LambdaRewriter.LAMBDA_GROUP_CLASS_NAME_PREFIX;
import static com.android.tools.r8.ir.optimize.enums.UnboxedEnumMemberRelocator.ENUM_UNBOXING_UTILITY_CLASS_SUFFIX;
@@ -44,6 +43,7 @@
"$r8$backportedMethods$utility",
"$r8$java8methods$utility",
"$r8$twr$utility",
+ "$-DC",
"-$$Lambda$");
public final DexString descriptor;
@@ -334,7 +334,6 @@
// Any entry that is removed from here must be added to OLD_SYNTHESIZED_NAMES to ensure that
// newer releases can be used to merge previous builds.
return name.contains(LAMBDA_GROUP_CLASS_NAME_PREFIX) // Could collide.
- || name.contains(DISPATCH_CLASS_NAME_SUFFIX) // Shared on reference.
|| name.contains(OutlineOptions.CLASS_NAME) // Global singleton.
|| name.contains(NestBasedAccessDesugaring.NEST_CONSTRUCTOR_NAME) // Global singleton.
|| name.contains(ServiceLoaderRewriter.SERVICE_LOADER_CLASS_NAME); // Global singleton.
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/InterfaceMethodRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/InterfaceMethodRewriter.java
index 5a00a4b..083e26e 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/InterfaceMethodRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/InterfaceMethodRewriter.java
@@ -112,7 +112,6 @@
// Public for testing.
public static final String EMULATE_LIBRARY_CLASS_NAME_SUFFIX = "$-EL";
- public static final String DISPATCH_CLASS_NAME_SUFFIX = "$-DC";
public static final String COMPANION_CLASS_NAME_SUFFIX = "$-CC";
public static final String DEFAULT_METHOD_PREFIX = "$default$";
public static final String PRIVATE_METHOD_PREFIX = "$private$";
@@ -861,15 +860,6 @@
return getCompanionClassType(type, factory);
}
- // Gets the forwarding class for the interface `type`.
- final DexType getDispatchClassType(DexType type) {
- assert type.isClassType();
- String descriptor = type.descriptor.toString();
- String dcTypeDescriptor = descriptor.substring(0, descriptor.length() - 1)
- + DISPATCH_CLASS_NAME_SUFFIX + ";";
- return factory.createType(dcTypeDescriptor);
- }
-
// Checks if `type` is a companion class.
public static boolean isCompanionClassType(DexType type) {
return type.descriptor.toString().endsWith(COMPANION_CLASS_NAME_SUFFIX + ";");
@@ -903,16 +893,6 @@
return factory.createMethod(getCompanionClassType(method.holder), method.proto, method.name);
}
- // Represent a static interface method as a method of dispatch class.
- final DexMethod staticAsMethodOfDispatchClass(DexMethod method) {
- return factory.createMethod(getDispatchClassType(method.holder), method.proto, method.name);
- }
-
- // Checks if the type ends with dispatch class suffix.
- public static boolean hasDispatchClassSuffix(DexType clazz) {
- return clazz.getName().endsWith(DISPATCH_CLASS_NAME_SUFFIX);
- }
-
private static DexMethod instanceAsMethodOfCompanionClass(
DexMethod method, String prefix, DexItemFactory factory) {
// Add an implicit argument to represent the receiver.
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/InterfaceProcessor.java b/src/main/java/com/android/tools/r8/ir/desugar/InterfaceProcessor.java
index 42787b7..c2db31a 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/InterfaceProcessor.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/InterfaceProcessor.java
@@ -14,7 +14,6 @@
import com.android.tools.r8.cf.code.CfStackInstruction.Opcode;
import com.android.tools.r8.code.Instruction;
import com.android.tools.r8.code.InvokeSuper;
-import com.android.tools.r8.dex.Constants;
import com.android.tools.r8.errors.CompilationError;
import com.android.tools.r8.errors.Unimplemented;
import com.android.tools.r8.graph.AppView;
@@ -27,7 +26,6 @@
import com.android.tools.r8.graph.DexEncodedMethod;
import com.android.tools.r8.graph.DexField;
import com.android.tools.r8.graph.DexItemFactory;
-import com.android.tools.r8.graph.DexLibraryClass;
import com.android.tools.r8.graph.DexMethod;
import com.android.tools.r8.graph.DexProgramClass;
import com.android.tools.r8.graph.DexProgramClass.ChecksumSupplier;
@@ -45,7 +43,6 @@
import com.android.tools.r8.graph.ParameterAnnotationsList;
import com.android.tools.r8.graph.ProgramMethod;
import com.android.tools.r8.ir.code.Invoke.Type;
-import com.android.tools.r8.ir.synthetic.ForwardMethodBuilder;
import com.android.tools.r8.origin.SynthesizedOrigin;
import com.android.tools.r8.utils.Pair;
import com.android.tools.r8.utils.collections.BidirectionalManyToManyRepresentativeMap;
@@ -362,85 +359,6 @@
return c -> 7 * checksum;
}
- DexProgramClass process(DexLibraryClass iface, Set<DexProgramClass> callers) {
- assert iface.isInterface();
-
- // The list of methods to be created in dispatch class.
- // NOTE: we do NOT check static methods being actually called on the interface against
- // static methods actually existing in that interface. It is essential for supporting
- // D8 desugaring when each class may be dexed separately since it allows us to assume
- // that all synthesized dispatch classes have the same set of methods so we don't
- // need to merge them.
- List<DexEncodedMethod> dispatchMethods = new ArrayList<>();
-
- // Process public static methods, for each of them create a method dispatching the call to it.
- for (DexEncodedMethod direct : iface.directMethods()) {
- MethodAccessFlags originalAccessFlags = direct.accessFlags;
- if (!originalAccessFlags.isStatic() || !originalAccessFlags.isPublic()) {
- // We assume only public static methods of library interfaces can be called
- // from program classes, since there should not be protected or package private
- // static methods on interfaces.
- assert !originalAccessFlags.isStatic() || originalAccessFlags.isPrivate();
- continue;
- }
-
- assert !rewriter.factory.isClassConstructor(direct.method);
-
- DexMethod origMethod = direct.method;
- DexMethod newMethod = rewriter.staticAsMethodOfDispatchClass(origMethod);
- // Create a forwarding method to the library static interface method. The method is added
- // to the dispatch class, however, the targeted method is still on the interface, so the
- // interface bit should be set to true.
- ForwardMethodBuilder forwardMethodBuilder =
- ForwardMethodBuilder.builder(appView.dexItemFactory())
- .setStaticSource(newMethod)
- .setStaticTarget(origMethod, true);
- DexEncodedMethod newEncodedMethod =
- new DexEncodedMethod(
- newMethod,
- MethodAccessFlags.fromSharedAccessFlags(
- Constants.ACC_PUBLIC | Constants.ACC_STATIC | Constants.ACC_SYNTHETIC, false),
- MethodTypeSignature.noSignature(),
- DexAnnotationSet.empty(),
- ParameterAnnotationsList.empty(),
- forwardMethodBuilder.build(),
- true);
- newEncodedMethod.getMutableOptimizationInfo().markNeverInline();
- dispatchMethods.add(newEncodedMethod);
- }
-
- ClassAccessFlags dispatchClassFlags =
- ClassAccessFlags.fromSharedAccessFlags(
- Constants.ACC_PUBLIC | Constants.ACC_FINAL | Constants.ACC_SYNTHETIC);
-
- // Create dispatch class.
- DexType dispatchClassType = rewriter.getDispatchClassType(iface.type);
- DexProgramClass dispatchClass =
- new DexProgramClass(
- dispatchClassType,
- null,
- new SynthesizedOrigin("interface dispatch", getClass()),
- dispatchClassFlags,
- rewriter.factory.objectType,
- DexTypeList.empty(),
- iface.sourceFile,
- null,
- Collections.emptyList(),
- null,
- Collections.emptyList(),
- ClassSignature.noSignature(),
- DexAnnotationSet.empty(),
- DexEncodedField.EMPTY_ARRAY,
- DexEncodedField.EMPTY_ARRAY,
- dispatchMethods.toArray(DexEncodedMethod.EMPTY_ARRAY),
- DexEncodedMethod.EMPTY_ARRAY,
- rewriter.factory.getSkipNameValidationForTesting(),
- DexProgramClass::checksumFromType,
- callers);
- syntheticClasses.put(iface, dispatchClass);
- return dispatchClass;
- }
-
private boolean canMoveToCompanionClass(DexEncodedMethod method) {
Code code = method.getCode();
assert code != null;
diff --git a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
index f1c5405..97b2504 100644
--- a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
+++ b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
@@ -469,7 +469,6 @@
|| getMissingClasses().contains(type)
// TODO(b/150693139): Remove these exceptions once fixed.
|| InterfaceMethodRewriter.isCompanionClassType(type)
- || InterfaceMethodRewriter.hasDispatchClassSuffix(type)
|| InterfaceMethodRewriter.isEmulatedLibraryClassType(type)
|| type.toDescriptorString().startsWith("Lj$/$r8$retargetLibraryMember$")
// TODO(b/150736225): Not sure how to remove these.
diff --git a/src/test/java/com/android/tools/r8/D8IncrementalRunExamplesAndroidOTest.java b/src/test/java/com/android/tools/r8/D8IncrementalRunExamplesAndroidOTest.java
index 845a5c5..82cfebf 100644
--- a/src/test/java/com/android/tools/r8/D8IncrementalRunExamplesAndroidOTest.java
+++ b/src/test/java/com/android/tools/r8/D8IncrementalRunExamplesAndroidOTest.java
@@ -96,7 +96,6 @@
ClassReference reference = Reference.classFromDescriptor(descriptor);
Assert.assertTrue(
descriptor.endsWith(InterfaceMethodRewriter.COMPANION_CLASS_NAME_SUFFIX + ";")
- || descriptor.endsWith(InterfaceMethodRewriter.DISPATCH_CLASS_NAME_SUFFIX + ";")
|| SyntheticItemsTestUtils.isExternalTwrCloseMethod(reference)
|| SyntheticItemsTestUtils.isExternalLambda(reference)
|| SyntheticItemsTestUtils.isExternalStaticInterfaceCall(reference)