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

reduceEq-Regel korrigiert

	modified:   ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Threads soweit fertig
This commit is contained in:
Martin Plümicke 2019-01-23 01:31:25 +01:00
parent 188ea1f7f8
commit 25487469c7
2 changed files with 101 additions and 21 deletions

View File

@ -319,13 +319,20 @@ public class RuleSet implements IRuleSet{
UnifyType lhsType = pair.getLhsType(); UnifyType lhsType = pair.getLhsType();
ReferenceType lhsSType; ReferenceType lhsSType;
UnifyType rhsType = pair.getRhsType();
ReferenceType rhsSType;
if(lhsType instanceof ReferenceType) if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) {
lhsSType = (ReferenceType) lhsType; lhsSType = (ReferenceType) lhsType;
else if(lhsType instanceof WildcardType) { rhsSType = (ReferenceType) rhsType;
}
else if ((lhsType instanceof WildcardType) && (rhsType instanceof WildcardType)) {
UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType(); UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType();
if(lhsSTypeRaw instanceof ReferenceType) UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType();
if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) {
lhsSType = (ReferenceType) lhsSTypeRaw; lhsSType = (ReferenceType) lhsSTypeRaw;
rhsSType = (ReferenceType) rhsSTypeRaw;
}
else else
return Optional.empty(); return Optional.empty();
} }
@ -334,7 +341,8 @@ public class RuleSet implements IRuleSet{
if(lhsSType.getTypeParams().empty()) if(lhsSType.getTypeParams().empty())
return Optional.empty(); return Optional.empty();
/* PL 2018-01-22 in obere Teil integriert
UnifyType rhsType = pair.getRhsType(); UnifyType rhsType = pair.getRhsType();
ReferenceType rhsSType; ReferenceType rhsSType;
@ -349,6 +357,7 @@ public class RuleSet implements IRuleSet{
} }
else else
return Optional.empty(); return Optional.empty();
*/
if(!rhsSType.getName().equals(lhsSType.getName())) if(!rhsSType.getName().equals(lhsSType.getName()))
return Optional.empty(); return Optional.empty();

View File

@ -61,7 +61,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/ */
private static int noOfThread = 0; private static int noOfThread = 0;
private static int totalnoOfThread = 0; private static int totalnoOfThread = 0;
private int thNo; int thNo;
protected boolean one = false; protected boolean one = false;
Integer MaxNoOfThreads = 4; Integer MaxNoOfThreads = 4;
@ -709,12 +709,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* Step 6 b) Build the union over everything. * Step 6 b) Build the union over everything.
*/ */
/* /*
* PL 2019-01-20: muss uebrprueft werden * PL 2019-01-22: geloescht
*/
if(parallel) if(parallel)
for(TypeUnifyTask fork : forks) for(TypeUnifyTask fork : forks)
eqPrimePrimeSet.addAll(fork.join()); eqPrimePrimeSet.addAll(fork.join());
*/
/* /*
* Step 7: Filter empty sets; * Step 7: Filter empty sets;
*/ */
@ -881,9 +881,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems); Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
newElemsOrig.add(a); newElemsOrig.add(a);
/* FORK ANFANG
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
forks.add(forkOrig); //forks.add(forkOrig);
forkOrig.fork(); forkOrig.fork();
FORK ENDE */
synchronized (this) { synchronized (this) {
writeLog("a in " + variance + " "+ a); writeLog("a in " + variance + " "+ a);
writeLog("nextSetasListRest: " + nextSetasListRest.toString()); writeLog("nextSetasListRest: " + nextSetasListRest.toString());
@ -901,8 +905,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
forks.add(fork); forks.add(fork);
fork.fork(); fork.fork();
} }
//res = unify2(elems, eq, fc, parallel); res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
res = forkOrig.join();
/* FORK ANFANG
synchronized (this) {
res = forkOrig.join();
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
noOfThread--;
//add_res.add(fork_res);
};
FORK ENDE */
for(TypeUnifyTask fork : forks) { for(TypeUnifyTask fork : forks) {
synchronized (this) { synchronized (this) {
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
@ -918,9 +932,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems); Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
newElemsOrig.add(a); newElemsOrig.add(a);
/* FORK ANFANG
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
forks.add(forkOrig); //forks.add(forkOrig);
forkOrig.fork(); forkOrig.fork();
FORK ENDE */
synchronized (this) { synchronized (this) {
writeLog("a in " + variance + " "+ a); writeLog("a in " + variance + " "+ a);
writeLog("nextSetasListRest: " + nextSetasListRest.toString()); writeLog("nextSetasListRest: " + nextSetasListRest.toString());
@ -938,8 +956,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
forks.add(fork); forks.add(fork);
fork.fork(); fork.fork();
} }
//res = unify2(elems, eq, fc, parallel); res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
res = forkOrig.join();
/* FORK ANFANG
synchronized (this) {
res = forkOrig.join();
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
noOfThread--;
//add_res.add(fork_res);
};
FORK ENDE */
for(TypeUnifyTask fork : forks) { for(TypeUnifyTask fork : forks) {
synchronized (this) { synchronized (this) {
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
@ -949,17 +977,20 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}; };
} }
} else { } else {
if(parallel && (variance == 2) //&& noOfThread <= MaxNoOfThreads if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) {
) {
writeLog("var2einstieg"); writeLog("var2einstieg");
Set<TypeUnifyTask> forks = new HashSet<>(); Set<TypeUnifyTask> forks = new HashSet<>();
Set<UnifyPair> newEqOrig = new HashSet<>(eq); Set<UnifyPair> newEqOrig = new HashSet<>(eq);
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems); Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
newElemsOrig.add(a); newElemsOrig.add(a);
/* FORK ANFANG
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
forks.add(forkOrig); //forks.add(forkOrig);
forkOrig.fork(); forkOrig.fork();
FORK ENDE */
synchronized (this) { synchronized (this) {
writeLog("a in " + variance + " "+ a); writeLog("a in " + variance + " "+ a);
writeLog("nextSetasListRest: " + nextSetasListRest.toString()); writeLog("nextSetasListRest: " + nextSetasListRest.toString());
@ -975,8 +1006,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
forks.add(fork); forks.add(fork);
fork.fork(); fork.fork();
} }
//res = unify2(elems, eq, fc, parallel); res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
res = forkOrig.join();
/* FORK ANFANG
synchronized (this) {
res = forkOrig.join();
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
noOfThread--;
//add_res.add(fork_res); //vermutlich falsch
};
FORK ENDE */
for(TypeUnifyTask fork : forks) { for(TypeUnifyTask fork : forks) {
synchronized (this) { synchronized (this) {
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
@ -1089,6 +1130,27 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); //result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
//} //}
if (parallel) {
for (Set<Set<UnifyPair>> par_res : add_res) {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
result = par_res;
if (par_res.iterator().next() instanceof WildcardType) {
System.out.println("");
}
}
else {
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|| result.isEmpty()) {
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString());
result.addAll(par_res);
}
}
}
//break;
}
/* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
@ -1096,6 +1158,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
System.out.print(""); System.out.print("");
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator(); Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
if (variance == 1) { if (variance == 1) {
/* vorgezogen vor das if
if (parallel) { if (parallel) {
for (Set<Set<UnifyPair>> par_res : add_res) { for (Set<Set<UnifyPair>> par_res : add_res) {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
@ -1116,7 +1179,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
//break; //break;
} */
/* nextSetasList = nextSetasListRest; */ /* nextSetasList = nextSetasListRest; */
/* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet
*/ */
@ -1137,6 +1201,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
else { if (variance == -1) { else { if (variance == -1) {
/* vorgezogen vor das if
if (parallel) { if (parallel) {
for (Set<Set<UnifyPair>> par_res : add_res) { for (Set<Set<UnifyPair>> par_res : add_res) {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
@ -1156,8 +1221,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
} }
//break; //break;
} }
}
*/
System.out.println(""); System.out.println("");
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
while (nextSetasListIt.hasNext()) { while (nextSetasListIt.hasNext()) {
@ -1177,6 +1246,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
break; } break; }
else { if (variance == 2) { else { if (variance == 2) {
/* vorgezogen vor das if
if (parallel) { if (parallel) {
for (Set<Set<UnifyPair>> par_res : add_res) { for (Set<Set<UnifyPair>> par_res : add_res) {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
@ -1198,6 +1268,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
//break; //break;
} }
*/
}}} }}}
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
} }