Enable minimal synthetic names in D8 intermediate tests
Bug: b/185560004
Change-Id: I11c022296cd56ec6db690412a6c842b0e4592621
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticDefinition.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticDefinition.java
index cddae05..36729e5 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticDefinition.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticDefinition.java
@@ -75,7 +75,8 @@
// name back to the original context.
return context.getSynthesizingContextType().toBinaryName();
}
- return SyntheticNaming.getPrefixForExternalSyntheticType(getKind(), getHolder().getType());
+ return SyntheticNaming.getPrefixForExternalSyntheticType(
+ getKind(), getHolder().getType(), appView);
}
public abstract C getHolder();
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
index a6d7112..0f2f5e6 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
@@ -336,7 +336,8 @@
return;
}
String prefix =
- SyntheticNaming.getPrefixForExternalSyntheticType(item.getKind(), item.getHolder());
+ SyntheticNaming.getPrefixForExternalSyntheticType(
+ item.getKind(), item.getHolder(), appView);
assert !prefix.contains(SyntheticNaming.getPhaseSeparator(Phase.INTERNAL));
DexType context =
appView
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
index 406c2de..a98b37f 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticItems.java
@@ -603,8 +603,11 @@
}
boolean isSyntheticInput(DexProgramClass clazz) {
- return committed.containsSyntheticInput(clazz.getType())
- || finalized.containsSyntheticInput(clazz.getType());
+ return isSyntheticInput(clazz.getType());
+ }
+
+ boolean isSyntheticInput(DexType type) {
+ return committed.containsSyntheticInput(type) || finalized.containsSyntheticInput(type);
}
public FeatureSplit getContextualFeatureSplitOrDefault(DexType type, FeatureSplit defaultValue) {
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticMarker.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticMarker.java
index 7670696..a2e13b6 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticMarker.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticMarker.java
@@ -9,7 +9,6 @@
import com.android.tools.r8.graph.DexAnnotation.SynthesizedAnnotationClassInfo;
import com.android.tools.r8.graph.DexAnnotationSet;
import com.android.tools.r8.graph.DexEncodedMethod;
-import com.android.tools.r8.graph.DexItemFactory;
import com.android.tools.r8.graph.DexProgramClass;
import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.synthesis.SyntheticNaming.SyntheticKind;
@@ -131,8 +130,7 @@
return NO_MARKER;
}
assert marker.getContext() == null;
- DexType contextType =
- getSyntheticContextType(clazz.type, marker.kind, appView.dexItemFactory());
+ DexType contextType = getSyntheticContextType(clazz.type, marker.kind, appView);
SynthesizingContext context =
SynthesizingContext.fromSyntheticInputClass(clazz, contextType, appView);
return new SyntheticMarker(marker.kind, context);
@@ -175,7 +173,7 @@
}
clazz.setAnnotations(DexAnnotationSet.empty());
clazz.forEachMethod(method -> method.setApiLevelForCode(synthesizedInfo.getComputedApiLevel()));
- DexType context = getSyntheticContextType(clazz.type, kind, appView.dexItemFactory());
+ DexType context = getSyntheticContextType(clazz.type, kind, appView);
return new SyntheticMarker(
kind, SynthesizingContext.fromSyntheticInputClass(clazz, context, appView));
}
@@ -187,12 +185,15 @@
}
private static DexType getSyntheticContextType(
- DexType type, SyntheticKind kind, DexItemFactory factory) {
+ DexType type, SyntheticKind kind, AppView<?> appView) {
if (kind.isGlobal()) {
return type;
}
- String prefix = SyntheticNaming.getOuterContextFromExternalSyntheticType(kind, type);
- return factory.createType(DescriptorUtils.getDescriptorFromClassBinaryName(prefix));
+ String prefix =
+ SyntheticNaming.getOuterContextFromExternalSyntheticType(kind, type, appView.options());
+ return appView
+ .dexItemFactory()
+ .createType(DescriptorUtils.getDescriptorFromClassBinaryName(prefix));
}
private static final SyntheticMarker NO_MARKER = new SyntheticMarker(null, null);
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticNaming.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticNaming.java
index fbc5471..3f6f217 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticNaming.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticNaming.java
@@ -436,28 +436,43 @@
/** Method name when generating synthetic methods in a class. */
static final String INTERNAL_SYNTHETIC_METHOD_NAME = "m";
- static String getPrefixForExternalSyntheticType(SyntheticKind kind, DexType type) {
+ static String getPrefixForExternalSyntheticType(
+ SyntheticKind kind, DexType type, AppView<?> appView) {
String binaryName = type.toBinaryName();
if (kind.isGlobal()) {
return binaryName;
}
- int index =
- binaryName.lastIndexOf(
- kind.isFixedSuffixSynthetic() ? kind.descriptor : SYNTHETIC_CLASS_SEPARATOR);
+ int index;
+ if (kind.isFixedSuffixSynthetic()) {
+ index = binaryName.lastIndexOf(kind.descriptor);
+ } else {
+ // If this synthetic class was present on input from an intermediate compilation then it
+ // won't have the $$InternalSynthetic marker.
+ if (appView.options().desugarSpecificOptions().minimizeSyntheticNames
+ && appView.getSyntheticItems().isSyntheticInput(type)) {
+ index = binaryName.lastIndexOf(INNER_CLASS_SEPARATOR);
+ } else {
+ index = binaryName.lastIndexOf(SYNTHETIC_CLASS_SEPARATOR);
+ }
+ }
if (index < 0) {
throw new Unreachable("Unexpected failure to compute a synthetic prefix for " + binaryName);
}
return binaryName.substring(0, index);
}
- static String getOuterContextFromExternalSyntheticType(SyntheticKind kind, DexType type) {
+ static String getOuterContextFromExternalSyntheticType(
+ SyntheticKind kind, DexType type, InternalOptions options) {
assert !kind.isGlobal();
String binaryName = type.toBinaryName();
- int index =
- binaryName.lastIndexOf(
- kind.isFixedSuffixSynthetic()
- ? kind.descriptor
- : EXTERNAL_SYNTHETIC_CLASS_SEPARATOR + kind.getDescriptor());
+ int index;
+ if (kind.isFixedSuffixSynthetic()) {
+ index = binaryName.lastIndexOf(kind.descriptor);
+ } else if (options.desugarSpecificOptions().minimizeSyntheticNames) {
+ index = binaryName.lastIndexOf(INNER_CLASS_SEPARATOR);
+ } else {
+ index = binaryName.lastIndexOf(EXTERNAL_SYNTHETIC_CLASS_SEPARATOR + kind.getDescriptor());
+ }
if (index < 0) {
throw new Unreachable(
"Unexpected failure to determine the context of synthetic class: " + binaryName);
@@ -492,7 +507,7 @@
if (kind.isFixedSuffixSynthetic()) {
assert id.isEmpty();
return createType("", kind, externalSyntheticTypePrefix, id, factory);
- } else if (options.desugarSpecificOptions().minimizeSyntheticNames && !options.intermediate) {
+ } else if (options.desugarSpecificOptions().minimizeSyntheticNames) {
return factory.createType(
DescriptorUtils.getDescriptorFromClassBinaryName(
externalSyntheticTypePrefix + INNER_CLASS_SEPARATOR + id));
diff --git a/src/test/java/com/android/tools/r8/compilerapi/syntheticscontexts/SyntheticContextsConsumerTest.java b/src/test/java/com/android/tools/r8/compilerapi/syntheticscontexts/SyntheticContextsConsumerTest.java
index 6c6544e..905b235 100644
--- a/src/test/java/com/android/tools/r8/compilerapi/syntheticscontexts/SyntheticContextsConsumerTest.java
+++ b/src/test/java/com/android/tools/r8/compilerapi/syntheticscontexts/SyntheticContextsConsumerTest.java
@@ -44,6 +44,9 @@
D8TestCompileResult compileResult =
testForD8(Backend.CF)
.addProgramClasses(UsesBackport.class)
+ // Disable since the external compilation runs with non-minimal synthetic names.
+ .addOptionsModification(
+ options -> options.desugarSpecificOptions().minimizeSyntheticNames = false)
.collectSyntheticItems()
.setIntermediate(true)
.setMinApi(1)
diff --git a/src/test/java/com/android/tools/r8/desugar/lambdas/DeduplicateLambdasWithDefaultMethodsTest.java b/src/test/java/com/android/tools/r8/desugar/lambdas/DeduplicateLambdasWithDefaultMethodsTest.java
index 62e4eb4..b08625b 100644
--- a/src/test/java/com/android/tools/r8/desugar/lambdas/DeduplicateLambdasWithDefaultMethodsTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/lambdas/DeduplicateLambdasWithDefaultMethodsTest.java
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.desugar.lambdas;
-import static com.android.tools.r8.synthesis.SyntheticItemsTestUtils.getDefaultSyntheticItemsTestUtils;
import static org.junit.Assert.assertEquals;
import com.android.tools.r8.TestBase;
@@ -33,22 +32,24 @@
@Test
public void test() throws Exception {
- assertEquals(
- ImmutableSet.of(
- Reference.classFromClass(I.class),
- Reference.classFromClass(TestClass.class),
- SyntheticItemsTestUtils.syntheticCompanionClass(I.class),
- getDefaultSyntheticItemsTestUtils().syntheticLambdaClass(TestClass.class, 0)),
- testForD8(Backend.CF)
- .addInnerClasses(getClass())
- .setIntermediate(true)
- .setMinApi(AndroidApiLevel.B)
- .compile()
- .inspector()
- .allClasses()
- .stream()
- .map(FoundClassSubject::getFinalReference)
- .collect(Collectors.toSet()));
+ testForD8(Backend.CF)
+ .addInnerClasses(getClass())
+ .collectSyntheticItems()
+ .setIntermediate(true)
+ .setMinApi(AndroidApiLevel.B)
+ .compile()
+ .inspectWithSyntheticItems(
+ (inspector, syntheticItems) -> {
+ assertEquals(
+ ImmutableSet.of(
+ Reference.classFromClass(I.class),
+ Reference.classFromClass(TestClass.class),
+ SyntheticItemsTestUtils.syntheticCompanionClass(I.class),
+ syntheticItems.syntheticLambdaClass(TestClass.class, 0)),
+ inspector.allClasses().stream()
+ .map(FoundClassSubject::getFinalReference)
+ .collect(Collectors.toSet()));
+ });
}
interface I {
diff --git a/src/test/java/com/android/tools/r8/globalsynthetics/GlobalSyntheticsEnsureClassesOutputTest.java b/src/test/java/com/android/tools/r8/globalsynthetics/GlobalSyntheticsEnsureClassesOutputTest.java
index 71d1d19..803751c 100644
--- a/src/test/java/com/android/tools/r8/globalsynthetics/GlobalSyntheticsEnsureClassesOutputTest.java
+++ b/src/test/java/com/android/tools/r8/globalsynthetics/GlobalSyntheticsEnsureClassesOutputTest.java
@@ -55,6 +55,9 @@
.apply(
b ->
b.getBuilder().addGlobalSyntheticsResourceProviders(globalsConsumer.getProviders()))
+ // Enable when enabled in GlobalSyntheticsGenerator above.
+ .addOptionsModification(
+ options -> options.desugarSpecificOptions().minimizeSyntheticNames = false)
.setMinApi(AndroidApiLevel.K)
.compile()
.inspect(
diff --git a/src/test/java/com/android/tools/r8/profile/art/completeness/ApiOutlineProfileRewritingShardTest.java b/src/test/java/com/android/tools/r8/profile/art/completeness/ApiOutlineProfileRewritingShardTest.java
index 7679c5a..1475ce4 100644
--- a/src/test/java/com/android/tools/r8/profile/art/completeness/ApiOutlineProfileRewritingShardTest.java
+++ b/src/test/java/com/android/tools/r8/profile/art/completeness/ApiOutlineProfileRewritingShardTest.java
@@ -142,7 +142,7 @@
Class<?> mainClass)
throws Exception {
// Verify that outlining happened.
- verifyThat(inspector, parameters, LibraryClass.class)
+ verifyThat(inspector, parameters, LibraryClass.class, syntheticItems)
.applyIf(
isLibraryClassAlwaysPresent(),
verifier ->
diff --git a/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationNestedSyntheticsAndStrippedMarkerTest.java b/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationNestedSyntheticsAndStrippedMarkerTest.java
index 9959eb7..12476f3 100644
--- a/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationNestedSyntheticsAndStrippedMarkerTest.java
+++ b/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationNestedSyntheticsAndStrippedMarkerTest.java
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.synthesis;
-import static com.android.tools.r8.synthesis.SyntheticItemsTestUtils.getDefaultSyntheticItemsTestUtils;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
@@ -53,15 +52,8 @@
@Test
public void test() throws Exception {
- assertEquals(Backend.DEX, parameters.getBackend());
-
- ClassReference syntheticLambdaClass =
- getDefaultSyntheticItemsTestUtils().syntheticLambdaClass(UsesBackport.class, 0);
- ImmutableSet<String> expectedClassOutputs =
- ImmutableSet.of(descriptor(UsesBackport.class), syntheticLambdaClass.getDescriptor());
-
Map<String, byte[]> firstCompilation = new HashMap<>();
- D8TestCompileResult initialIntermediateCompileResult =
+ SyntheticItemsTestUtils firstSyntheticItems =
testForD8(Backend.CF)
// High API level such that only the lambda is desugared.
.setMinApi(AndroidApiLevel.S)
@@ -84,10 +76,17 @@
@Override
public void finished(DiagnosticsHandler handler) {}
})
- .compile();
+ .compile()
+ .getSyntheticItems();
+
+ ClassReference syntheticLambdaClass =
+ firstSyntheticItems.syntheticLambdaClass(UsesBackport.class, 0);
+ ImmutableSet<String> expectedClassOutputs =
+ ImmutableSet.of(descriptor(UsesBackport.class), syntheticLambdaClass.getDescriptor());
assertEquals(expectedClassOutputs, firstCompilation.keySet());
Map<String, byte[]> secondCompilation = new HashMap<>();
+ SyntheticItemsTestUtils secondSyntheticItems = null;
ImmutableSet.Builder<String> allDescriptors = ImmutableSet.builder();
BooleanBox matched = new BooleanBox(false);
for (Entry<String, byte[]> entry : firstCompilation.entrySet()) {
@@ -99,8 +98,9 @@
return entry.getKey();
}
};
- D8TestCompileResult secondIntermediateCompileResult =
+ D8TestCompileResult secondCompileResult =
testForD8(intermediateBackend)
+ .collectSyntheticItems()
.setMinApi(parameters)
.setIntermediate(true)
.addClasspathClasses(I.class)
@@ -157,6 +157,9 @@
public void finished(DiagnosticsHandler handler) {}
}))
.compile();
+ if (entry.getKey().equals(syntheticLambdaClass.getDescriptor())) {
+ secondSyntheticItems = secondCompileResult.getSyntheticItems();
+ }
}
assertTrue(matched.get());
// The dex file per class file output should maintain the exact same set of primary descriptors.
@@ -165,13 +168,13 @@
}
// The total set of classes should also include the backport. The backport should be
// hygienically placed under the synthetic lambda (not the context of the lambda!).
+ ClassReference syntheticBackportClass =
+ secondSyntheticItems.syntheticBackportClass(syntheticLambdaClass, 0);
+ assertEquals(syntheticLambdaClass.getTypeName() + "$0", syntheticBackportClass.getTypeName());
assertEquals(
ImmutableSet.<String>builder()
.addAll(expectedClassOutputs)
- .add(
- getDefaultSyntheticItemsTestUtils()
- .syntheticBackportClass(syntheticLambdaClass, 0)
- .getDescriptor())
+ .add(syntheticBackportClass.getDescriptor())
.build(),
allDescriptors.build());
@@ -210,9 +213,7 @@
.collect(Collectors.toSet());
// The initial lambda stays as the only item under UsesBackport.
ClassReference lambdaClass =
- initialIntermediateCompileResult
- .getSyntheticItems()
- .syntheticLambdaClass(UsesBackport.class, 0);
+ firstSyntheticItems.syntheticLambdaClass(UsesBackport.class, 0);
// The nested backport has context in the lambda since the lambda was not marked.
ClassReference backportClass =
thirdNonIntermediateCompileResult
diff --git a/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationNestedSyntheticsTest.java b/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationNestedSyntheticsTest.java
index bdbfaae..135082a 100644
--- a/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationNestedSyntheticsTest.java
+++ b/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationNestedSyntheticsTest.java
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.synthesis;
-import static com.android.tools.r8.synthesis.SyntheticItemsTestUtils.getDefaultSyntheticItemsTestUtils;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
@@ -11,6 +10,7 @@
import com.android.tools.r8.ByteDataView;
import com.android.tools.r8.ClassFileConsumer;
+import com.android.tools.r8.D8TestCompileResult;
import com.android.tools.r8.DesugarGraphConsumer;
import com.android.tools.r8.DexFilePerClassFileConsumer;
import com.android.tools.r8.DiagnosticsHandler;
@@ -52,34 +52,37 @@
@Test
public void test() throws Exception {
- assertEquals(Backend.DEX, parameters.getBackend());
+ Map<String, byte[]> firstCompilation = new HashMap<>();
+ SyntheticItemsTestUtils firstSyntheticItems =
+ testForD8(Backend.CF)
+ .collectSyntheticItems()
+ // High API level such that only the lambda is desugared.
+ .setMinApi(AndroidApiLevel.S)
+ .setIntermediate(true)
+ .addClasspathClasses(I.class)
+ .addProgramClasses(UsesBackport.class)
+ .setProgramConsumer(
+ new ClassFileConsumer() {
+ @Override
+ public void accept(
+ ByteDataView data, String descriptor, DiagnosticsHandler handler) {
+ firstCompilation.put(descriptor, data.copyByteData());
+ }
+
+ @Override
+ public void finished(DiagnosticsHandler handler) {}
+ })
+ .compile()
+ .getSyntheticItems();
ClassReference syntheticLambdaClass =
- getDefaultSyntheticItemsTestUtils().syntheticLambdaClass(UsesBackport.class, 0);
+ firstSyntheticItems.syntheticLambdaClass(UsesBackport.class, 0);
ImmutableSet<String> expectedClassOutputs =
ImmutableSet.of(descriptor(UsesBackport.class), syntheticLambdaClass.getDescriptor());
-
- Map<String, byte[]> firstCompilation = new HashMap<>();
- testForD8(Backend.CF)
- // High API level such that only the lambda is desugared.
- .setMinApi(AndroidApiLevel.S)
- .setIntermediate(true)
- .addClasspathClasses(I.class)
- .addProgramClasses(UsesBackport.class)
- .setProgramConsumer(
- new ClassFileConsumer() {
- @Override
- public void accept(ByteDataView data, String descriptor, DiagnosticsHandler handler) {
- firstCompilation.put(descriptor, data.copyByteData());
- }
-
- @Override
- public void finished(DiagnosticsHandler handler) {}
- })
- .compile();
assertEquals(expectedClassOutputs, firstCompilation.keySet());
Map<String, byte[]> secondCompilation = new HashMap<>();
+ SyntheticItemsTestUtils secondSyntheticItems = null;
ImmutableSet.Builder<String> allDescriptors = ImmutableSet.builder();
BooleanBox matched = new BooleanBox(false);
for (Entry<String, byte[]> entry : firstCompilation.entrySet()) {
@@ -91,63 +94,68 @@
return entry.getKey();
}
};
- testForD8(intermediateBackend)
- .setMinApi(parameters)
- .setIntermediate(true)
- .addClasspathClasses(I.class)
- .apply(b -> b.getBuilder().addClassProgramData(bytes, origin))
- .apply(
- b ->
- b.getBuilder()
- .setDesugarGraphConsumer(
- new DesugarGraphConsumer() {
+ D8TestCompileResult secondCompileResult =
+ testForD8(intermediateBackend)
+ .collectSyntheticItems()
+ .setMinApi(parameters)
+ .setIntermediate(true)
+ .addClasspathClasses(I.class)
+ .apply(b -> b.getBuilder().addClassProgramData(bytes, origin))
+ .apply(
+ b ->
+ b.getBuilder()
+ .setDesugarGraphConsumer(
+ new DesugarGraphConsumer() {
+ @Override
+ public void accept(Origin dependent, Origin dependency) {
+ assertThat(
+ dependency.toString(), containsString(binaryName(I.class)));
+ assertThat(
+ dependent.toString(),
+ containsString(syntheticLambdaClass.getBinaryName()));
+ matched.set(true);
+ }
+
+ @Override
+ public void finished() {}
+ }))
+ .applyIf(
+ intermediateBackend == Backend.CF,
+ b ->
+ b.setProgramConsumer(
+ new ClassFileConsumer() {
@Override
- public void accept(Origin dependent, Origin dependency) {
- assertThat(
- dependency.toString(), containsString(binaryName(I.class)));
- assertThat(
- dependent.toString(),
- containsString(syntheticLambdaClass.getBinaryName()));
- matched.set(true);
+ public void accept(
+ ByteDataView data, String descriptor, DiagnosticsHandler handler) {
+ secondCompilation.put(descriptor, data.copyByteData());
+ allDescriptors.add(descriptor);
}
@Override
- public void finished() {}
+ public void finished(DiagnosticsHandler handler) {}
+ }),
+ b ->
+ b.setProgramConsumer(
+ new DexFilePerClassFileConsumer() {
+
+ @Override
+ public void accept(
+ String primaryClassDescriptor,
+ ByteDataView data,
+ Set<String> descriptors,
+ DiagnosticsHandler handler) {
+ secondCompilation.put(primaryClassDescriptor, data.copyByteData());
+ allDescriptors.addAll(descriptors);
+ }
+
+ @Override
+ public void finished(DiagnosticsHandler handler) {}
}))
- .applyIf(
- intermediateBackend == Backend.CF,
- b ->
- b.setProgramConsumer(
- new ClassFileConsumer() {
- @Override
- public void accept(
- ByteDataView data, String descriptor, DiagnosticsHandler handler) {
- secondCompilation.put(descriptor, data.copyByteData());
- allDescriptors.add(descriptor);
- }
-
- @Override
- public void finished(DiagnosticsHandler handler) {}
- }),
- b ->
- b.setProgramConsumer(
- new DexFilePerClassFileConsumer() {
-
- @Override
- public void accept(
- String primaryClassDescriptor,
- ByteDataView data,
- Set<String> descriptors,
- DiagnosticsHandler handler) {
- secondCompilation.put(primaryClassDescriptor, data.copyByteData());
- allDescriptors.addAll(descriptors);
- }
-
- @Override
- public void finished(DiagnosticsHandler handler) {}
- }))
- .compile();
+ .compile();
+ if (entry.getKey().equals(syntheticLambdaClass.getDescriptor())) {
+ secondSyntheticItems = secondCompileResult.getSyntheticItems();
+ }
}
assertTrue(matched.get());
// The dex file per class file output should maintain the exact same set of primary descriptors.
@@ -156,13 +164,13 @@
}
// The total set of classes should also include the backport. The backport should be
// hygienically placed under the synthetic lambda (not the context of the lambda!).
+ ClassReference syntheticBackportClass =
+ secondSyntheticItems.syntheticBackportClass(UsesBackport.class, 0);
+ assertEquals(syntheticLambdaClass.getTypeName() + "$0", syntheticBackportClass.getTypeName());
assertEquals(
ImmutableSet.<String>builder()
.addAll(expectedClassOutputs)
- .add(
- getDefaultSyntheticItemsTestUtils()
- .syntheticBackportClass(syntheticLambdaClass, 0)
- .getDescriptor())
+ .add(syntheticBackportClass.getDescriptor())
.build(),
allDescriptors.build());
diff --git a/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationSyntheticsTest.java b/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationSyntheticsTest.java
index 212c062..cd76ece 100644
--- a/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationSyntheticsTest.java
+++ b/src/test/java/com/android/tools/r8/synthesis/RepeatedCompilationSyntheticsTest.java
@@ -3,17 +3,18 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.synthesis;
-import static com.android.tools.r8.synthesis.SyntheticItemsTestUtils.getDefaultSyntheticItemsTestUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import com.android.tools.r8.ByteDataView;
import com.android.tools.r8.ClassFileConsumer;
+import com.android.tools.r8.D8TestCompileResult;
import com.android.tools.r8.DexFilePerClassFileConsumer;
import com.android.tools.r8.DiagnosticsHandler;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.utils.AndroidApiLevel;
+import com.android.tools.r8.utils.ListUtils;
import com.android.tools.r8.utils.StringUtils;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -61,87 +62,87 @@
@Test
public void test() throws Exception {
- assertEquals(Backend.DEX, parameters.getBackend());
-
Map<String, byte[]> firstCompilation = new HashMap<>();
- testForD8(Backend.CF)
- // High API level such that only the compareUnsigned is desugared.
- .setMinApi(API_WITH_BYTE_COMPARE)
- .setIntermediate(true)
- .addProgramClassFileData(getTransformedUsesBackport())
- .setProgramConsumer(
- new ClassFileConsumer() {
- @Override
- public synchronized void accept(
- ByteDataView data, String descriptor, DiagnosticsHandler handler) {
- byte[] old = firstCompilation.put(descriptor, data.copyByteData());
- assertNull("Duplicate " + descriptor, old);
- }
+ SyntheticItemsTestUtils firstSyntheticItems =
+ testForD8(Backend.CF)
+ .collectSyntheticItems()
+ // High API level such that only the compareUnsigned is desugared.
+ .setMinApi(API_WITH_BYTE_COMPARE)
+ .setIntermediate(true)
+ .addProgramClassFileData(getTransformedUsesBackport())
+ .setProgramConsumer(
+ new ClassFileConsumer() {
+ @Override
+ public synchronized void accept(
+ ByteDataView data, String descriptor, DiagnosticsHandler handler) {
+ byte[] old = firstCompilation.put(descriptor, data.copyByteData());
+ assertNull("Duplicate " + descriptor, old);
+ }
- @Override
- public void finished(DiagnosticsHandler handler) {}
- })
- .compile();
+ @Override
+ public void finished(DiagnosticsHandler handler) {}
+ })
+ .compile()
+ .getSyntheticItems();
assertEquals(
ImmutableSet.of(
descriptor(UsesBackport.class),
- getDefaultSyntheticItemsTestUtils()
- .syntheticBackportClass(UsesBackport.class, 0)
- .getDescriptor()),
+ firstSyntheticItems.syntheticBackportClass(UsesBackport.class, 0).getDescriptor()),
firstCompilation.keySet());
List<String> secondCompilation = new ArrayList<>();
+ SyntheticItemsTestUtils secondSyntheticItems = null;
for (Entry<String, byte[]> entry : firstCompilation.entrySet()) {
byte[] bytes = entry.getValue();
- testForD8(intermediateBackend)
- .setMinApi(parameters)
- .setIntermediate(true)
- .addProgramClassFileData(bytes)
- .applyIf(
- intermediateBackend == Backend.CF,
- b ->
- b.setProgramConsumer(
- new ClassFileConsumer() {
- @Override
- public synchronized void accept(
- ByteDataView data, String descriptor, DiagnosticsHandler handler) {
- secondCompilation.add(descriptor);
- }
+ D8TestCompileResult secondCompileResult =
+ testForD8(intermediateBackend)
+ .collectSyntheticItems()
+ .setMinApi(parameters)
+ .setIntermediate(true)
+ .addProgramClassFileData(bytes)
+ .applyIf(
+ intermediateBackend == Backend.CF,
+ b ->
+ b.setProgramConsumer(
+ new ClassFileConsumer() {
+ @Override
+ public synchronized void accept(
+ ByteDataView data, String descriptor, DiagnosticsHandler handler) {
+ secondCompilation.add(descriptor);
+ }
- @Override
- public void finished(DiagnosticsHandler handler) {}
- }),
- b ->
- b.setProgramConsumer(
- new DexFilePerClassFileConsumer() {
- @Override
- public void accept(
- String primaryClassDescriptor,
- ByteDataView data,
- Set<String> descriptors,
- DiagnosticsHandler handler) {
- secondCompilation.addAll(descriptors);
- }
+ @Override
+ public void finished(DiagnosticsHandler handler) {}
+ }),
+ b ->
+ b.setProgramConsumer(
+ new DexFilePerClassFileConsumer() {
+ @Override
+ public void accept(
+ String primaryClassDescriptor,
+ ByteDataView data,
+ Set<String> descriptors,
+ DiagnosticsHandler handler) {
+ secondCompilation.addAll(descriptors);
+ }
- @Override
- public void finished(DiagnosticsHandler handler) {}
- }))
- .compile();
+ @Override
+ public void finished(DiagnosticsHandler handler) {}
+ }))
+ .compile();
+ if (entry.getKey().equals(descriptor(UsesBackport.class))) {
+ secondSyntheticItems = secondCompileResult.getSyntheticItems();
+ }
}
// TODO(b/271235788): The repeated compilation is unsound and we have duplicate definitions of
// the backports both using the same type name.
- secondCompilation.sort(String::compareTo);
assertEquals(
ImmutableList.of(
- getDefaultSyntheticItemsTestUtils()
- .syntheticBackportClass(UsesBackport.class, 0)
- .getDescriptor(),
- getDefaultSyntheticItemsTestUtils()
- .syntheticBackportClass(UsesBackport.class, 0)
- .getDescriptor(),
+ firstSyntheticItems.syntheticBackportClass(UsesBackport.class, 0).getDescriptor(),
+ secondSyntheticItems.syntheticBackportClass(UsesBackport.class, 0).getDescriptor(),
descriptor(UsesBackport.class)),
- secondCompilation);
+ ListUtils.destructiveSort(secondCompilation, String::compareTo));
}
private byte[] getTransformedUsesBackport() throws Exception {
diff --git a/src/test/testbase/java/com/android/tools/r8/apimodel/ApiModelingTestHelper.java b/src/test/testbase/java/com/android/tools/r8/apimodel/ApiModelingTestHelper.java
index cd022f8..26f99a1 100644
--- a/src/test/testbase/java/com/android/tools/r8/apimodel/ApiModelingTestHelper.java
+++ b/src/test/testbase/java/com/android/tools/r8/apimodel/ApiModelingTestHelper.java
@@ -4,7 +4,6 @@
package com.android.tools.r8.apimodel;
-import static com.android.tools.r8.synthesis.SyntheticItemsTestUtils.getDefaultSyntheticItemsTestUtils;
import static com.android.tools.r8.utils.codeinspector.CodeMatchers.accessesField;
import static com.android.tools.r8.utils.codeinspector.CodeMatchers.invokesMethod;
import static com.android.tools.r8.utils.codeinspector.CodeMatchers.invokesMethodWithHolderAndName;
@@ -242,7 +241,7 @@
public static ApiModelingClassVerificationHelper verifyThat(
CodeInspector inspector, TestParameters parameters, Class<?> clazz) {
- return verifyThat(inspector, parameters, clazz, getDefaultSyntheticItemsTestUtils());
+ return verifyThat(inspector, parameters, clazz, null);
}
public static ApiModelingClassVerificationHelper verifyThat(
diff --git a/third_party/binary_compatibility_tests/compiler_api_tests.tar.gz.sha1 b/third_party/binary_compatibility_tests/compiler_api_tests.tar.gz.sha1
index 8e95b3e..f5f3ac0 100644
--- a/third_party/binary_compatibility_tests/compiler_api_tests.tar.gz.sha1
+++ b/third_party/binary_compatibility_tests/compiler_api_tests.tar.gz.sha1
@@ -1 +1 @@
-ba206a3d39e1bac4793e54c9c30f3072ba220f3e
\ No newline at end of file
+e923542ae70a4c3944f53f434501677680db914e
\ No newline at end of file