Some fixes

This commit is contained in:
Daniel Holle 2023-06-28 14:09:24 +02:00
parent bdaf578f86
commit d55b402269

View File

@ -140,6 +140,7 @@ public abstract class GenerateGenerics {
this.astToTargetAST = astToTargetAST; this.astToTargetAST = astToTargetAST;
for (var constraint : constraints.results) { for (var constraint : constraints.results) {
if (constraint instanceof PairTPHsmallerTPH p) { if (constraint instanceof PairTPHsmallerTPH p) {
System.out.println(p.left + " " + p.left.getVariance());
simplifiedConstraints.add(new PairLT(new TPH(p.left), new TPH(p.right))); simplifiedConstraints.add(new PairLT(new TPH(p.left), new TPH(p.right)));
} else if (constraint instanceof PairTPHEqualTPH p) { } else if (constraint instanceof PairTPHEqualTPH p) {
equality.put(p.getLeft(), p.getRight()); equality.put(p.getLeft(), p.getRight());
@ -213,7 +214,8 @@ public abstract class GenerateGenerics {
equality.put(entry.getKey(), to); equality.put(entry.getKey(), to);
} }
} }
to.setVariance(from.getVariance()); System.out.println(from + " -> " + to + " " + from.getVariance());
//from.setVariance(to.getVariance());
equality.put(from, to); equality.put(from, to);
referenced.remove(new TPH(from)); referenced.remove(new TPH(from));
referenced.add(new TPH(to)); referenced.add(new TPH(to));
@ -838,19 +840,24 @@ public abstract class GenerateGenerics {
} }
} }
TPH findConnectionToReturnType(Set<TPH> returnTypes, Set<Pair> input, Set<TPH> visited, TPH tph) { Set<TPH> findConnectionToReturnType(Set<TPH> returnTypes, Set<Pair> input, Set<TPH> visited, TPH tph) {
if (returnTypes.contains(tph)) { if (returnTypes.contains(tph)) {
return tph; var res = new HashSet<TPH>();
res.add(tph);
return res;
} else { } else {
for (var pair : input) if (pair instanceof PairLT ptph) { for (var pair : input) if (pair instanceof PairLT ptph) {
if (ptph.left.equals(tph) && !visited.contains(ptph.right)) { if (ptph.left.equals(tph) && !visited.contains(ptph.right)) {
visited.add(ptph.right); visited.add(ptph.right);
var result = findConnectionToReturnType(returnTypes, input, visited, ptph.right); var result = findConnectionToReturnType(returnTypes, input, visited, ptph.right);
if (result != null) return result; if (result.size() > 0) {
result.add(ptph.right);
return result;
};
} }
} }
} }
return null; return new HashSet<>();
} }
void eliminateInfimaConnectedToReturnType(Method method, Set<Pair> input, Set<TPH> referenced) { void eliminateInfimaConnectedToReturnType(Method method, Set<Pair> input, Set<TPH> referenced) {
@ -867,19 +874,22 @@ public abstract class GenerateGenerics {
} }
} }
if (infima.size() > 1) { if (infima.size() > 1) {
System.out.println(infima);
for (var pair : infima) { for (var pair : infima) {
var returnTypes = findTypeVariables(method.getReturnType()); var returnTypes = findTypeVariables(method.getReturnType());
var returnType = findConnectionToReturnType(returnTypes, input, new HashSet<>(), pair.left); var chain = findConnectionToReturnType(returnTypes, input, new HashSet<>(), pair.left);
if (returnType != null && !returnType.equals(pair.left)) { System.out.println("Find: " + pair.left + " " + chain);
System.out.println("Equals now: " + pair.left.resolve() + " " + returnType.resolve()); chain.remove(pair.left);
addToEquality(pair.left.resolve(), returnType.resolve(), referenced); if (chain.size() > 0) {
for (var tph : chain)
addToEquality(pair.left.resolve(), tph.resolve(), referenced);
foundInfima = true; foundInfima = true;
} }
} }
} }
} }
} while (foundInfima); } while (foundInfima);
input.removeIf((i) -> !(i instanceof PairLT lt) || lt.left.equals(lt.right)); input.removeIf((i) -> (i instanceof PairLT lt) && lt.left.equals(lt.right));
} }
void eliminateInfima(Set<Pair> input, Set<TPH> referenced) { void eliminateInfima(Set<Pair> input, Set<TPH> referenced) {