From 95f48ffcb73ec7e1f938da7f9ac74e81c1ca3da1 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 14 Jan 2021 15:29:06 +0100 Subject: [PATCH] modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java ckeckA druch checkNoContradiction ersetzt --- .../typeinference/unify/TypeUnifyTask.java | 160 +++--------------- 1 file changed, 25 insertions(+), 135 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8377edd6..5abacf70 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -859,37 +859,10 @@ public class TypeUnifyTask extends RecursiveTask>> { /* Wenn bei (a \in theta) \in a zu Widerspruch in oneElems wird * a verworfen und zu nächstem Element von nextSetasList gegangen */ - if (!oderConstraint && !sameEqSet.isEmpty()) { - //optAPair enthaelt ggf. das Paar a = ty' \in a - //unterscheidet sich von optOrigPair, da dort a = ty - Optional optAPair = a.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + variance + "sameEqSet:" + sameEqSet); - boolean newCheckA = newCheckA(a, sameEqSet, result); - if (!checkA(aPair, sameEqSet, elems, result)) { - writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); - a = null; - noShortendElements++; - continue; - } - else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); - } + if (!oderConstraint && !sameEqSet.isEmpty() && !checkNoContradiction(a, sameEqSet, result)) { + a = null; + noShortendElements++; + continue; } /* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread @@ -923,38 +896,14 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("1 RM" + nSaL.toString()); } - /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - if (!oderConstraint) {//weiss nicht ob das wirklich stimmt - Optional optAPair = nSaL.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - boolean newCheckA = newCheckA(nSaL, sameEqSet, result); - if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { - writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); - nSaL = null; - noShortendElements++; - continue; - } - else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); + if (!oderConstraint) { + //ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht + if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) { + nSaL = null; + noShortendElements++; + continue; } } - /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ else { nextSetasListOderConstraints.add(((Constraint)nSaL).getExtendConstraint()); } @@ -1046,38 +995,14 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("-1 RM" + nSaL.toString()); } - if (!oderConstraint) {//weiss nicht ob das wirklich stimmt - /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional optAPair = nSaL.stream().filter(x -> ( - //x.getBasePair() != null && ist gegeben wenn variance != 2 - //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && - (x.getPairOp().equals(PairOperator.EQUALSDOT) - /* - (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()) - */ - ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist - x.getLhsType().equals(x.getBasePair().getLhsType()) || - x.getLhsType().equals(x.getBasePair().getRhsType()) - ).findFirst(); - - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - boolean newCheckA = newCheckA(nSaL, sameEqSet, result); - if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { - writeLog("newCheckA:" + new Boolean(newCheckA == false).toString()); - nSaL = null; - noShortendElements++; - continue; - } - else writeLog("newCheckA:" + new Boolean(newCheckA == true).toString()); + if (!oderConstraint) { + //ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht + if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) { + nSaL = null; + noShortendElements++; + continue; } } - /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ else { nextSetasListOderConstraints.add(((Constraint)nSaL).getExtendConstraint()); } @@ -1560,7 +1485,15 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } - protected Boolean newCheckA(Set a, Set sameEqSet, Set> result) { + /** + * checks if there is for (a = ty) \in a in sameEqSet a constradiction + * @param a Set of actual element of constraints with a =. ty \in a + * @param sameEqSet Set of constraints where a <. ty' and ty' <. a + * @param result set of results which contains correct solution s and the + * the error constraints. Error constraints are added + * @result contradiction of (a = ty) in sameEqSet + */ + protected Boolean checkNoContradiction(Set a, Set sameEqSet, Set> result) { //optAPair enthaelt ggf. das Paar a = ty' \in a //unterscheidet sich von optOrigPair, da dort a = ty @@ -1620,49 +1553,6 @@ public class TypeUnifyTask extends RecursiveTask>> { return true; } - protected Boolean checkA (UnifyPair aPair, Set sameEqSet, Set> elems, Set> result) { - writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); - for (UnifyPair sameEq : sameEqSet) { - if (sameEq.getLhsType() instanceof PlaceholderType) { - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); - unitedSubst.addAll(aPair.getAllBases()); - unitedSubst.addAll(sameEq.getAllSubstitutions()); - unitedSubst.addAll(sameEq.getAllBases()); - localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - finalresult = false; - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); - finalresult = true; - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); - return false; - } - } - else { - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); - unitedSubst.addAll(aPair.getAllBases()); - unitedSubst.addAll(sameEq.getAllSubstitutions()); - unitedSubst.addAll(sameEq.getAllBases()); - localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - finalresult = false; - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); - finalresult = true; - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); - return false; - } - } - } - writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); - return true; - } protected boolean couldBecorrect(Set, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set nextElem) { return reducedUndefResSubstGroundedBasePair.stream()