From b5a601d798250324360ad7221839c2c503dcd8e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 19 May 2018 09:50:57 +0200 Subject: [PATCH] modified: TypeUnifyTask.java Varianceweitergabe in den verschiedenen Cases eingefuegt Erste Zaehlungen eingefuegt --- .../typeinference/unify/TypeUnifyTask.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1f9a67d1..4a7e2750 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -74,6 +74,12 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean parallel; + Integer nOfUnify = 0; + + Integer noUndefPair = 0; + + Integer noBacktracking = 0; + public TypeUnifyTask() { rules = new RuleSet(); } @@ -137,7 +143,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 1: Repeated application of reduce, adapt, erase, swap */ - writeLog("Unifikation: " + eq.toString()); + nOfUnify++; + writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); /* @@ -212,8 +219,9 @@ public class TypeUnifyTask extends RecursiveTask>> { // 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()) { + noUndefPair++; for (UnifyPair up : undefinedPairs) { - writeLog("UndefinedPairs; " + up); + writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); writeLog("BasePair; " + up.getBasePair()); } Set> error = new HashSet<>(); @@ -400,13 +408,13 @@ public class TypeUnifyTask extends RecursiveTask>> { if (xi.isPresent()) { variance = xi.get(); } - if (variance == 1 && nextSetasList.size() > 1) { - List> al = new ArrayList<>(nextSetasList.size()); - for (int ii = 0; ii < nextSetasList.size();ii++) { - al.add(0,nextSetasList.get(ii)); - } - nextSetasList = al; - } + //if (variance == 1 && nextSetasList.size() > 1) { + // List> al = new ArrayList<>(nextSetasList.size()); + // for (int ii = 0; ii < nextSetasList.size();ii++) { + // al.add(0,nextSetasList.get(ii)); + // } + // nextSetasList = al; + //} //Set a = nextSetasListIt.next(); /*if (nextSetasList.size()>1) {zu loeschen if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) @@ -552,6 +560,8 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("nextSetasList: " + nextSetasList.toString()); writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); System.out.println(""); + noBacktracking++; + writeLog("Number of Backtracking: " + noBacktracking); } //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { // return result; @@ -1010,6 +1020,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); UnifyType extAPrime = new ExtendsType(aPrime); UnifyType thetaPrime = extThetaPrime.getExtendedType(); Set resultPrime = new HashSet<>(); @@ -1035,6 +1046,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); UnifyType supAPrime = new SuperType(aPrime); UnifyType thetaPrime = subThetaPrime.getSuperedType(); Set resultPrime = new HashSet<>(); @@ -1074,6 +1086,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; for(int i = 0; !allGen && i < freshTphs.length; i++) { freshTphs[i] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance()); resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); } @@ -1104,6 +1117,8 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog(resultPrime.toString()); UnifyType freshTph = PlaceholderType.freshPlaceholder(); + + ((PlaceholderType)freshTph).setVariance(a.getVariance()); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair));