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();
ReferenceType lhsSType;
UnifyType rhsType = pair.getRhsType();
ReferenceType rhsSType;
if(lhsType instanceof ReferenceType)
if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) {
lhsSType = (ReferenceType) lhsType;
else if(lhsType instanceof WildcardType) {
rhsSType = (ReferenceType) rhsType;
}
else if ((lhsType instanceof WildcardType) && (rhsType instanceof WildcardType)) {
UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType();
if(lhsSTypeRaw instanceof ReferenceType)
UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType();
if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) {
lhsSType = (ReferenceType) lhsSTypeRaw;
rhsSType = (ReferenceType) rhsSTypeRaw;
}
else
return Optional.empty();
}
@ -335,6 +342,7 @@ public class RuleSet implements IRuleSet{
if(lhsSType.getTypeParams().empty())
return Optional.empty();
/* PL 2018-01-22 in obere Teil integriert
UnifyType rhsType = pair.getRhsType();
ReferenceType rhsSType;
@ -349,6 +357,7 @@ public class RuleSet implements IRuleSet{
}
else
return Optional.empty();
*/
if(!rhsSType.getName().equals(lhsSType.getName()))
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 totalnoOfThread = 0;
private int thNo;
int thNo;
protected boolean one = false;
Integer MaxNoOfThreads = 4;
@ -709,12 +709,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* Step 6 b) Build the union over everything.
*/
/*
* PL 2019-01-20: muss uebrprueft werden
*/
* PL 2019-01-22: geloescht
if(parallel)
for(TypeUnifyTask fork : forks)
eqPrimePrimeSet.addAll(fork.join());
*/
/*
* Step 7: Filter empty sets;
*/
@ -881,9 +881,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
newElemsOrig.add(a);
/* FORK ANFANG
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
forks.add(forkOrig);
//forks.add(forkOrig);
forkOrig.fork();
FORK ENDE */
synchronized (this) {
writeLog("a in " + variance + " "+ a);
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
@ -901,8 +905,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
forks.add(fork);
fork.fork();
}
//res = unify2(elems, eq, fc, parallel);
res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
/* 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) {
synchronized (this) {
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);
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
newElemsOrig.add(a);
/* FORK ANFANG
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
forks.add(forkOrig);
//forks.add(forkOrig);
forkOrig.fork();
FORK ENDE */
synchronized (this) {
writeLog("a in " + variance + " "+ a);
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
@ -938,8 +956,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
forks.add(fork);
fork.fork();
}
//res = unify2(elems, eq, fc, parallel);
res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
/* 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) {
synchronized (this) {
Set<Set<UnifyPair>> fork_res = fork.join();
@ -949,17 +977,20 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
};
}
} else {
if(parallel && (variance == 2) //&& noOfThread <= MaxNoOfThreads
) {
if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) {
writeLog("var2einstieg");
Set<TypeUnifyTask> forks = new HashSet<>();
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
newElemsOrig.add(a);
/* FORK ANFANG
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe);
forks.add(forkOrig);
//forks.add(forkOrig);
forkOrig.fork();
FORK ENDE */
synchronized (this) {
writeLog("a in " + variance + " "+ a);
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
@ -975,8 +1006,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
forks.add(fork);
fork.fork();
}
//res = unify2(elems, eq, fc, parallel);
res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
/* 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) {
synchronized (this) {
Set<Set<UnifyPair>> fork_res = fork.join();
@ -1089,13 +1130,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
//}
/* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1)
System.out.print("");
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
if (variance == 1) {
if (parallel) {
for (Set<Set<UnifyPair>> par_res : add_res) {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
@ -1117,6 +1151,36 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
//break;
}
/* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1)
System.out.print("");
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
if (variance == 1) {
/* vorgezogen vor das if
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;
*/
/* nextSetasList = nextSetasListRest; */
/* 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) {
/* vorgezogen vor das if
if (parallel) {
for (Set<Set<UnifyPair>> par_res : add_res) {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
@ -1158,6 +1223,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
//break;
}
}
*/
System.out.println("");
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
while (nextSetasListIt.hasNext()) {
@ -1177,6 +1246,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
break; }
else { if (variance == 2) {
/* vorgezogen vor das if
if (parallel) {
for (Set<Set<UnifyPair>> par_res : add_res) {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
@ -1198,6 +1268,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
//break;
}
*/
}}}
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
}