Revert "Final synthetic ordering based on internal types."
This reverts commit 87e64ee7d31b67042b3a67bad4675e485e0f2525.
Reason for revert: red bots
Change-Id: Ic9f7f4e17bbcc6c3843aa60f50b3889655095662
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 533e24f..5cc5876 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
@@ -575,7 +575,10 @@
});
groupsPerPrefix.forEach(
(externalSyntheticTypePrefix, groups) -> {
- Comparator<EquivalenceGroup<T>> comparator = this::compareForFinalGroupSorting;
+ // Sort the equivalence groups that go into 'context' including the context type of the
+ // representative which is equal to 'context' here (see assert below).
+ Comparator<EquivalenceGroup<T>> comparator =
+ (a, b) -> a.compareToIncludingContext(b, appView.graphLens(), classToFeatureSplitMap);
ListUtils.destructiveSort(groups, comparator);
for (int i = 0; i < groups.size(); i++) {
EquivalenceGroup<T> group = groups.get(i);
@@ -585,7 +588,9 @@
.equals(externalSyntheticTypePrefix);
// Two equivalence groups in same context type must be distinct otherwise the assignment
// of the synthetic name will be non-deterministic between the two.
- assert i == 0 || checkGroupsAreDistinct(groups.get(i - 1), group, comparator);
+ assert i == 0
+ || checkGroupsAreDistinct(
+ groups.get(i - 1), group, appView.graphLens(), classToFeatureSplitMap);
SyntheticKind kind = group.getRepresentative().getKind();
DexType representativeType =
intermediate
@@ -612,17 +617,6 @@
return equivalences;
}
- private <T extends SyntheticDefinition<?, T, ?>> int compareForFinalGroupSorting(
- EquivalenceGroup<T> a, EquivalenceGroup<T> b) {
- // Sort the equivalence groups based on the representative types. The representatives are
- // deterministically chosen and the internal synthetics deterministically named so using
- // the internal type as the order is deterministic.
- return a.getRepresentative()
- .getHolder()
- .getType()
- .compareTo(b.getRepresentative().getHolder().getType());
- }
-
private static <T extends SyntheticDefinition<?, T, ?>> List<EquivalenceGroup<T>> groupEquivalent(
AppView<?> appView,
List<T> potentialEquivalence,
@@ -701,11 +695,13 @@
}
private static <T extends SyntheticDefinition<?, T, ?>> boolean checkGroupsAreDistinct(
- EquivalenceGroup<T> g1, EquivalenceGroup<T> g2, Comparator<EquivalenceGroup<T>> comparator) {
- int smaller = comparator.compare(g1, g2);
- assert smaller < 0;
- int bigger = comparator.compare(g2, g1);
- assert bigger > 0;
+ EquivalenceGroup<T> g1,
+ EquivalenceGroup<T> g2,
+ GraphLens graphLens,
+ ClassToFeatureSplitMap classToFeatureSplitMap) {
+ int order = g1.compareToIncludingContext(g2, graphLens, classToFeatureSplitMap);
+ assert order != 0;
+ assert order != g2.compareToIncludingContext(g1, graphLens, classToFeatureSplitMap);
return true;
}