From 2d117e24cfda43822d128202907f421ac0b96e1e Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 8 Feb 2023 16:52:23 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java methodsignature so eingerichtet, dass die Constraints erst am Ende hinzugefuegt werden. --- .../typeinference/unify/TypeUnify2Task.java | 6 +- .../typeinference/unify/TypeUnifyTask.java | 94 +++++++++++-------- 2 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index a0515849..20820eef 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -17,11 +17,13 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; + Set methodSignatureConstraintUebergabe; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set methodSignatureConstraintUebergabe) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; + this.methodSignatureConstraintUebergabe = methodSignatureConstraintUebergabe; } Set getNextSetElement() { @@ -34,7 +36,7 @@ public class TypeUnify2Task extends TypeUnifyTask { System.out.println("two"); } one = true; - Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, false); + Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, methodSignatureConstraintUebergabe); /*if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 3e8e9994..bf6a3dcc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -260,7 +260,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); - Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, false); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, new HashSet<>()); noOfThread--; try { logFile.close(); @@ -305,7 +305,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, boolean sameEq) { + protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set methodSignatureConstraint) { //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) // ).collect(Collectors.toCollection(HashSet::new)); //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); @@ -484,12 +484,12 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, sameEq); + return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, methodSignatureConstraint); } - Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, boolean sameEq) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set methodSignatureConstraint) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -574,16 +574,34 @@ public class TypeUnifyTask extends RecursiveTask>> { eqPrimePrimeSet.add(eqPrime); if (finalresult && isSolvedForm(eqPrime)) { writeLog("eqPrime:" + eqPrime.toString()+"\n"); + + /* methodconstraintsets werden zum Ergebnis hinzugefuegt + * Anfang + */ + //System.out.println("methodSignatureConstraint Return: " + methodSignatureConstraint); + eqPrimePrimeSet.forEach(x -> x.addAll(methodSignatureConstraint)); + + //Substitutionen in methodcontraintsets werdne ausgeführt + eqPrimePrimeSet = eqPrimePrimeSet.stream().map( + x -> { Optional> help = rules.subst(x); + return help.isPresent() ? + help.get(): + x; }).collect(Collectors.toSet()); + /* + * Ende + */ + + urm.notify(eqPrimePrimeSet); } } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, sameEq); + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, methodSignatureConstraint); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, sameEq); + Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, methodSignatureConstraint); eqPrimePrimeSet.addAll(unifyres); @@ -625,7 +643,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param rekTiefe Deep of recursive calls * @return The set of all principal type unifiers */ - Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, boolean sameEq) { + Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set methodSignatureConstraint) { //oneElems: Alle 1-elementigen Mengen, die nur ein Paar //a <. theta, theta <. a oder a =. theta enthalten @@ -639,7 +657,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Optional>> optNextSet = topLevelSets.stream().filter(x -> x.size()>1).findAny(); if (!optNextSet.isPresent()) {//Alle Elemente sind 1-elementig - Set> result = unify2(oneElems, eq, oderConstraints, fc, parallel, rekTiefe, sameEq); + Set> result = unify2(oneElems, eq, oderConstraints, fc, parallel, rekTiefe, methodSignatureConstraint); return result; } @@ -849,6 +867,11 @@ public class TypeUnifyTask extends RecursiveTask>> { } } + if (oderConstraint) { + methodSignatureConstraint.addAll(((Constraint)a).getmethodSignatureConstraint()); + System.out.println("ERSTELLUNG: " +methodSignatureConstraint); + } + i++; Set> elems = new HashSet>(oneElems); writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); @@ -882,7 +905,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint); //forks.add(forkOrig); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -917,7 +940,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); forks.add(fork); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -981,7 +1004,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); //forks.add(forkOrig); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -1016,7 +1039,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); forks.add(fork); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -1081,7 +1104,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); //forks.add(forkOrig); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -1102,7 +1125,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint); forks.add(fork); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -1153,18 +1176,15 @@ public class TypeUnifyTask extends RecursiveTask>> { //noOfThread++; } else {//parallel = false oder MaxNoOfThreads ist erreicht, sequentiell weiterarbeiten elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 - res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, sameEq); + res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, new HashSet<>(methodSignatureConstraint)); }}} //Ab hier alle parallele Berechnungen wieder zusammengeführt. - Set methodSignatureConstraint = - oderConstraint ? - ((Constraint)a).getmethodSignatureConstraint() - : new HashSet<>(); if (oderConstraint) { - System.out.println("ERSTELLUNG: " +methodSignatureConstraint); + methodSignatureConstraint.removeAll(((Constraint)a).getmethodSignatureConstraint()); + System.out.println("REMOVE: " +methodSignatureConstraint); } - if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { + if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; } @@ -1456,14 +1476,16 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(); } writeLog("nextSetasList vor filter-Aufruf: " + nextSetasList); - nextSetasList = nextSetasList.stream().filter(x -> { - //Boolean ret = false; - //for (PlaceholderType var : vars) { - // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); - //} - return (!x.containsAll(durchschnitt)); - })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10 + if (!oderConstraint) { + nextSetasList = nextSetasList.stream().filter(x -> { + //Boolean ret = false; + //for (PlaceholderType var : vars) { + // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); + //} + return (!x.containsAll(durchschnitt)); + })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10 .collect(Collectors.toCollection(ArrayList::new)); + } writeLog("nextSetasList nach filter-Aufruf: " + nextSetasList); nofstred = nextSetasList.size(); //NOCH NICHT korrekt PL 2018-10-12 @@ -1492,17 +1514,6 @@ public class TypeUnifyTask extends RecursiveTask>> { //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); writeLog("res: " + res.toString()); - if (oderConstraint && !sameEq && !isUndefinedPairSetSet(result)) { - System.out.println("methodSignatureConstraint Return: " + methodSignatureConstraint); - result.forEach(x -> x.addAll(methodSignatureConstraint)); - /* - result = result.stream().map( - x -> { Optional> help = rules.subst(x); - return help.isPresent() ? - help.get(): - x; }).collect(Collectors.toSet()); - */ - } } //2020-02-02: if (variance ==2) Hier Aufruf von filterOverriding einfuegen writeLog("Return computeCR: " + result.toString()); @@ -1542,7 +1553,7 @@ public class TypeUnifyTask extends RecursiveTask>> { 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, true); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, new HashSet<>()); finalresult = true; if (isUndefinedPairSetSet(localRes)) { if (result.isEmpty() || isUndefinedPairSetSet(result)) { @@ -1560,7 +1571,7 @@ public class TypeUnifyTask extends RecursiveTask>> { 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, true); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, new HashSet<>()); finalresult = true; if (isUndefinedPairSetSet(localRes)) { if (result.isEmpty() || isUndefinedPairSetSet(result)) { @@ -1971,6 +1982,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .findAny()).isPresent() && optElem.get().getRhsType() instanceof ExtendsType);}) .collect(Collectors.toSet()); + ret.stream().forEach(x -> x.stream().forEach(y -> { Set x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen x_new.remove(y); y.addSubstitutions(x_new);