Attempt to synthesize companion class only when needed
Bug: 183998768
Change-Id: I5006b96e4aacd6cc3b10a74b7f92fd5365ba8764
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 e8f4756..9efdc49 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
@@ -23,6 +23,7 @@
import com.android.tools.r8.utils.Pair;
import com.android.tools.r8.utils.StringDiagnostic;
import com.android.tools.r8.utils.collections.ProgramMethodSet;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Arrays;
@@ -138,9 +139,8 @@
assert rewriter.isEmulatedInterface(emulatedInterface.type);
DexProgramClass theProgramInterface = emulatedInterface.asProgramClass();
DexProgramClass synthesizedClass = synthesizeEmulateInterfaceLibraryClass(theProgramInterface);
- if (synthesizedClass != null) {
- syntheticClasses.put(emulatedInterface, synthesizedClass);
- }
+ assert synthesizedClass != null;
+ syntheticClasses.put(emulatedInterface, synthesizedClass);
}
private DexProgramClass synthesizeEmulateInterfaceLibraryClass(DexProgramClass theInterface) {
@@ -220,9 +220,7 @@
extraDispatchCases,
appView));
});
- if (emulationMethods.isEmpty()) {
- return null;
- }
+ assert !emulationMethods.isEmpty();
DexType emulateLibraryClassType =
InterfaceMethodRewriter.getEmulateLibraryInterfaceClassType(
theInterface.type, appView.dexItemFactory());
@@ -280,7 +278,13 @@
|| appView.isAlreadyLibraryDesugared(emulatedInterface)) {
return;
}
- generateEmulateInterfaceLibrary(emulatedInterface);
+ if (needsEmulateInterfaceLibrary(emulatedInterface)) {
+ generateEmulateInterfaceLibrary(emulatedInterface);
+ }
+ }
+
+ private boolean needsEmulateInterfaceLibrary(DexProgramClass emulatedInterface) {
+ return Iterables.any(emulatedInterface.methods(), DexEncodedMethod::isDefaultMethod);
}
@Override