modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java

in calculatePairSets werden andere Constraints fuer die gleiche Variable betrachtet
Sollte aber nach computeCartesianRecursive verschoben werden.
This commit is contained in:
Martin Plümicke 2019-03-05 00:24:11 +01:00
parent 27c6351aed
commit 728b729f08

View File

@ -590,10 +590,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren
//Typen getestet werden.
writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString());
writeLog(nOfUnify.toString() + " collectErr: " + collectErr.toString());
if (printtag) System.out.println("secondLevelSets:" +secondLevelSets);
// If pairs occured that did not match one of the cartesian product cases,
// those pairs are contradictory and the unification is impossible.
if(!undefinedPairs.isEmpty()) {
Set<UnifyPair> flatCollectErr = new HashSet<>();
collectErr.forEach(x -> flatCollectErr.addAll(x));
undefinedPairs.addAll(flatCollectErr);
noUndefPair++;
for (UnifyPair up : undefinedPairs) {
writeLog(noUndefPair.toString() + " UndefinedPairs; " + up);
@ -602,6 +606,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> error = new HashSet<>();
undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new));
error.add(undefinedPairs);
undefinedPairs.forEach(x -> writeLog("AllSubst: " +x.getAllSubstitutions().toString()));
return error;
}
@ -642,7 +647,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//Aufruf von computeCartesianRecursive ANFANG
//writeLog("topLevelSets: " + topLevelSets.toString());
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe);
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, collectErr);
}
@ -764,7 +769,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set<Set<UnifyPair>> collectErr) {
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
fstElems.addAll(topLevelSets.stream()
.filter(x -> x.size()==1)
@ -1208,7 +1213,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
else {
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
writeLog("RES Fst:" + result.toString() + " " + res.toString());
writeLog("RES Fst:" + result.toString() + " " + res.toString() + " " + collectErr.toString());
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))) {//Wenn Fehlerfall: dann die Fehler aus calculatePairSets hinzufuegen
result.addAll(collectErr);
}
result.addAll(res);
}
}
@ -1239,6 +1247,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|| result.isEmpty()) {
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString());
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))) {//Wenn Fehlerfall: dann die Fehler aus calculatePairSets hinzufuegen
result.addAll(collectErr);
}
result.addAll(par_res);
}
}
@ -1787,7 +1798,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution
hinzufuegen
*/
Set<UnifyPair> consideredElements = new HashSet<>();
for(UnifyPair pair : eq2sAsList) {
if (consideredElements.contains(pair)) {
continue;
}
PairOperator pairOp = pair.getPairOp();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
@ -1815,19 +1830,30 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<UnifyPair> sameEqSet = eq2sAsList.stream()
.filter(x -> ((x.getLhsType().equals(lhsType) || x.getRhsType().equals(lhsType)) && !x.equals(pair)))
.collect(Collectors.toCollection(HashSet::new));
consideredElements.addAll(sameEqSet);
Set<Set<UnifyPair>> x2 = x1;
Set<Set<UnifyPair>> x1Res = new HashSet<>();
writeLog("pair:\n" + pair.toString());
writeLog("x1 Start:\n" + x1.toString());
writeLog("sameEqSet:\n" + sameEqSet.toString());
for (UnifyPair sameEq : sameEqSet) {
writeLog("x1 Original:\n" + x1.toString());
if (sameEq.getLhsType() instanceof PlaceholderType) {
x1 = x1.stream().filter(y -> {
UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get();
Set<UnifyPair> localEq = new HashSet<>();
localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp()));
Set<UnifyPair> unitedSubst = new HashSet<>(type.getSubstitution());
unitedSubst.addAll(sameEq.getSubstitution());
localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0);
Boolean localCorr = !isUndefinedPairSetSet(localRes);
if (!localCorr) {
collectErr.addAll(localRes);
}
else {
localRes.forEach(z -> z.addAll(y));
x1Res.addAll(localRes);
}
return localCorr;
}
).collect(Collectors.toCollection(HashSet::new));
@ -1836,20 +1862,33 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
x1 = x1.stream().filter(y -> {
UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get();
Set<UnifyPair> localEq = new HashSet<>();
localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp()));
Set<UnifyPair> unitedSubst = new HashSet<>(type.getSubstitution());
unitedSubst.addAll(sameEq.getSubstitution());
localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0);
Boolean localCorr = !isUndefinedPairSetSet(localRes);
if (!localCorr) {
collectErr.addAll(localRes);
}
else {
localRes.forEach(z -> z.addAll(y));
x1Res.addAll(localRes);
}
return localCorr;
}
).collect(Collectors.toCollection(HashSet::new));
}
writeLog("x1 nach Lösung von " + sameEq.toString()+" :\n" + x1.toString());
writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString());
}
result.get(0).add(x1);
if (x1.isEmpty()) {
Set<Set<UnifyPair>> x1ResPrime;
if (sameEqSet.isEmpty()) {
x1ResPrime = x1;
}
else {
x1ResPrime = x1Res;
}
result.get(0).add(x1ResPrime);
if (x1ResPrime.isEmpty()) {
undefined.add(pair); //Theta ist nicht im FC => Abbruch
}
}