Turn off uninstantiated type optimization for interfaces
Bug: 146957343
Bug: 147153808
Change-Id: I4b4423ee74e806361153644ff27b78dac9e51a8e
diff --git a/src/main/java/com/android/tools/r8/utils/InternalOptions.java b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
index 1425bc0..f973d47 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -242,7 +242,8 @@
// TODO(b/125282093): Enable member value propagation for instance fields.
public boolean enableValuePropagationForInstanceFields = false;
public boolean enableUninstantiatedTypeOptimization = true;
- public boolean enableUninstantiatedTypeOptimizationForInterfaces = true;
+ // Currently disabled, see b/146957343.
+ public boolean enableUninstantiatedTypeOptimizationForInterfaces = false;
// TODO(b/138917494): Disable until we have numbers on potential performance penalties.
public boolean enableRedundantConstNumberOptimization = false;
diff --git a/src/test/java/com/android/tools/r8/shaking/InvalidTypesTest.java b/src/test/java/com/android/tools/r8/shaking/InvalidTypesTest.java
index b951b4f..b42be41 100644
--- a/src/test/java/com/android/tools/r8/shaking/InvalidTypesTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/InvalidTypesTest.java
@@ -40,7 +40,8 @@
D8,
JAVAC,
PROGUARD,
- R8
+ R8,
+ R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES
}
private enum Mode {
@@ -207,6 +208,27 @@
.setMinApi(parameters.getRuntime())
.run(parameters.getRuntime(), mainClass.name);
checkTestRunResult(r8Result, Compiler.R8);
+
+ R8TestRunResult r8ResultWithUninstantiatedTypeOptimizationForInterfaces =
+ testForR8(parameters.getBackend())
+ .addProgramFiles(inputJar)
+ .addKeepMainRule(mainClass.name)
+ .addKeepRules(
+ "-keep class TestClass { public static I g; }",
+ "-neverinline class TestClass { public static void m(); }")
+ .enableProguardTestOptions()
+ .addOptionsModification(
+ options -> {
+ if (mode == Mode.INVOKE_UNVERIFIABLE_METHOD) {
+ options.testing.allowTypeErrors = true;
+ }
+ options.enableUninstantiatedTypeOptimizationForInterfaces = true;
+ })
+ .setMinApi(parameters.getRuntime())
+ .run(parameters.getRuntime(), mainClass.name);
+ checkTestRunResult(
+ r8ResultWithUninstantiatedTypeOptimizationForInterfaces,
+ Compiler.R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES);
}
private void checkTestRunResult(TestRunResult<?> result, Compiler compiler) {
@@ -219,7 +241,9 @@
if (useInterface) {
result.assertSuccessWithOutput(getExpectedOutput(compiler));
} else {
- if (compiler == Compiler.R8 || compiler == Compiler.PROGUARD) {
+ if (compiler == Compiler.R8
+ || compiler == Compiler.R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES
+ || compiler == Compiler.PROGUARD) {
result.assertSuccessWithOutput(getExpectedOutput(compiler));
} else {
result
@@ -233,7 +257,8 @@
if (useInterface) {
result.assertSuccessWithOutput(getExpectedOutput(compiler));
} else {
- if (compiler == Compiler.R8) {
+ if (compiler == Compiler.R8
+ || compiler == Compiler.R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES) {
result
.assertFailureWithOutput(getExpectedOutput(compiler))
.assertFailureWithErrorThatMatches(
@@ -261,7 +286,9 @@
if (useInterface) {
return StringUtils.joinLines("Hello!", "In verifiable method!", "Goodbye!", "");
} else {
- if (compiler == Compiler.R8 || compiler == Compiler.PROGUARD) {
+ if (compiler == Compiler.R8
+ || compiler == Compiler.R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES
+ || compiler == Compiler.PROGUARD) {
// The unverifiable method has been removed as a result of tree shaking, so the code does
// not fail with a verification error when trying to load class `UnverifiableClass`.
return StringUtils.joinLines("Hello!", "In verifiable method!", "Goodbye!", "");
@@ -274,14 +301,14 @@
}
assert mode == Mode.INVOKE_UNVERIFIABLE_METHOD;
if (useInterface) {
- if (compiler == Compiler.R8) {
+ if (compiler == Compiler.R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES) {
return StringUtils.joinLines(
"Hello!",
"Unexpected outcome of getstatic",
"Unexpected outcome of checkcast",
"Goodbye!",
"");
- } else if (compiler == Compiler.PROGUARD) {
+ } else if (compiler == Compiler.R8 || compiler == Compiler.PROGUARD) {
return StringUtils.joinLines("Hello!", "Unexpected outcome of checkcast", "Goodbye!", "");
} else if (compiler == Compiler.DX || compiler == Compiler.D8) {
if (ToolHelper.getDexVm().getVersion() == Version.V4_0_4
diff --git a/src/test/java/com/android/tools/r8/shaking/annotations/ReflectiveAnnotationUseTest.java b/src/test/java/com/android/tools/r8/shaking/annotations/ReflectiveAnnotationUseTest.java
index 74f4321..5c6a305 100644
--- a/src/test/java/com/android/tools/r8/shaking/annotations/ReflectiveAnnotationUseTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/annotations/ReflectiveAnnotationUseTest.java
@@ -207,9 +207,9 @@
assertThat(clazz, isPresent());
assertEquals(minify, clazz.isRenamed());
MethodSubject f1 = clazz.uniqueMethodWithName("f1");
- assertThat(f1, not(isPresent()));
+ assertThat(f1, isPresent());
MethodSubject f2 = clazz.uniqueMethodWithName("f2");
- assertThat(f2, not(isPresent()));
+ assertThat(f2, isPresent());
MethodSubject f3 = clazz.uniqueMethodWithName("f3");
assertThat(f3, not(isPresent()));
MethodSubject f4 = clazz.uniqueMethodWithName("f4");