Fix assertion error when building iosched
Change-Id: I67c0b803cb494e1ffc744cc10bfa865fe0d8ad70
diff --git a/src/main/java/com/android/tools/r8/ir/analysis/type/DynamicType.java b/src/main/java/com/android/tools/r8/ir/analysis/type/DynamicType.java
index 971a56e..fd17fa4 100644
--- a/src/main/java/com/android/tools/r8/ir/analysis/type/DynamicType.java
+++ b/src/main/java/com/android/tools/r8/ir/analysis/type/DynamicType.java
@@ -170,8 +170,8 @@
if (isBottom()) {
// Account for the fact that the in-static-type may be more precise than the static type of
// the current dynamic type.
- if (inDynamicType.isNotNullType() && inStaticType != null) {
- return create(appView, inStaticType.toNonNullTypeElement(appView));
+ if (inStaticType != null) {
+ return inDynamicType.uncanonicalizeNotNullType(appView, inStaticType);
}
return inDynamicType;
}
@@ -188,7 +188,7 @@
if (inStaticType == null || inStaticType.isIdenticalTo(outStaticType)) {
return getNullability().isNullable() ? unknown() : inDynamicType;
}
- inDynamicType = create(appView, inStaticType.toNonNullTypeElement(appView));
+ inDynamicType = inDynamicType.uncanonicalizeNotNullType(appView, inStaticType);
}
assert isDynamicTypeWithUpperBound();
assert inDynamicType.isDynamicTypeWithUpperBound();
@@ -198,6 +198,11 @@
public abstract DynamicType rewrittenWithLens(
AppView<AppInfoWithLiveness> appView, GraphLens graphLens, Set<DexType> prunedTypes);
+ public DynamicType uncanonicalizeNotNullType(
+ AppView<AppInfoWithLiveness> appView, DexType staticType) {
+ return this;
+ }
+
public abstract DynamicType withNullability(Nullability nullability);
@Override
diff --git a/src/main/java/com/android/tools/r8/ir/analysis/type/NotNullDynamicType.java b/src/main/java/com/android/tools/r8/ir/analysis/type/NotNullDynamicType.java
index 7645341..adfed52 100644
--- a/src/main/java/com/android/tools/r8/ir/analysis/type/NotNullDynamicType.java
+++ b/src/main/java/com/android/tools/r8/ir/analysis/type/NotNullDynamicType.java
@@ -56,6 +56,12 @@
}
@Override
+ public DynamicType uncanonicalizeNotNullType(
+ AppView<AppInfoWithLiveness> appView, DexType staticType) {
+ return DynamicType.create(appView, staticType.toNonNullTypeElement(appView));
+ }
+
+ @Override
public DynamicType withNullability(Nullability nullability) {
assert !nullability.isBottom();
return nullability.isDefinitelyNotNull() ? this : unknown();
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/passes/CodeRewriterPass.java b/src/main/java/com/android/tools/r8/ir/conversion/passes/CodeRewriterPass.java
index 87fc847..c56ddbf 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/passes/CodeRewriterPass.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/passes/CodeRewriterPass.java
@@ -29,8 +29,8 @@
}
@SuppressWarnings("unchecked")
- protected AppView<? extends T> appView() {
- return (AppView<? extends T>) appView;
+ protected AppView<T> appView() {
+ return (AppView<T>) appView;
}
public final CodeRewriterResult run(
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/enums/EnumUnboxerImpl.java b/src/main/java/com/android/tools/r8/ir/optimize/enums/EnumUnboxerImpl.java
index 65487d8..a7cbb72 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/enums/EnumUnboxerImpl.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/enums/EnumUnboxerImpl.java
@@ -967,14 +967,11 @@
unboxedValues.put(field.getReference(), ordinalToUnboxedInt(ordinal));
ordinalToObjectState.put(ordinal, enumState);
if (isEnumWithSubtypes) {
- DynamicType dynamicType = field.getOptimizationInfo().getDynamicType();
- // If the dynamic type is a NotNull dynamic type, then de-canonicalize the dynamic
- // type. If the static type is an effectively final class then this yields an
- // exact dynamic type.
- if (dynamicType.isNotNullType()) {
- dynamicType =
- DynamicType.create(appView, field.getType().toNonNullTypeElement(appView));
- }
+ DynamicType dynamicType =
+ field
+ .getOptimizationInfo()
+ .getDynamicType()
+ .uncanonicalizeNotNullType(appView, field.getType());
if (dynamicType.isExactClassType()) {
valueTypes.put(ordinal, dynamicType.getExactClassType().getClassType());
} else {
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/enums/EnumValueOptimizer.java b/src/main/java/com/android/tools/r8/ir/optimize/enums/EnumValueOptimizer.java
index 9f3a782..4479b16 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/enums/EnumValueOptimizer.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/enums/EnumValueOptimizer.java
@@ -151,7 +151,11 @@
// Since the value is a single field value, the type should be exact.
assert abstractValue.isSingleFieldValue();
- ClassTypeElement enumFieldType = optimizationInfo.getDynamicType().getExactClassType();
+ ClassTypeElement enumFieldType =
+ optimizationInfo
+ .getDynamicType()
+ .uncanonicalizeNotNullType(appView(), field.getType())
+ .getExactClassType();
if (enumFieldType == null) {
assert false : "Expected to have an exact dynamic type for enum instance";
continue;
@@ -188,10 +192,9 @@
@Override
protected boolean shouldRewriteCode(IRCode code, MethodProcessor methodProcessor) {
- if (!options.enableEnumValueOptimization || !appView.hasLiveness()) {
- return false;
- }
- return code.metadata().mayHaveInvokeMethodWithReceiver();
+ return appView.hasLiveness()
+ && options.enableEnumValueOptimization
+ && code.metadata().mayHaveInvokeMethodWithReceiver();
}
/**