Merge branch 'unify-test' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify-test

Merge
This commit is contained in:
Martin Plümicke 2018-03-15 20:50:59 +01:00
commit bd98bed5ca
3 changed files with 52 additions and 9 deletions

View File

@ -157,6 +157,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
if(!undefinedPairs.isEmpty()) { if(!undefinedPairs.isEmpty()) {
writeLog("UndefinedPairs; " + undefinedPairs); writeLog("UndefinedPairs; " + undefinedPairs);
Set<Set<UnifyPair>> error = new HashSet<>(); Set<Set<UnifyPair>> error = new HashSet<>();
undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new));
error.add(undefinedPairs); error.add(undefinedPairs);
return error; return error;
} }
@ -296,7 +297,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/* /*
* Step 7: Filter empty sets; * Step 7: Filter empty sets;
*/ */
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new)); eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
if (!eqPrimePrimeSet.isEmpty()) if (!eqPrimePrimeSet.isEmpty())
writeLog("Result " + eqPrimePrimeSet.toString()); writeLog("Result " + eqPrimePrimeSet.toString());
return eqPrimePrimeSet; return eqPrimePrimeSet;
@ -362,7 +363,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
else { else {
result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
} }
if (!result.isEmpty()) {
if (!result.isEmpty() && !isUndefinedPairSetSet(result)) {
if (variance == 1) { if (variance == 1) {
if (a.iterator().next().getLhsType().getName().equals("WL")) if (a.iterator().next().getLhsType().getName().equals("WL"))
System.out.print(""); System.out.print("");
@ -391,16 +393,29 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
} }
if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result)) {
return result;
}
//else result.stream().filter(y -> !isUndefinedPairSet(y));
} }
return result; return result;
} }
protected boolean isUndefinedPairSet(Set<Set<UnifyPair>> s) {
boolean res = true; protected boolean isUndefinedPairSet(Set<UnifyPair> s) {
Optional<Boolean> res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y));
if (res.isPresent()) { return res.get(); }
else { return false; }
}
protected boolean isUndefinedPairSetSet(Set<Set<UnifyPair>> s) {
if (s.size() ==1) { if (s.size() ==1) {
s.iterator().next().stream().forEach(x -> { res = res && x.isUndefinedPair(); return; }); Optional<Boolean> res = s.stream().map(x -> isUndefinedPairSet(x)).reduce((x,y)-> (x == y));
return res; if (res.isPresent()) { return res.get(); }
else { return false; }
} }
return false;
} }
/** /**

View File

@ -63,7 +63,7 @@ public class Unifier implements Function<UnifyType, UnifyType>, Iterable<Entry<P
* @return A new pair where the left and right-hand side are applied * @return A new pair where the left and right-hand side are applied
*/ */
public UnifyPair apply(UnifyPair p) { public UnifyPair apply(UnifyPair p) {
return new UnifyPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp()); return new UnifyPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp(), this, p);
} }
/** /**

View File

@ -30,6 +30,18 @@ public class UnifyPair {
private boolean undefinedPair = false; private boolean undefinedPair = false;
/**
* Unifier that generated this pair
* PL 2018-03-15
*/
private Unifier unifier;
/**
* Base on which the the unifier is applied
* PL 2018-03-15
*/
private UnifyPair basePair;
private final int hashCode; private final int hashCode;
/** /**
@ -47,6 +59,18 @@ public class UnifyPair {
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
} }
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Unifier uni, UnifyPair base) {
this.lhs = lhs;
this.rhs = rhs;
pairOp = op;
unifier = uni;
basePair = base;
// Caching hashcode
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
}
/** /**
* Returns the type on the left hand side of the pair. * Returns the type on the left hand side of the pair.
*/ */
@ -76,6 +100,10 @@ public class UnifyPair {
variance = v; variance = v;
} }
public void setUndefinedPair() {
undefinedPair = true;
}
public boolean isUndefinedPair() { public boolean isUndefinedPair() {
return undefinedPair; return undefinedPair;
} }