modified: TypeUnifyTask.java

Varianceweitergabe in den verschiedenen Cases eingefuegt
Erste Zaehlungen eingefuegt
This commit is contained in:
Martin Plümicke 2018-05-19 09:50:57 +02:00
parent 7ea6777906
commit b5a601d798

View File

@ -74,6 +74,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
protected boolean parallel; protected boolean parallel;
Integer nOfUnify = 0;
Integer noUndefPair = 0;
Integer noBacktracking = 0;
public TypeUnifyTask() { public TypeUnifyTask() {
rules = new RuleSet(); rules = new RuleSet();
} }
@ -137,7 +143,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/* /*
* Step 1: Repeated application of reduce, adapt, erase, swap * 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)); //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<Set<Set<UnifyPair>>> {
// If pairs occured that did not match one of the cartesian product cases, // If pairs occured that did not match one of the cartesian product cases,
// those pairs are contradictory and the unification is impossible. // those pairs are contradictory and the unification is impossible.
if(!undefinedPairs.isEmpty()) { if(!undefinedPairs.isEmpty()) {
noUndefPair++;
for (UnifyPair up : undefinedPairs) { for (UnifyPair up : undefinedPairs) {
writeLog("UndefinedPairs; " + up); writeLog(noUndefPair.toString() + " UndefinedPairs; " + up);
writeLog("BasePair; " + up.getBasePair()); writeLog("BasePair; " + up.getBasePair());
} }
Set<Set<UnifyPair>> error = new HashSet<>(); Set<Set<UnifyPair>> error = new HashSet<>();
@ -400,13 +408,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
if (xi.isPresent()) { if (xi.isPresent()) {
variance = xi.get(); variance = xi.get();
} }
if (variance == 1 && nextSetasList.size() > 1) { //if (variance == 1 && nextSetasList.size() > 1) {
List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size()); // List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
for (int ii = 0; ii < nextSetasList.size();ii++) { // for (int ii = 0; ii < nextSetasList.size();ii++) {
al.add(0,nextSetasList.get(ii)); // al.add(0,nextSetasList.get(ii));
} // }
nextSetasList = al; // nextSetasList = al;
} //}
//Set<UnifyPair> a = nextSetasListIt.next(); //Set<UnifyPair> a = nextSetasListIt.next();
/*if (nextSetasList.size()>1) {zu loeschen /*if (nextSetasList.size()>1) {zu loeschen
if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D"))
@ -552,6 +560,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("nextSetasList: " + nextSetasList.toString()); writeLog("nextSetasList: " + nextSetasList.toString());
writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); writeLog("Number erased Elements (undef): " + (len - nextSetasList.size()));
System.out.println(""); System.out.println("");
noBacktracking++;
writeLog("Number of Backtracking: " + noBacktracking);
} }
//if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) {
// return result; // return result;
@ -1010,6 +1020,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> result = new HashSet<>(); Set<Set<UnifyPair>> result = new HashSet<>();
UnifyType aPrime = PlaceholderType.freshPlaceholder(); UnifyType aPrime = PlaceholderType.freshPlaceholder();
((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance());
UnifyType extAPrime = new ExtendsType(aPrime); UnifyType extAPrime = new ExtendsType(aPrime);
UnifyType thetaPrime = extThetaPrime.getExtendedType(); UnifyType thetaPrime = extThetaPrime.getExtendedType();
Set<UnifyPair> resultPrime = new HashSet<>(); Set<UnifyPair> resultPrime = new HashSet<>();
@ -1035,6 +1046,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> result = new HashSet<>(); Set<Set<UnifyPair>> result = new HashSet<>();
UnifyType aPrime = PlaceholderType.freshPlaceholder(); UnifyType aPrime = PlaceholderType.freshPlaceholder();
((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance());
UnifyType supAPrime = new SuperType(aPrime); UnifyType supAPrime = new SuperType(aPrime);
UnifyType thetaPrime = subThetaPrime.getSuperedType(); UnifyType thetaPrime = subThetaPrime.getSuperedType();
Set<UnifyPair> resultPrime = new HashSet<>(); Set<UnifyPair> resultPrime = new HashSet<>();
@ -1074,6 +1086,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
for(int i = 0; !allGen && i < freshTphs.length; i++) { for(int i = 0; !allGen && i < freshTphs.length; i++) {
freshTphs[i] = PlaceholderType.freshPlaceholder(); 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)); resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair));
} }
@ -1104,6 +1117,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//writeLog(resultPrime.toString()); //writeLog(resultPrime.toString());
UnifyType freshTph = PlaceholderType.freshPlaceholder(); UnifyType freshTph = PlaceholderType.freshPlaceholder();
((PlaceholderType)freshTph).setVariance(a.getVariance());
resultPrime = new HashSet<>(); resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair));