Merge "Virtualize some methods from TypeLatticeElement"
diff --git a/src/main/java/com/android/tools/r8/cf/TypeVerificationHelper.java b/src/main/java/com/android/tools/r8/cf/TypeVerificationHelper.java
index d640a30..83f2e8e 100644
--- a/src/main/java/com/android/tools/r8/cf/TypeVerificationHelper.java
+++ b/src/main/java/com/android/tools/r8/cf/TypeVerificationHelper.java
@@ -52,23 +52,23 @@
return types.iterator().next();
}
Iterator<DexType> iterator = types.iterator();
- TypeLatticeElement join = getLatticeElement(iterator.next());
+ TypeLatticeElement result = getLatticeElement(iterator.next());
while (iterator.hasNext()) {
- join = TypeLatticeElement.join(appInfo, join, getLatticeElement(iterator.next()));
+ result = result.join(getLatticeElement(iterator.next()), appInfo);
}
// All types are reference types so the join is either a class or an array.
- if (join.isClassType()) {
- return join.asClassTypeLatticeElement().getClassType();
- } else if (join.isArrayType()) {
- return join.asArrayTypeLatticeElement().getArrayType();
+ if (result.isClassType()) {
+ return result.asClassTypeLatticeElement().getClassType();
+ } else if (result.isArrayType()) {
+ return result.asArrayTypeLatticeElement().getArrayType();
}
- throw new CompilationError("Unexpected join " + join + " of types: " +
+ throw new CompilationError("Unexpected join " + result + " of types: " +
String.join(", ",
types.stream().map(DexType::toSourceString).collect(Collectors.toList())));
}
private TypeLatticeElement getLatticeElement(DexType type) {
- return TypeLatticeElement.fromDexType(type, appInfo, true);
+ return TypeLatticeElement.fromDexType(type, true, appInfo);
}
public Map<Value, DexType> computeVerificationTypes() {
diff --git a/src/main/java/com/android/tools/r8/ir/analysis/type/ArrayTypeLatticeElement.java b/src/main/java/com/android/tools/r8/ir/analysis/type/ArrayTypeLatticeElement.java
index 6b368b3..128e640 100644
--- a/src/main/java/com/android/tools/r8/ir/analysis/type/ArrayTypeLatticeElement.java
+++ b/src/main/java/com/android/tools/r8/ir/analysis/type/ArrayTypeLatticeElement.java
@@ -52,7 +52,7 @@
@Override
public TypeLatticeElement arrayGet(AppInfo appInfo) {
- return fromDexType(getArrayElementType(appInfo.dexItemFactory), appInfo, true);
+ return fromDexType(getArrayElementType(appInfo.dexItemFactory), true, appInfo);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/ir/analysis/type/TypeAnalysis.java b/src/main/java/com/android/tools/r8/ir/analysis/type/TypeAnalysis.java
index b8988c1..9711079 100644
--- a/src/main/java/com/android/tools/r8/ir/analysis/type/TypeAnalysis.java
+++ b/src/main/java/com/android/tools/r8/ir/analysis/type/TypeAnalysis.java
@@ -84,12 +84,12 @@
TypeLatticeElement derived;
if (argumentsSeen < 0) {
// Receiver
- derived = fromDexType(encodedMethod.method.holder, appInfo,
+ derived = fromDexType(encodedMethod.method.holder,
// Now we try inlining even when the receiver could be null.
- encodedMethod != context);
+ encodedMethod != context, appInfo);
} else {
DexType argType = encodedMethod.method.proto.parameters.values[argumentsSeen];
- derived = fromDexType(argType, appInfo, true);
+ derived = fromDexType(argType, true, appInfo);
}
argumentsSeen++;
updateTypeOfValue(outValue, derived);
@@ -149,8 +149,7 @@
private TypeLatticeElement computePhiType(Phi phi) {
// Type of phi(v1, v2, ..., vn) is the least upper bound of all those n operands.
- return TypeLatticeElement.join(
- appInfo, phi.getOperands().stream().map(Value::getTypeLattice));
+ return TypeLatticeElement.join(phi.getOperands().stream().map(Value::getTypeLattice), appInfo);
}
public static DexType getRefinedReceiverType(
diff --git a/src/main/java/com/android/tools/r8/ir/analysis/type/TypeLatticeElement.java b/src/main/java/com/android/tools/r8/ir/analysis/type/TypeLatticeElement.java
index a09039c..e0a5707 100644
--- a/src/main/java/com/android/tools/r8/ir/analysis/type/TypeLatticeElement.java
+++ b/src/main/java/com/android/tools/r8/ir/analysis/type/TypeLatticeElement.java
@@ -81,57 +81,55 @@
/**
* Computes the least upper bound of the current and the other elements.
*
+ * @param other {@link TypeLatticeElement} to join.
* @param appInfo {@link AppInfo}.
- * @param l1 {@link TypeLatticeElement} to join.
- * @param l2 {@link TypeLatticeElement} to join.
- * @return {@link TypeLatticeElement}, a least upper bound of {@param l1} and {@param l2}.
+ * @return {@link TypeLatticeElement}, a least upper bound of {@param this} and {@param other}.
*/
- public static TypeLatticeElement join(
- AppInfo appInfo, TypeLatticeElement l1, TypeLatticeElement l2) {
- if (l1.isBottom()) {
- return l2;
+ public TypeLatticeElement join(TypeLatticeElement other, AppInfo appInfo) {
+ if (isBottom()) {
+ return other;
}
- if (l2.isBottom()) {
- return l1;
+ if (other.isBottom()) {
+ return this;
}
- if (l1.isTop() || l2.isTop()) {
+ if (isTop() || other.isTop()) {
return TOP;
}
- if (l1.isNull()) {
- return l2.asNullable();
+ if (isNull()) {
+ return other.asNullable();
}
- if (l2.isNull()) {
- return l1.asNullable();
+ if (other.isNull()) {
+ return asNullable();
}
- if (l1.isPrimitive()) {
- return l2.isPrimitive()
+ if (isPrimitive()) {
+ return other.isPrimitive()
? PrimitiveTypeLatticeElement.join(
- l1.asPrimitiveTypeLatticeElement(), l2.asPrimitiveTypeLatticeElement())
+ asPrimitiveTypeLatticeElement(), other.asPrimitiveTypeLatticeElement())
: TOP;
}
- if (l2.isPrimitive()) {
- // By the above case, !(l1.isPrimitive())
+ if (other.isPrimitive()) {
+ // By the above case, !(isPrimitive())
return TOP;
}
- // From now on, l1 and l2 are reference types, but might be imprecise yet.
- assert l1.isReference() && l2.isReference();
- if (!l1.isPreciseType() || !l2.isPreciseType()) {
- if (l1.isReferenceInstance()) {
- return l1;
+ // From now on, this and other are reference types, but might be imprecise yet.
+ assert isReference() && other.isReference();
+ if (!isPreciseType() || !other.isPreciseType()) {
+ if (isReferenceInstance()) {
+ return this;
}
- assert l2.isReferenceInstance();
- return l2;
+ assert other.isReferenceInstance();
+ return other;
}
- // From now on, l1 and l2 are precise reference types, i.e., either ArrayType or ClassType.
- boolean isNullable = l1.isNullable() || l2.isNullable();
- if (l1.getClass() != l2.getClass()) {
+ // From now on, this and other are precise reference types, i.e., either ArrayType or ClassType.
+ boolean isNullable = isNullable() || other.isNullable();
+ if (getClass() != other.getClass()) {
return objectClassType(appInfo, isNullable);
}
- // From now on, l1.getClass() == l2.getClass()
- if (l1.isArrayType()) {
- assert l2.isArrayType();
- ArrayTypeLatticeElement a1 = l1.asArrayTypeLatticeElement();
- ArrayTypeLatticeElement a2 = l2.asArrayTypeLatticeElement();
+ // From now on, getClass() == other.getClass()
+ if (isArrayType()) {
+ assert other.isArrayType();
+ ArrayTypeLatticeElement a1 = asArrayTypeLatticeElement();
+ ArrayTypeLatticeElement a2 = other.asArrayTypeLatticeElement();
// Identical types are the same elements
if (a1.getArrayType() == a2.getArrayType()) {
return a1.isNullable() ? a1 : a2;
@@ -166,10 +164,10 @@
DexType arrayTypeLub = appInfo.dexItemFactory.createArrayType(a1Nesting, lub);
return new ArrayTypeLatticeElement(arrayTypeLub, isNullable);
}
- if (l1.isClassType()) {
- assert l2.isClassType();
- ClassTypeLatticeElement c1 = l1.asClassTypeLatticeElement();
- ClassTypeLatticeElement c2 = l2.asClassTypeLatticeElement();
+ if (isClassType()) {
+ assert other.isClassType();
+ ClassTypeLatticeElement c1 = asClassTypeLatticeElement();
+ ClassTypeLatticeElement c2 = other.asClassTypeLatticeElement();
DexType lubType =
c1.getClassType().computeLeastUpperBoundOfClasses(appInfo, c2.getClassType());
return new ClassTypeLatticeElement(lubType, isNullable,
@@ -258,47 +256,43 @@
}
public static BinaryOperator<TypeLatticeElement> joiner(AppInfo appInfo) {
- return (l1, l2) -> join(appInfo, l1, l2);
+ return (l1, l2) -> l1.join(l2, appInfo);
}
- public static TypeLatticeElement join(AppInfo appInfo, Stream<TypeLatticeElement> types) {
+ public static TypeLatticeElement join(Stream<TypeLatticeElement> types, AppInfo appInfo) {
BinaryOperator<TypeLatticeElement> joiner = joiner(appInfo);
return types.reduce(BottomTypeLatticeElement.getInstance(), joiner, joiner);
}
public static TypeLatticeElement join(
- AppInfo appInfo, Stream<DexType> types, boolean isNullable) {
- return join(appInfo, types.map(t -> fromDexType(t, appInfo, isNullable)));
+ Stream<DexType> types, boolean isNullable, AppInfo appInfo) {
+ return join(types.map(t -> fromDexType(t, isNullable, appInfo)), appInfo);
}
/**
* Determines the strict partial order of the given {@link TypeLatticeElement}s.
*
+ * @param other expected to be *strictly* bigger than {@param this}
* @param appInfo {@link AppInfo} to compute the least upper bound of {@link TypeLatticeElement}
- * @param l1 subject {@link TypeLatticeElement}
- * @param l2 expected to be *strict* bigger than {@param l1}
- * @return {@code true} if {@param l1} is strictly less than {@param l2}.
+ * @return {@code true} if {@param this} is strictly less than {@param other}.
*/
- public static boolean strictlyLessThan(
- AppInfo appInfo, TypeLatticeElement l1, TypeLatticeElement l2) {
- if (l1.equals(l2)) {
+ public boolean strictlyLessThan(TypeLatticeElement other, AppInfo appInfo) {
+ if (equals(other)) {
return false;
}
- TypeLatticeElement lub = join(appInfo, Stream.of(l1, l2));
- return !l1.equals(lub) && l2.equals(lub);
+ TypeLatticeElement lub = join(other, appInfo);
+ return !equals(lub) && other.equals(lub);
}
/**
* Determines the partial order of the given {@link TypeLatticeElement}s.
*
+ * @param other expected to be bigger than or equal to {@param this}
* @param appInfo {@link AppInfo} to compute the least upper bound of {@link TypeLatticeElement}
- * @param l1 subject {@link TypeLatticeElement}
- * @param l2 expected to be bigger than or equal to {@param l1}
- * @return {@code true} if {@param l1} is less than or equal to {@param l2}.
+ * @return {@code true} if {@param this} is less than or equal to {@param other}.
*/
- public static boolean lessThanOrEqual(
- AppInfo appInfo, TypeLatticeElement l1, TypeLatticeElement l2) {
- return l1.equals(l2) || strictlyLessThan(appInfo, l1, l2);
+ public boolean lessThanOrEqual(TypeLatticeElement other, AppInfo appInfo) {
+ return equals(other) || strictlyLessThan(other, appInfo);
}
/**
@@ -404,14 +398,14 @@
}
public static TypeLatticeElement classClassType(AppInfo appInfo) {
- return fromDexType(appInfo.dexItemFactory.classType, appInfo, false);
+ return fromDexType(appInfo.dexItemFactory.classType, false, appInfo);
}
public static TypeLatticeElement stringClassType(AppInfo appInfo) {
- return fromDexType(appInfo.dexItemFactory.stringType, appInfo, false);
+ return fromDexType(appInfo.dexItemFactory.stringType, false, appInfo);
}
- public static TypeLatticeElement fromDexType(DexType type, AppInfo appInfo, boolean isNullable) {
+ public static TypeLatticeElement fromDexType(DexType type, boolean isNullable, AppInfo appInfo) {
if (type == DexItemFactory.nullValueType) {
return NULL;
}
@@ -483,8 +477,8 @@
}
public TypeLatticeElement checkCast(AppInfo appInfo, DexType castType) {
- TypeLatticeElement castTypeLattice = fromDexType(castType, appInfo, isNullable());
- if (lessThanOrEqual(appInfo, this, castTypeLattice)) {
+ TypeLatticeElement castTypeLattice = fromDexType(castType, isNullable(), appInfo);
+ if (lessThanOrEqual(castTypeLattice, appInfo)) {
return this;
}
return castTypeLattice;
diff --git a/src/main/java/com/android/tools/r8/ir/code/BasicBlockInstructionIterator.java b/src/main/java/com/android/tools/r8/ir/code/BasicBlockInstructionIterator.java
index 7caaff9..705bb97 100644
--- a/src/main/java/com/android/tools/r8/ir/code/BasicBlockInstructionIterator.java
+++ b/src/main/java/com/android/tools/r8/ir/code/BasicBlockInstructionIterator.java
@@ -366,7 +366,7 @@
if (downcast != null) {
Value receiver = invoke.inValues().get(0);
TypeLatticeElement castTypeLattice = TypeLatticeElement.fromDexType(
- downcast, appInfo, receiver.getTypeLattice().isNullable());
+ downcast, receiver.getTypeLattice().isNullable(), appInfo);
CheckCast castInstruction =
new CheckCast(code.createValue(castTypeLattice), receiver, downcast);
castInstruction.setPosition(invoke.getPosition());
diff --git a/src/main/java/com/android/tools/r8/ir/code/CheckCast.java b/src/main/java/com/android/tools/r8/ir/code/CheckCast.java
index 8d461bd..03d718f 100644
--- a/src/main/java/com/android/tools/r8/ir/code/CheckCast.java
+++ b/src/main/java/com/android/tools/r8/ir/code/CheckCast.java
@@ -133,12 +133,12 @@
TypeLatticeElement outType = outValue().getTypeLattice();
TypeLatticeElement castType =
- TypeLatticeElement.fromDexType(getType(), appInfo, inType.isNullable());
+ TypeLatticeElement.fromDexType(getType(), inType.isNullable(), appInfo);
- if (TypeLatticeElement.lessThanOrEqual(appInfo, inType, castType)) {
+ if (inType.lessThanOrEqual(castType, appInfo)) {
// Cast can be removed. Check that it is sound to replace all users of the out-value by the
// in-value.
- assert TypeLatticeElement.lessThanOrEqual(appInfo, inType, outType);
+ assert inType.lessThanOrEqual(outType, appInfo);
// TODO(b/72693244): Consider checking equivalence. This requires that the types are always
// as precise as possible, though, meaning that almost all changes to the IR must be followed
diff --git a/src/main/java/com/android/tools/r8/ir/code/ConstClass.java b/src/main/java/com/android/tools/r8/ir/code/ConstClass.java
index 401656c..7aa9a62 100644
--- a/src/main/java/com/android/tools/r8/ir/code/ConstClass.java
+++ b/src/main/java/com/android/tools/r8/ir/code/ConstClass.java
@@ -105,7 +105,7 @@
@Override
public TypeLatticeElement evaluate(AppInfo appInfo) {
- return TypeLatticeElement.fromDexType(appInfo.dexItemFactory.classType, appInfo, false);
+ return TypeLatticeElement.fromDexType(appInfo.dexItemFactory.classType, false, appInfo);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/ir/code/ConstMethodHandle.java b/src/main/java/com/android/tools/r8/ir/code/ConstMethodHandle.java
index ffc4359..95aa81c 100644
--- a/src/main/java/com/android/tools/r8/ir/code/ConstMethodHandle.java
+++ b/src/main/java/com/android/tools/r8/ir/code/ConstMethodHandle.java
@@ -91,7 +91,7 @@
@Override
public TypeLatticeElement evaluate(AppInfo appInfo) {
- return TypeLatticeElement.fromDexType(appInfo.dexItemFactory.methodHandleType, appInfo, false);
+ return TypeLatticeElement.fromDexType(appInfo.dexItemFactory.methodHandleType, false, appInfo);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/ir/code/ConstMethodType.java b/src/main/java/com/android/tools/r8/ir/code/ConstMethodType.java
index 81d7b28..d258839 100644
--- a/src/main/java/com/android/tools/r8/ir/code/ConstMethodType.java
+++ b/src/main/java/com/android/tools/r8/ir/code/ConstMethodType.java
@@ -91,7 +91,7 @@
@Override
public TypeLatticeElement evaluate(AppInfo appInfo) {
- return TypeLatticeElement.fromDexType(appInfo.dexItemFactory.methodTypeType, appInfo, false);
+ return TypeLatticeElement.fromDexType(appInfo.dexItemFactory.methodTypeType, false, appInfo);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/ir/code/ConstString.java b/src/main/java/com/android/tools/r8/ir/code/ConstString.java
index 85fd784..e05a55f 100644
--- a/src/main/java/com/android/tools/r8/ir/code/ConstString.java
+++ b/src/main/java/com/android/tools/r8/ir/code/ConstString.java
@@ -133,6 +133,6 @@
@Override
public TypeLatticeElement evaluate(AppInfo appInfo) {
- return TypeLatticeElement.fromDexType(appInfo.dexItemFactory.stringType, appInfo, false);
+ return TypeLatticeElement.fromDexType(appInfo.dexItemFactory.stringType, false, appInfo);
}
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/InstanceGet.java b/src/main/java/com/android/tools/r8/ir/code/InstanceGet.java
index 0c8c372..3d30b82 100644
--- a/src/main/java/com/android/tools/r8/ir/code/InstanceGet.java
+++ b/src/main/java/com/android/tools/r8/ir/code/InstanceGet.java
@@ -135,7 +135,7 @@
@Override
public TypeLatticeElement evaluate(AppInfo appInfo) {
- return TypeLatticeElement.fromDexType(field.type, appInfo, true);
+ return TypeLatticeElement.fromDexType(field.type, true, appInfo);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/ir/code/Invoke.java b/src/main/java/com/android/tools/r8/ir/code/Invoke.java
index b755336..468f3d05 100644
--- a/src/main/java/com/android/tools/r8/ir/code/Invoke.java
+++ b/src/main/java/com/android/tools/r8/ir/code/Invoke.java
@@ -280,6 +280,6 @@
if (returnType.isVoidType()) {
throw new Unreachable("void methods have no type.");
}
- return TypeLatticeElement.fromDexType(returnType, appInfo, true);
+ return TypeLatticeElement.fromDexType(returnType, true, appInfo);
}
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/MoveException.java b/src/main/java/com/android/tools/r8/ir/code/MoveException.java
index 562b33d..15ab6b0 100644
--- a/src/main/java/com/android/tools/r8/ir/code/MoveException.java
+++ b/src/main/java/com/android/tools/r8/ir/code/MoveException.java
@@ -105,7 +105,7 @@
if (targets.get(i) == currentBlock) {
DexType guard = guards.get(i);
exceptionTypes.add(
- guard == dexItemFactory.catchAllType
+ guard == DexItemFactory.catchAllType
? dexItemFactory.throwableType
: guard);
}
@@ -122,8 +122,6 @@
@Override
public TypeLatticeElement evaluate(AppInfo appInfo) {
Set<DexType> exceptionTypes = collectExceptionTypes(getBlock(), appInfo.dexItemFactory);
- return TypeLatticeElement.join(
- appInfo,
- exceptionTypes.stream().map(t -> TypeLatticeElement.fromDexType(t, appInfo, false)));
+ return TypeLatticeElement.join(exceptionTypes.stream(), false, appInfo);
}
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/NewInstance.java b/src/main/java/com/android/tools/r8/ir/code/NewInstance.java
index 29b263f..18a60d4 100644
--- a/src/main/java/com/android/tools/r8/ir/code/NewInstance.java
+++ b/src/main/java/com/android/tools/r8/ir/code/NewInstance.java
@@ -107,7 +107,7 @@
@Override
public TypeLatticeElement evaluate(AppInfo appInfo) {
- return TypeLatticeElement.fromDexType(clazz, appInfo, false);
+ return TypeLatticeElement.fromDexType(clazz, false, appInfo);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/ir/code/StaticGet.java b/src/main/java/com/android/tools/r8/ir/code/StaticGet.java
index 9ef7ed4..e767246 100644
--- a/src/main/java/com/android/tools/r8/ir/code/StaticGet.java
+++ b/src/main/java/com/android/tools/r8/ir/code/StaticGet.java
@@ -145,7 +145,7 @@
@Override
public TypeLatticeElement evaluate(AppInfo appInfo) {
- return TypeLatticeElement.fromDexType(field.type, appInfo, true);
+ return TypeLatticeElement.fromDexType(field.type, true, appInfo);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java b/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
index b471e12..a643947 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
@@ -680,8 +680,8 @@
Position position = source.getCanonicalDebugPositionAtOffset(moveExceptionItem.targetOffset);
if (moveExceptionDest >= 0) {
Set<DexType> exceptionTypes = MoveException.collectExceptionTypes(currentBlock, getFactory());
- TypeLatticeElement typeLattice = TypeLatticeElement.join(appInfo,
- exceptionTypes.stream().map(t -> TypeLatticeElement.fromDexType(t, appInfo, false)));
+ TypeLatticeElement typeLattice =
+ TypeLatticeElement.join(exceptionTypes.stream(), false, appInfo);
Value out = writeRegister(moveExceptionDest, typeLattice, ThrowingInfo.NO_THROW, null);
MoveException moveException = new MoveException(out);
moveException.setPosition(position);
@@ -731,7 +731,7 @@
DebugLocalInfo local = getOutgoingLocal(register);
// TODO(b/72693244): Update nullability if this is for building inlinee's IR.
TypeLatticeElement receiver =
- TypeLatticeElement.fromDexType(method.method.getHolder(), appInfo, false);
+ TypeLatticeElement.fromDexType(method.method.getHolder(), false, appInfo);
Value value = writeRegister(register, receiver, ThrowingInfo.NO_THROW, local);
addInstruction(new Argument(value));
value.markAsThis();
@@ -872,7 +872,7 @@
public void addCheckCast(int value, DexType type) {
Value in = readRegister(value, ValueType.OBJECT);
TypeLatticeElement castTypeLattice =
- TypeLatticeElement.fromDexType(type, appInfo, in.getTypeLattice().isNullable());
+ TypeLatticeElement.fromDexType(type, in.getTypeLattice().isNullable(), appInfo);
Value out = writeRegister(value, castTypeLattice, ThrowingInfo.CAN_THROW);
CheckCast instruction = new CheckCast(out, in, type);
assert instruction.instructionTypeCanThrow();
@@ -931,7 +931,7 @@
null /* sourceString */);
}
TypeLatticeElement typeLattice =
- TypeLatticeElement.fromDexType(appInfo.dexItemFactory.methodHandleType, appInfo, false);
+ TypeLatticeElement.fromDexType(appInfo.dexItemFactory.methodHandleType, false, appInfo);
Value out = writeRegister(dest, typeLattice, ThrowingInfo.CAN_THROW);
ConstMethodHandle instruction = new ConstMethodHandle(out, methodHandle);
add(instruction);
@@ -945,7 +945,7 @@
null /* sourceString */);
}
TypeLatticeElement typeLattice =
- TypeLatticeElement.fromDexType(appInfo.dexItemFactory.methodTypeType, appInfo, false);
+ TypeLatticeElement.fromDexType(appInfo.dexItemFactory.methodTypeType, false, appInfo);
Value out = writeRegister(dest, typeLattice, ThrowingInfo.CAN_THROW);
ConstMethodType instruction = new ConstMethodType(out, methodType);
add(instruction);
@@ -1104,7 +1104,7 @@
MemberType type = MemberType.fromDexType(field.type);
Value in = readRegister(object, ValueType.OBJECT);
Value out = writeRegister(
- dest, TypeLatticeElement.fromDexType(field.type, appInfo, true), ThrowingInfo.CAN_THROW);
+ dest, TypeLatticeElement.fromDexType(field.type, true, appInfo), ThrowingInfo.CAN_THROW);
out.setKnownToBeBoolean(type == MemberType.BOOLEAN);
InstanceGet instruction = new InstanceGet(type, out, in, field);
assert instruction.instructionTypeCanThrow();
@@ -1415,7 +1415,7 @@
public void addNewArrayEmpty(int dest, int size, DexType type) {
assert type.isArrayType();
Value in = readRegister(size, ValueType.INT);
- TypeLatticeElement arrayTypeLattice = TypeLatticeElement.fromDexType(type, appInfo, false);
+ TypeLatticeElement arrayTypeLattice = TypeLatticeElement.fromDexType(type, false, appInfo);
Value out = writeRegister(dest, arrayTypeLattice, ThrowingInfo.CAN_THROW);
NewArrayEmpty instruction = new NewArrayEmpty(out, in, type);
assert instruction.instructionTypeCanThrow();
@@ -1427,7 +1427,7 @@
}
public void addNewInstance(int dest, DexType type) {
- TypeLatticeElement instanceType = TypeLatticeElement.fromDexType(type, appInfo, false);
+ TypeLatticeElement instanceType = TypeLatticeElement.fromDexType(type, false, appInfo);
Value out = writeRegister(dest, instanceType, ThrowingInfo.CAN_THROW);
NewInstance instruction = new NewInstance(type, out);
assert instruction.instructionTypeCanThrow();
@@ -1455,7 +1455,7 @@
public void addStaticGet(int dest, DexField field) {
MemberType type = MemberType.fromDexType(field.type);
Value out = writeRegister(
- dest, TypeLatticeElement.fromDexType(field.type, appInfo, true), ThrowingInfo.CAN_THROW);
+ dest, TypeLatticeElement.fromDexType(field.type, true, appInfo), ThrowingInfo.CAN_THROW);
out.setKnownToBeBoolean(type == MemberType.BOOLEAN);
StaticGet instruction = new StaticGet(type, out, field);
assert instruction.instructionTypeCanThrow();
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/LambdaRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/LambdaRewriter.java
index 129ed58..22113f8 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/LambdaRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/LambdaRewriter.java
@@ -277,7 +277,7 @@
if (lambdaInstanceValue == null) {
// The out value might be empty in case it was optimized out.
lambdaInstanceValue = code.createValue(
- TypeLatticeElement.fromDexType(lambdaClass.type, appInfo, true));
+ TypeLatticeElement.fromDexType(lambdaClass.type, true, appInfo));
}
// For stateless lambdas we replace InvokeCustom instruction with StaticGet
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/StringConcatRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/StringConcatRewriter.java
index c805494..1b13398 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/StringConcatRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/StringConcatRewriter.java
@@ -337,7 +337,7 @@
// new-instance v0, StringBuilder
TypeLatticeElement stringBuilderTypeLattice =
- TypeLatticeElement.fromDexType(factory.stringBuilderType, appInfo, false);
+ TypeLatticeElement.fromDexType(factory.stringBuilderType, false, appInfo);
Value sbInstance = code.createValue(stringBuilderTypeLattice);
appendInstruction(new NewInstance(factory.stringBuilderType, sbInstance));
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
index f8b85de..93df273 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
@@ -297,7 +297,7 @@
BasicBlock rethrowBlock = BasicBlock.createRethrowBlock(
code,
lastSelfRecursiveCall.getPosition(),
- TypeLatticeElement.fromDexType(guard, appInfo, true));
+ TypeLatticeElement.fromDexType(guard, true, appInfo));
code.blocks.add(rethrowBlock);
// Add catch handler to the block containing the last recursive call.
newBlock.addCatchHandler(rethrowBlock, guard);
@@ -1660,11 +1660,11 @@
if (inTypeLattice.isPreciseType() || inTypeLattice.isNull()) {
TypeLatticeElement outTypeLattice = outValue.getTypeLattice();
TypeLatticeElement castTypeLattice =
- TypeLatticeElement.fromDexType(castType, appInfo, inTypeLattice.isNullable());
+ TypeLatticeElement.fromDexType(castType, inTypeLattice.isNullable(), appInfo);
assert inTypeLattice.nullElement().lessThanOrEqual(outTypeLattice.nullElement());
- if (TypeLatticeElement.lessThanOrEqual(appInfo, inTypeLattice, castTypeLattice)) {
+ if (inTypeLattice.lessThanOrEqual(castTypeLattice, appInfo)) {
// 1) Trivial cast.
// A a = ...
// A a' = (A) a;
@@ -1672,7 +1672,7 @@
// A < B
// A a = ...
// B b = (B) a;
- assert TypeLatticeElement.lessThanOrEqual(appInfo, inTypeLattice, outTypeLattice);
+ assert inTypeLattice.lessThanOrEqual(outTypeLattice, appInfo);
needToRemoveTrivialPhis = needToRemoveTrivialPhis || outValue.numberOfPhiUsers() != 0;
removeOrReplaceByDebugLocalWrite(checkCast, it, inValue, outValue);
} else {
@@ -3013,7 +3013,7 @@
DexType javaLangSystemType = dexItemFactory.createType("Ljava/lang/System;");
DexType javaIoPrintStreamType = dexItemFactory.createType("Ljava/io/PrintStream;");
Value out = code.createValue(
- TypeLatticeElement.fromDexType(javaIoPrintStreamType, appInfo, false));
+ TypeLatticeElement.fromDexType(javaIoPrintStreamType, false, appInfo));
DexProto proto = dexItemFactory.createProto(dexItemFactory.voidType, dexItemFactory.objectType);
DexMethod print = dexItemFactory.createMethod(javaIoPrintStreamType, proto, "print");
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/Devirtualizer.java b/src/main/java/com/android/tools/r8/ir/optimize/Devirtualizer.java
index 37cfb44..e7b6ca8 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/Devirtualizer.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/Devirtualizer.java
@@ -110,14 +110,13 @@
Value receiver = invoke.getReceiver();
TypeLatticeElement receiverTypeLattice = receiver.getTypeLattice();
TypeLatticeElement castTypeLattice =
- TypeLatticeElement.fromDexType(holderType, appInfo, receiverTypeLattice.isNullable());
+ TypeLatticeElement.fromDexType(holderType, receiverTypeLattice.isNullable(), appInfo);
// Avoid adding trivial cast and up-cast.
// We should not use strictlyLessThan(castType, receiverType), which detects downcast,
// due to side-casts, e.g., A (unused) < I, B < I, and cast from A to B.
// TODO(b/72693244): Soon, there won't be a value with imprecise type at this point.
if (!receiverTypeLattice.isPreciseType()
- || !TypeLatticeElement.lessThanOrEqual(
- appInfo, receiverTypeLattice, castTypeLattice)) {
+ || !receiverTypeLattice.lessThanOrEqual(castTypeLattice, appInfo)) {
Value newReceiver = null;
// If this value is ever downcast'ed to the same holder type before, and that casted
// value is safely accessible, i.e., the current line is dominated by that cast, use it.
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/lambda/kotlin/KotlinLambdaGroupCodeStrategy.java b/src/main/java/com/android/tools/r8/ir/optimize/lambda/kotlin/KotlinLambdaGroupCodeStrategy.java
index 538d7be..51da91d 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/lambda/kotlin/KotlinLambdaGroupCodeStrategy.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/lambda/kotlin/KotlinLambdaGroupCodeStrategy.java
@@ -115,7 +115,7 @@
NewInstance patchedNewInstance = new NewInstance(
group.getGroupClassType(),
context.code.createValue(
- TypeLatticeElement.fromDexType(newInstance.clazz, context.appInfo, false)));
+ TypeLatticeElement.fromDexType(newInstance.clazz, false, context.appInfo)));
context.instructions().replaceCurrentInstruction(patchedNewInstance);
}
@@ -160,7 +160,7 @@
// Since all captured values of non-primitive types are stored in fields of type
// java.lang.Object, we need to cast them to appropriate type to satisfy the verifier.
TypeLatticeElement castTypeLattice =
- TypeLatticeElement.fromDexType(fieldType, context.appInfo, false);
+ TypeLatticeElement.fromDexType(fieldType, false, context.appInfo);
Value newValue = context.code.createValue(castTypeLattice, newInstanceGet.getLocalInfo());
newInstanceGet.outValue().replaceUsers(newValue);
CheckCast cast = new CheckCast(newValue, newInstanceGet.outValue(), fieldType);
@@ -187,7 +187,7 @@
new StaticGet(
staticGet.getType(),
context.code.createValue(
- TypeLatticeElement.fromDexType(staticGet.getField().type, context.appInfo, true)),
+ TypeLatticeElement.fromDexType(staticGet.getField().type, true, context.appInfo)),
mapSingletonInstanceField(context.factory, staticGet.getField())));
}
@@ -222,7 +222,7 @@
private Value createValueForType(CodeProcessor context, DexType returnType) {
return returnType == context.factory.voidType ? null :
context.code.createValue(
- TypeLatticeElement.fromDexType(returnType, context.appInfo, true));
+ TypeLatticeElement.fromDexType(returnType, true, context.appInfo));
}
private List<Value> mapInitializerArgs(
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/staticizer/StaticizingProcessor.java b/src/main/java/com/android/tools/r8/ir/optimize/staticizer/StaticizingProcessor.java
index 669baf9..ac3a8af 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/staticizer/StaticizingProcessor.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/staticizer/StaticizingProcessor.java
@@ -273,7 +273,7 @@
new StaticGet(
MemberType.fromDexType(field.type),
code.createValue(
- TypeLatticeElement.fromDexType(field.type, classStaticizer.appInfo, true),
+ TypeLatticeElement.fromDexType(field.type, true, classStaticizer.appInfo),
outValue.getLocalInfo()),
field
)
@@ -303,7 +303,7 @@
Value newOutValue = method.proto.returnType.isVoidType() ? null
: code.createValue(
TypeLatticeElement.fromDexType(
- method.proto.returnType, classStaticizer.appInfo, true),
+ method.proto.returnType, true, classStaticizer.appInfo),
outValue == null ? null : outValue.getLocalInfo());
it.replaceCurrentInstruction(
new InvokeStatic(newMethod, newOutValue, invoke.inValues()));
diff --git a/src/test/java/com/android/tools/r8/ir/analysis/type/NullabilityTest.java b/src/test/java/com/android/tools/r8/ir/analysis/type/NullabilityTest.java
index 109a6cb..bd0f8fb 100644
--- a/src/test/java/com/android/tools/r8/ir/analysis/type/NullabilityTest.java
+++ b/src/test/java/com/android/tools/r8/ir/analysis/type/NullabilityTest.java
@@ -120,9 +120,9 @@
DexType mainClass = appInfo.dexItemFactory.createType(
DescriptorUtils.javaTypeToDescriptor(NonNullAfterInvoke.class.getCanonicalName()));
Map<Class<? extends Instruction>, TypeLatticeElement> expectedLattices = ImmutableMap.of(
- InvokeVirtual.class, fromDexType(appInfo.dexItemFactory.stringType, appInfo, true),
- NonNull.class, fromDexType(appInfo.dexItemFactory.stringType, appInfo, false),
- NewInstance.class, fromDexType(assertionErrorType, appInfo, false));
+ InvokeVirtual.class, fromDexType(appInfo.dexItemFactory.stringType, true, appInfo),
+ NonNull.class, fromDexType(appInfo.dexItemFactory.stringType, false, appInfo),
+ NewInstance.class, fromDexType(assertionErrorType, false, appInfo));
forEachOutValue(irCode, (v, l) -> verifyClassTypeLattice(expectedLattices, mainClass, v, l));
});
}
@@ -136,9 +136,9 @@
DexType mainClass = appInfo.dexItemFactory.createType(
DescriptorUtils.javaTypeToDescriptor(NonNullAfterInvoke.class.getCanonicalName()));
Map<Class<? extends Instruction>, TypeLatticeElement> expectedLattices = ImmutableMap.of(
- InvokeVirtual.class, fromDexType(appInfo.dexItemFactory.stringType, appInfo, true),
- NonNull.class, fromDexType(appInfo.dexItemFactory.stringType, appInfo, false),
- NewInstance.class, fromDexType(assertionErrorType, appInfo, false));
+ InvokeVirtual.class, fromDexType(appInfo.dexItemFactory.stringType, true, appInfo),
+ NonNull.class, fromDexType(appInfo.dexItemFactory.stringType, false, appInfo),
+ NewInstance.class, fromDexType(assertionErrorType, false, appInfo));
forEachOutValue(irCode, (v, l) -> verifyClassTypeLattice(expectedLattices, mainClass, v, l));
});
}
@@ -153,8 +153,8 @@
DescriptorUtils.javaTypeToDescriptor(NonNullAfterArrayAccess.class.getCanonicalName()));
Map<Class<? extends Instruction>, TypeLatticeElement> expectedLattices = ImmutableMap.of(
// An element inside a non-null array could be null.
- ArrayGet.class, fromDexType(appInfo.dexItemFactory.stringType, appInfo, true),
- NewInstance.class, fromDexType(assertionErrorType, appInfo, false));
+ ArrayGet.class, fromDexType(appInfo.dexItemFactory.stringType, true, appInfo),
+ NewInstance.class, fromDexType(assertionErrorType, false, appInfo));
forEachOutValue(irCode, (v, l) -> {
if (l.isArrayType()) {
ArrayTypeLatticeElement lattice = l.asArrayTypeLatticeElement();
@@ -179,8 +179,8 @@
DescriptorUtils.javaTypeToDescriptor(NonNullAfterArrayAccess.class.getCanonicalName()));
Map<Class<? extends Instruction>, TypeLatticeElement> expectedLattices = ImmutableMap.of(
// An element inside a non-null array could be null.
- ArrayGet.class, fromDexType(appInfo.dexItemFactory.stringType, appInfo, true),
- NewInstance.class, fromDexType(assertionErrorType, appInfo, false));
+ ArrayGet.class, fromDexType(appInfo.dexItemFactory.stringType, true, appInfo),
+ NewInstance.class, fromDexType(assertionErrorType, false, appInfo));
forEachOutValue(irCode, (v, l) -> {
if (l.isArrayType()) {
ArrayTypeLatticeElement lattice = l.asArrayTypeLatticeElement();
@@ -206,11 +206,11 @@
DexType testClass = appInfo.dexItemFactory.createType(
DescriptorUtils.javaTypeToDescriptor(FieldAccessTest.class.getCanonicalName()));
Map<Class<? extends Instruction>, TypeLatticeElement> expectedLattices = ImmutableMap.of(
- Argument.class, fromDexType(testClass, appInfo, true),
- NonNull.class, fromDexType(testClass, appInfo, false),
+ Argument.class, fromDexType(testClass, true, appInfo),
+ NonNull.class, fromDexType(testClass, false, appInfo),
// instance may not be initialized.
- InstanceGet.class, fromDexType(appInfo.dexItemFactory.stringType, appInfo, true),
- NewInstance.class, fromDexType(assertionErrorType, appInfo, false));
+ InstanceGet.class, fromDexType(appInfo.dexItemFactory.stringType, true, appInfo),
+ NewInstance.class, fromDexType(assertionErrorType, false, appInfo));
forEachOutValue(irCode, (v, l) -> verifyClassTypeLattice(expectedLattices, mainClass, v, l));
});
}
@@ -226,11 +226,11 @@
DexType testClass = appInfo.dexItemFactory.createType(
DescriptorUtils.javaTypeToDescriptor(FieldAccessTest.class.getCanonicalName()));
Map<Class<? extends Instruction>, TypeLatticeElement> expectedLattices = ImmutableMap.of(
- Argument.class, fromDexType(testClass, appInfo, true),
- NonNull.class, fromDexType(testClass, appInfo, false),
+ Argument.class, fromDexType(testClass, true, appInfo),
+ NonNull.class, fromDexType(testClass, false, appInfo),
// instance may not be initialized.
- InstanceGet.class, fromDexType(appInfo.dexItemFactory.stringType, appInfo, true),
- NewInstance.class, fromDexType(assertionErrorType, appInfo, false));
+ InstanceGet.class, fromDexType(appInfo.dexItemFactory.stringType, true, appInfo),
+ NewInstance.class, fromDexType(assertionErrorType, false, appInfo));
forEachOutValue(irCode, (v, l) -> verifyClassTypeLattice(expectedLattices, mainClass, v, l));
});
}
diff --git a/src/test/java/com/android/tools/r8/ir/analysis/type/TypeLatticeTest.java b/src/test/java/com/android/tools/r8/ir/analysis/type/TypeLatticeTest.java
index 8d956a8..08a220f 100644
--- a/src/test/java/com/android/tools/r8/ir/analysis/type/TypeLatticeTest.java
+++ b/src/test/java/com/android/tools/r8/ir/analysis/type/TypeLatticeTest.java
@@ -75,7 +75,7 @@
}
private TypeLatticeElement element(DexType type) {
- return TypeLatticeElement.fromDexType(type, appInfo, true);
+ return TypeLatticeElement.fromDexType(type, true, appInfo);
}
private ArrayTypeLatticeElement array(int nesting, DexType base) {
@@ -84,15 +84,15 @@
private TypeLatticeElement join(TypeLatticeElement... elements) {
assertTrue(elements.length > 1);
- return TypeLatticeElement.join(appInfo, Arrays.stream(elements));
+ return TypeLatticeElement.join(Arrays.stream(elements), appInfo);
}
private boolean strictlyLessThan(TypeLatticeElement l1, TypeLatticeElement l2) {
- return TypeLatticeElement.strictlyLessThan(appInfo, l1, l2);
+ return l1.strictlyLessThan(l2, appInfo);
}
private boolean lessThanOrEqual(TypeLatticeElement l1, TypeLatticeElement l2) {
- return TypeLatticeElement.lessThanOrEqual(appInfo, l1, l2);
+ return l1.lessThanOrEqual(l2, appInfo);
}
@Test