Re-use method to compute companion method
This replaces the revert of
Re-use ensure method to compute companion method
Bug: 191656218
Change-Id: I02a395e1d44ac2852c325a5ccae1a027590cd964
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/itf/EmulatedInterfaceProcessor.java b/src/main/java/com/android/tools/r8/ir/desugar/itf/EmulatedInterfaceProcessor.java
index 4ec0ef8..46bd871 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/itf/EmulatedInterfaceProcessor.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/itf/EmulatedInterfaceProcessor.java
@@ -177,22 +177,17 @@
for (int i = subInterfaces.size() - 1; i >= 0; i--) {
DexClass subInterfaceClass = appView.definitionFor(subInterfaces.get(i));
assert subInterfaceClass != null;
+ assert subInterfaceClass.isProgramClass();
// Else computation of subInterface would have failed.
// if the method is implemented, extra dispatch is required.
DexEncodedMethod result = subInterfaceClass.lookupVirtualMethod(method.getReference());
if (result != null && !result.isAbstract()) {
+ assert result.isDefaultMethod();
extraDispatchCases.add(
new Pair<>(
subInterfaceClass.type,
- appView
- .dexItemFactory()
- .createMethod(
- rewriter.getCompanionClassType(subInterfaceClass.type),
- appView
- .dexItemFactory()
- .protoWithDifferentFirstParameter(
- companionMethod.proto, subInterfaceClass.type),
- companionMethod.name)));
+ InterfaceMethodRewriter.defaultAsMethodOfCompanionClass(
+ result.getReference(), appView.dexItemFactory())));
}
}
} else {
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/itf/InterfaceMethodRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/itf/InterfaceMethodRewriter.java
index 0e46288..6ab6f1f 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/itf/InterfaceMethodRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/itf/InterfaceMethodRewriter.java
@@ -1168,10 +1168,6 @@
return factory.createSynthesizedType(ccTypeDescriptor);
}
- public DexType getCompanionClassType(DexType type) {
- return getCompanionClassType(type, factory);
- }
-
// Checks if `type` is a companion class.
public static boolean isCompanionClassType(DexType type) {
return type.descriptor.toString().endsWith(COMPANION_CLASS_NAME_SUFFIX + ";");