No callback on emulated interfaces
Change-Id: I083b2c74a27ee1224ed0dd5f4364c44555f3e73c
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryAPIConverter.java b/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryAPIConverter.java
index f0eda16..708cabb8 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryAPIConverter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryAPIConverter.java
@@ -139,6 +139,7 @@
// We look up everywhere to see if there is a supertype/interface implementing the method...
LinkedList<DexType> workList = new LinkedList<>();
Collections.addAll(workList, theClass.interfaces.values);
+ boolean foundOverrideToRewrite = false;
// There is no methods with desugared types on Object.
if (theClass.superType != factory.objectType) {
workList.add(theClass.superType);
@@ -158,10 +159,14 @@
}
DexEncodedMethod dexEncodedMethod = dexClass.lookupVirtualMethod(method);
if (dexEncodedMethod != null) {
- return true;
+ if (appView.options().desugaredLibraryConfiguration.getEmulateLibraryInterface()
+ .containsKey(dexClass.type)) {
+ return false;
+ }
+ foundOverrideToRewrite = true;
}
}
- return false;
+ return foundOverrideToRewrite;
}
private synchronized void generateCallBack(DexClass dexClass, DexEncodedMethod originalMethod) {
@@ -169,7 +174,7 @@
methodWithVivifiedTypeInSignature(originalMethod.method, dexClass.type, appView);
CfCode cfCode =
new APIConverterWrapperCfCodeProvider(
- appView, originalMethod.method, null, this, dexClass.isInterface())
+ appView, originalMethod.method, null, this, dexClass.isInterface())
.generateCfCode();
DexEncodedMethod newDexEncodedMethod =
wrapperSynthesizor.newSynthesizedMethod(methodToInstall, originalMethod, cfCode);
@@ -256,7 +261,7 @@
// Return conversion added only if return value is used.
if (invokeMethod.outValue() != null
&& invokeMethod.outValue().numberOfUsers() + invokeMethod.outValue().numberOfPhiUsers()
- > 0) {
+ > 0) {
returnConversion =
createReturnConversionAndReplaceUses(code, invokeMethod, returnType, newReturnType);
}
diff --git a/src/test/java/com/android/tools/r8/desugar/corelib/CustomCollectionTest.java b/src/test/java/com/android/tools/r8/desugar/corelib/CustomCollectionTest.java
index 9a8bb6b..71cbfcd 100644
--- a/src/test/java/com/android/tools/r8/desugar/corelib/CustomCollectionTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/corelib/CustomCollectionTest.java
@@ -11,8 +11,10 @@
import com.android.tools.r8.R8TestRunResult;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.ToolHelper.DexVm;
+import com.android.tools.r8.ir.desugar.DesugaredLibraryWrapperSynthesizer;
import com.android.tools.r8.utils.BooleanUtils;
import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import com.android.tools.r8.utils.codeinspector.FoundClassSubject;
import com.android.tools.r8.utils.codeinspector.InstructionSubject;
import com.android.tools.r8.utils.codeinspector.InstructionSubject.JumboStringMode;
import com.android.tools.r8.utils.codeinspector.MethodSubject;
@@ -57,8 +59,6 @@
public void testCustomCollectionD8() throws Exception {
// TODO(b/142377475).
Assume.assumeTrue(!shrinkDesugaredLibrary);
- // TODO(b/142377161).
- Assume.assumeTrue(parameters.getRuntime().asDex().getVm().isNewerThan(DexVm.ART_4_4_4_HOST));
KeepRuleConsumer keepRuleConsumer = createKeepRuleConsumer(parameters);
D8TestRunResult d8TestRunResult =
testForD8()
@@ -66,7 +66,9 @@
.setMinApi(parameters.getApiLevel())
.enableCoreLibraryDesugaring(parameters.getApiLevel(), keepRuleConsumer)
.compile()
- .inspect(inspector -> this.assertCustomCollectionCallsCorrect(inspector, false))
+ .inspect(inspector -> {
+ this.assertNoWrappers(inspector);
+ this.assertCustomCollectionCallsCorrect(inspector, false);})
.addDesugaredCoreLibraryRunClassPath(
this::buildDesugaredLibrary,
parameters.getApiLevel(),
@@ -89,8 +91,6 @@
@Test
public void testCustomCollectionR8() throws Exception {
- // TODO(b/142377161).
- Assume.assumeTrue(parameters.getRuntime().asDex().getVm().isNewerThan(DexVm.ART_4_4_4_HOST));
KeepRuleConsumer keepRuleConsumer = createKeepRuleConsumer(parameters);
R8TestRunResult r8TestRunResult =
testForR8(Backend.DEX)
@@ -104,7 +104,9 @@
})
.enableCoreLibraryDesugaring(parameters.getApiLevel(), keepRuleConsumer)
.compile()
- .inspect(inspector -> this.assertCustomCollectionCallsCorrect(inspector, true))
+ .inspect(inspector -> {
+ this.assertNoWrappers(inspector);
+ this.assertCustomCollectionCallsCorrect(inspector, true);})
.addDesugaredCoreLibraryRunClassPath(
this::buildDesugaredLibrary,
parameters.getApiLevel(),
@@ -125,6 +127,11 @@
}
}
+ private void assertNoWrappers(CodeInspector inspector) {
+ assertTrue(inspector.allClasses().stream().noneMatch(cl -> cl.getOriginalName().startsWith(
+ DesugaredLibraryWrapperSynthesizer.WRAPPER_PREFIX)));
+ }
+
private void assertCustomCollectionCallsCorrect(CodeInspector inspector, boolean r8) {
MethodSubject direct = inspector.clazz(EXECUTOR).uniqueMethodWithName("directTypes");
// TODO(b/134732760): Due to memberRebinding, R8 is not as precise as D8 regarding