forked from JavaTX/JavaCompilerCore
Fix equality
This commit is contained in:
parent
b9f19cc105
commit
3963baa9ce
@ -121,6 +121,16 @@ public class ASTToTargetAST {
|
|||||||
input.add(pair);
|
input.add(pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addToEquality(Map<TypePlaceholder, TypePlaceholder> equality, TypePlaceholder from, TypePlaceholder to) {
|
||||||
|
for (var entry : new HashSet<>(equality.entrySet())) {
|
||||||
|
if (entry.getValue().equals(from)) {
|
||||||
|
equality.remove(entry.getKey());
|
||||||
|
equality.put(entry.getKey(), to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
equality.put(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
static Set<ResultPair<?, ?>> transitiveClosure(Set<ResultPair<?, ?>> generics) {
|
static Set<ResultPair<?, ?>> transitiveClosure(Set<ResultPair<?, ?>> generics) {
|
||||||
Set<ResultPair<?, ?>> all = new HashSet<>(generics);
|
Set<ResultPair<?, ?>> all = new HashSet<>(generics);
|
||||||
HashSet<ResultPair<?, ?>> toAdd = new HashSet<>();
|
HashSet<ResultPair<?, ?>> toAdd = new HashSet<>();
|
||||||
@ -152,6 +162,7 @@ public class ASTToTargetAST {
|
|||||||
) {
|
) {
|
||||||
// Type variables with bounds that are also type variables of the method
|
// Type variables with bounds that are also type variables of the method
|
||||||
for (var typeVariable : new HashSet<>(typeVariables)) {
|
for (var typeVariable : new HashSet<>(typeVariables)) {
|
||||||
|
typeVariable = equality.getOrDefault(typeVariable, typeVariable);
|
||||||
if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
|
if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
|
||||||
continue;
|
continue;
|
||||||
for (var pair : simplifiedConstraints) {
|
for (var pair : simplifiedConstraints) {
|
||||||
@ -573,7 +584,6 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(method.name + ": " + txResult + " & " + javaResult);
|
System.out.println(method.name + ": " + txResult + " & " + javaResult);
|
||||||
|
|
||||||
return generics;
|
return generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,20 +631,17 @@ public class ASTToTargetAST {
|
|||||||
findAllBounds(field.getType(), txResult, txEquality);
|
findAllBounds(field.getType(), txResult, txEquality);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Java Generics
|
var referenced = new HashSet<TypePlaceholder>();
|
||||||
var referenced = new HashSet<TypePlaceholder>();
|
eliminateCycles(javaResult, equality, referenced);
|
||||||
eliminateCycles(javaResult, equality, referenced);
|
eliminateInfima(javaResult, equality, referenced);
|
||||||
eliminateInfima(javaResult, equality, referenced);
|
var txReferenced = new HashSet<TypePlaceholder>();
|
||||||
eliminateInnerTypeVariablesOfClass(classOrInterface, javaResult, equality, referenced);
|
eliminateInfima(txResult, txEquality, txReferenced);
|
||||||
equalizeTypeVariables(javaResult, equality);
|
|
||||||
}
|
|
||||||
{ // TX Generics
|
|
||||||
var referenced = new HashSet<TypePlaceholder>();
|
|
||||||
eliminateInfima(txResult, txEquality, referenced);
|
|
||||||
eliminateInnerTypeVariablesOfClass(classOrInterface, txResult, txEquality, referenced);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + txResult);
|
eliminateInnerTypeVariablesOfClass(classOrInterface, javaResult, equality, referenced);
|
||||||
|
equalizeTypeVariables(javaResult, equality);
|
||||||
|
eliminateInnerTypeVariablesOfClass(classOrInterface, txResult, txEquality, txReferenced);
|
||||||
|
|
||||||
|
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + txResult + ", " + javaResult);
|
||||||
return generics;
|
return generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,7 +649,7 @@ public class ASTToTargetAST {
|
|||||||
for (var pair : new HashSet<>(input)) {
|
for (var pair : new HashSet<>(input)) {
|
||||||
if (pair instanceof PairTPHsmallerTPH ptph) {
|
if (pair instanceof PairTPHsmallerTPH ptph) {
|
||||||
if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) {
|
if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) {
|
||||||
equality.put(ptph.left, ptph.right);
|
addToEquality(equality, ptph.left, ptph.right);
|
||||||
input.remove(ptph);
|
input.remove(ptph);
|
||||||
for (var pair2 : new HashSet<>(input)) {
|
for (var pair2 : new HashSet<>(input)) {
|
||||||
if (pair2 instanceof PairTPHsmallerTPH ptph2 && ptph2.right.equals(ptph.left)) {
|
if (pair2 instanceof PairTPHsmallerTPH ptph2 && ptph2.right.equals(ptph.left)) {
|
||||||
@ -735,7 +742,7 @@ public class ASTToTargetAST {
|
|||||||
var right = cycle.get(i + 1);
|
var right = cycle.get(i + 1);
|
||||||
var pair = new PairTPHsmallerTPH(left, right);
|
var pair = new PairTPHsmallerTPH(left, right);
|
||||||
input.remove(pair);
|
input.remove(pair);
|
||||||
equality.put(left, newTph);
|
addToEquality(equality, left, newTph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -759,7 +766,7 @@ public class ASTToTargetAST {
|
|||||||
addToPairs(input, new PairTPHsmallerTPH(left, newTph));
|
addToPairs(input, new PairTPHsmallerTPH(left, newTph));
|
||||||
input.removeAll(infima);
|
input.removeAll(infima);
|
||||||
for (var infimum : infima) {
|
for (var infimum : infima) {
|
||||||
equality.put(infimum.right, newTph);
|
addToEquality(equality, infimum.right, newTph);
|
||||||
new HashSet<>(input).forEach(pair -> {
|
new HashSet<>(input).forEach(pair -> {
|
||||||
if (pair.getLeft().equals(infimum.right)) {
|
if (pair.getLeft().equals(infimum.right)) {
|
||||||
input.remove(pair);
|
input.remove(pair);
|
||||||
|
@ -51,6 +51,7 @@ public class TestGenerics {
|
|||||||
var anyMethod = result.findMethod("anyMethod");
|
var anyMethod = result.findMethod("anyMethod");
|
||||||
var otherMethod = result.findMethod("otherMethod");
|
var otherMethod = result.findMethod("otherMethod");
|
||||||
var a = result.findField("a");
|
var a = result.findField("a");
|
||||||
|
var b = result.findField("b");
|
||||||
|
|
||||||
var generics = result.genericsResults.get(0);
|
var generics = result.genericsResults.get(0);
|
||||||
assertEquals(1, generics.get(anyMethod).size());
|
assertEquals(1, generics.get(anyMethod).size());
|
||||||
@ -60,7 +61,7 @@ public class TestGenerics {
|
|||||||
var ECK2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, anyMethod);
|
var ECK2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, anyMethod);
|
||||||
var ECKChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
|
var ECKChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
|
||||||
assertEquals(ECK1, ECK2);
|
assertEquals(ECK1, ECK2);
|
||||||
assertEquals(ECK2, ECKChain);
|
assertEquals(ECK2, generics.getBounds(b.getType(), result.clazz));
|
||||||
|
|
||||||
var M = generics.getBounds(a.getType(), result.clazz);
|
var M = generics.getBounds(a.getType(), result.clazz);
|
||||||
var MChain = new BoundsList(new Bound(false, TypePlaceholder.of("ECK")), new Bound(false, ASTToTargetAST.OBJECT));
|
var MChain = new BoundsList(new Bound(false, TypePlaceholder.of("ECK")), new Bound(false, ASTToTargetAST.OBJECT));
|
||||||
|
Loading…
Reference in New Issue
Block a user