Revert "Android U supports records and sealed classes"
This reverts commit 37b9a76bf701211c9579f97dcebdba145b0c8ef3.
Reason for revert: Test failures.
Bug: b/293592205
Change-Id: Idadbb43556a9306ffe15fe1c8ed09af7439ec38c
diff --git a/src/main/java/com/android/tools/r8/graph/DexAnnotation.java b/src/main/java/com/android/tools/r8/graph/DexAnnotation.java
index 0238749..968863a 100644
--- a/src/main/java/com/android/tools/r8/graph/DexAnnotation.java
+++ b/src/main/java/com/android/tools/r8/graph/DexAnnotation.java
@@ -573,25 +573,38 @@
}
}
- return new DexAnnotation(
- VISIBILITY_SYSTEM,
- new DexEncodedAnnotation(
- factory.annotationRecord,
- new DexAnnotationElement[] {
- new DexAnnotationElement(
- factory.annotationRecordComponentNames, new DexValueArray(componentNames)),
- new DexAnnotationElement(
- factory.annotationRecordComponentTypes, new DexValueArray(componentTypes)),
- new DexAnnotationElement(
- factory.annotationRecordComponentSignatures,
- new DexValueArray(componentSignatures)),
- new DexAnnotationElement(
- factory.annotationRecordComponentAnnotationVisibilities,
- new DexValueArray(componentAnnotationVisibilities)),
- new DexAnnotationElement(
- factory.annotationRecordComponentAnnotations,
- new DexValueArray(componentAnnotations))
- }));
+ if (appView.options().emitRecordAnnotationsExInDex) {
+ return new DexAnnotation(
+ VISIBILITY_SYSTEM,
+ new DexEncodedAnnotation(
+ factory.annotationRecord,
+ new DexAnnotationElement[] {
+ new DexAnnotationElement(
+ factory.annotationRecordComponentNames, new DexValueArray(componentNames)),
+ new DexAnnotationElement(
+ factory.annotationRecordComponentTypes, new DexValueArray(componentTypes)),
+ new DexAnnotationElement(
+ factory.annotationRecordComponentSignatures,
+ new DexValueArray(componentSignatures)),
+ new DexAnnotationElement(
+ factory.annotationRecordComponentAnnotationVisibilities,
+ new DexValueArray(componentAnnotationVisibilities)),
+ new DexAnnotationElement(
+ factory.annotationRecordComponentAnnotations,
+ new DexValueArray(componentAnnotations))
+ }));
+ } else {
+ return new DexAnnotation(
+ VISIBILITY_SYSTEM,
+ new DexEncodedAnnotation(
+ factory.annotationRecord,
+ new DexAnnotationElement[] {
+ new DexAnnotationElement(
+ factory.annotationRecordComponentNames, new DexValueArray(componentNames)),
+ new DexAnnotationElement(
+ factory.annotationRecordComponentTypes, new DexValueArray(componentTypes))
+ }));
+ }
}
public static String getSignature(DexAnnotation signatureAnnotation) {
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 f79fc07..03a8229 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -468,18 +468,18 @@
public boolean createSingletonsForStatelessLambdas =
System.getProperty("com.android.tools.r8.createSingletonsForStatelessLambdas") != null;
- // TODO(b/293591931): Remove this flag.
- // Flag to allow record annotations in DEX. See b/231930852 for context.
- private final boolean emitRecordAnnotationsInDex =
+ // Flag to allow record annotations in DEX. See b/231930852 for context.
+ public boolean emitRecordAnnotationsInDex =
System.getProperty("com.android.tools.r8.emitRecordAnnotationsInDex") != null;
+ public boolean emitRecordAnnotationsExInDex =
+ System.getProperty("com.android.tools.r8.emitRecordAnnotationsExInDex") != null;
// Flag to allow nest annotations in DEX. See b/231930852 for context.
public boolean emitNestAnnotationsInDex =
System.getProperty("com.android.tools.r8.emitNestAnnotationsInDex") != null;
- // TODO(b/293591931): Remove this flag.
// Flag to allow permitted subclasses annotations in DEX. See b/231930852 for context.
- private final boolean emitPermittedSubclassesAnnotationsInDex =
+ public boolean emitPermittedSubclassesAnnotationsInDex =
System.getProperty("com.android.tools.r8.emitPermittedSubclassesAnnotationsInDex") != null;
private DumpInputFlags dumpInputFlags = DumpInputFlags.getDefault();
@@ -2606,11 +2606,11 @@
}
public boolean canUseRecords() {
- return hasFeaturePresentFrom(AndroidApiLevel.U) || emitRecordAnnotationsInDex;
+ return hasFeaturePresentFrom(null) || emitRecordAnnotationsInDex;
}
public boolean canUseSealedClasses() {
- return hasFeaturePresentFrom(AndroidApiLevel.U) || emitPermittedSubclassesAnnotationsInDex;
+ return hasFeaturePresentFrom(null) || emitPermittedSubclassesAnnotationsInDex;
}
public boolean canLeaveStaticInterfaceMethodInvokes() {
diff --git a/src/test/java/com/android/tools/r8/desugar/records/RecordComponentAnnotationsTest.java b/src/test/java/com/android/tools/r8/desugar/records/RecordComponentAnnotationsTest.java
index 8ded32a..14485c9 100644
--- a/src/test/java/com/android/tools/r8/desugar/records/RecordComponentAnnotationsTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/records/RecordComponentAnnotationsTest.java
@@ -231,7 +231,16 @@
parameters.getApiLevel().isGreaterThanOrEqualTo(AndroidApiLevel.U);
boolean runtimeWithNativeRecordSupport =
parameters.getDexRuntimeVersion().isNewerThanOrEqual(Version.V14_0_0);
- testForDesugaring(parameters)
+ testForDesugaring(
+ parameters,
+ options -> {
+ if (compilingForNativeRecordSupport) {
+ // TODO(b/231930852): When Art 14 support records this will be controlled by API
+ // level.
+ options.emitRecordAnnotationsInDex = true;
+ options.emitRecordAnnotationsExInDex = true;
+ }
+ })
.addProgramClassFileData(PROGRAM_DATA)
.run(parameters.getRuntime(), MAIN_TYPE)
.applyIf(
@@ -331,6 +340,12 @@
"records.RecordWithAnnotations$AnnotationRecordComponentOnly")
.applyIf(keepAnnotations, TestShrinkerBuilder::addKeepRuntimeVisibleAnnotations)
.setMinApi(parameters)
+ .applyIf(
+ compilingForNativeRecordSupport,
+ // TODO(b/231930852): When Art 14 support records this will be controlled by API level.
+ b ->
+ b.addOptionsModification(options -> options.emitRecordAnnotationsInDex = true)
+ .addOptionsModification(options -> options.emitRecordAnnotationsExInDex = true))
.compile()
.inspect(
inspector -> {
diff --git a/src/test/java/com/android/tools/r8/desugar/records/RecordComponentSignatureTest.java b/src/test/java/com/android/tools/r8/desugar/records/RecordComponentSignatureTest.java
index ff6732a..db46699 100644
--- a/src/test/java/com/android/tools/r8/desugar/records/RecordComponentSignatureTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/records/RecordComponentSignatureTest.java
@@ -98,7 +98,16 @@
boolean runningWithNativeRecordSupport =
parameters.getRuntime().isDex()
&& parameters.getRuntime().asDex().getVersion().isNewerThanOrEqual(Version.V14_0_0);
- testForDesugaring(parameters)
+ testForDesugaring(
+ parameters,
+ options -> {
+ if (compilingForNativeRecordSupport) {
+ // TODO(b/231930852): When Art 14 support records this will be controlled by API
+ // level.
+ options.emitRecordAnnotationsInDex = true;
+ options.emitRecordAnnotationsExInDex = true;
+ }
+ })
.addProgramClassFileData(PROGRAM_DATA)
.run(parameters.getRuntime(), MAIN_TYPE)
.applyIf(
@@ -166,6 +175,12 @@
.addKeepMainRule(MAIN_TYPE)
.applyIf(keepSignatures, TestShrinkerBuilder::addKeepAttributeSignature)
.setMinApi(parameters)
+ .applyIf(
+ compilingForNativeRecordSupport,
+ // TODO(b/231930852): When Art 14 support records this will be controlled by API level.
+ b ->
+ b.addOptionsModification(options -> options.emitRecordAnnotationsInDex = true)
+ .addOptionsModification(options -> options.emitRecordAnnotationsExInDex = true))
.compile()
.inspect(
inspector -> {
diff --git a/src/test/java/com/android/tools/r8/desugar/sealed/PermittedSubclassesAttributeInDexTest.java b/src/test/java/com/android/tools/r8/desugar/sealed/PermittedSubclassesAttributeInDexTest.java
index 4934f16..cc01489 100644
--- a/src/test/java/com/android/tools/r8/desugar/sealed/PermittedSubclassesAttributeInDexTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/sealed/PermittedSubclassesAttributeInDexTest.java
@@ -39,7 +39,6 @@
return getTestParameters().withAllRuntimes().withAllApiLevelsAlsoForCf().build();
}
- private static final String EXPECTED_OUTPUT_PRE_34 = StringUtils.lines("false");
private static final String EXPECTED_OUTPUT = StringUtils.lines("true", "true");
@Test
@@ -57,12 +56,9 @@
private void inspect(CodeInspector inspector) {
assertEquals(
- parameters.getBackend().isDex()
- && parameters.getApiLevel().isGreaterThanOrEqualTo(AndroidApiLevel.U)
- ? ImmutableList.of(
- inspector.clazz(Sub1.class).asTypeSubject(),
- inspector.clazz(Sub2.class).asTypeSubject())
- : ImmutableList.of(),
+ ImmutableList.of(
+ inspector.clazz(Sub1.class).asTypeSubject(),
+ inspector.clazz(Sub2.class).asTypeSubject()),
inspector.clazz(C.class).getFinalPermittedSubclassAttributes());
}
@@ -73,17 +69,14 @@
.addProgramClassFileData(getTransformedClasses())
.addProgramClasses(Sub1.class, Sub2.class)
.setMinApi(parameters)
+ .addOptionsModification(options -> options.emitPermittedSubclassesAnnotationsInDex = true)
.compile()
.inspect(this::inspect)
.run(parameters.getRuntime(), TestClass.class)
.applyIf(
// TODO(b/270941147): Partial DEX support in Android U DP1 (reflective APIs).
parameters.isDexRuntimeVersionNewerThanOrEqual(Version.V14_0_0),
- r ->
- r.assertSuccessWithOutput(
- parameters.getApiLevel().isGreaterThanOrEqualTo(AndroidApiLevel.U)
- ? EXPECTED_OUTPUT
- : EXPECTED_OUTPUT_PRE_34),
+ r -> r.assertSuccessWithOutput(EXPECTED_OUTPUT),
r -> r.assertFailureWithErrorThatThrows(NoSuchMethodError.class));
}
@@ -142,12 +135,10 @@
public static void main(String[] args) {
System.out.println(AdditionalClassAPIs.isSealed(C.class));
- if (AdditionalClassAPIs.isSealed(C.class)) {
- System.out.println(
- sameArrayContent(
- new Class<?>[] {Sub1.class, Sub2.class},
- AdditionalClassAPIs.getPermittedSubclasses(C.class)));
- }
+ System.out.println(
+ sameArrayContent(
+ new Class<?>[] {Sub1.class, Sub2.class},
+ AdditionalClassAPIs.getPermittedSubclasses(C.class)));
}
}