forked from i21017/JavaCompilerCore
Compare commits
1 Commits
feat/unify
...
76f589dd33
Author | SHA1 | Date | |
---|---|---|---|
|
76f589dd33 |
@@ -259,6 +259,9 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
throw new TypeinferenceException("Unresolved constraints: " + res, new NullToken()); //return new HashSet<>();
|
throw new TypeinferenceException("Unresolved constraints: " + res, new NullToken()); //return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
System.out.println(res);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.myIsCancelled()) {
|
if (this.myIsCancelled()) {
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.cartesianproduct;
|
package de.dhbwstuttgart.typeinference.unify.cartesianproduct;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.UnifyCancelException;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify2Task;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
@@ -9,6 +11,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
|||||||
import de.dhbwstuttgart.util.Tuple;
|
import de.dhbwstuttgart.util.Tuple;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -47,6 +50,29 @@ public class Variance0Case extends VarianceCase {
|
|||||||
} else {
|
} else {
|
||||||
a = nextSetAsList.removeFirst();
|
a = nextSetAsList.removeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Set<UnifyPair> finalA = a;
|
||||||
|
if (!this.isOderConstraint && optOrigPair != null && optOrigPair.isPresent()) {
|
||||||
|
if (optOrigPair.get().getBasePair().getLhsType() instanceof PlaceholderType) {
|
||||||
|
nextSetasListRest = typeUnifyTask.oup.maxElements(
|
||||||
|
nextSetAsList.stream().filter(a_next -> typeUnifyTask.oup.compare(finalA, a_next) != 1).toList()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
nextSetasListRest = typeUnifyTask.oup.minElements(
|
||||||
|
nextSetAsList.stream().filter(a_next -> typeUnifyTask.oup.compare(finalA, a_next) != -1).toList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
nextSetAsList.remove(a);
|
||||||
|
} else if (this.isOderConstraint) {
|
||||||
|
nextSetasListRest = typeUnifyTask.oup.maxElements(
|
||||||
|
nextSetAsList.stream().filter(a_next -> typeUnifyTask.oup.compare(finalA, a_next) != 1).toList()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < Math.min(nextSetAsList.size(), 5); i++) {
|
||||||
|
nextSetasListRest.add(nextSetAsList.removeFirst());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,10 +88,79 @@ public class Variance0Case extends VarianceCase {
|
|||||||
Set<Set<UnifyPair>> result,
|
Set<Set<UnifyPair>> result,
|
||||||
Set<Set<UnifyPair>> aParDef
|
Set<Set<UnifyPair>> aParDef
|
||||||
) {
|
) {
|
||||||
elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
|
CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> resultValues = CompletableFuture.completedFuture(new Tuple<>(
|
||||||
return typeUnifyTask.unify2(elems, eq, oderConstraints, fc, context.parallel(), rekTiefe, new HashSet<>(methodSignatureConstraint)).thenApply(
|
new HashSet<>(), new HashSet<>()
|
||||||
unify2Result -> new Tuple<>(unify2Result, new HashSet<>())
|
));
|
||||||
);
|
|
||||||
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
|
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
|
/* FORK ANFANG */
|
||||||
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
||||||
|
// schedule compute() on another thread
|
||||||
|
CompletableFuture<Set<Set<UnifyPair>>> forkOrigFuture = CompletableFuture.supplyAsync(forkOrig::compute, context.executor()).thenCompose(f -> f);
|
||||||
|
resultValues = resultValues.thenCombine(forkOrigFuture,
|
||||||
|
(prevResults, currentThreadResult) -> {
|
||||||
|
forkOrig.writeLog("final Orig 0");
|
||||||
|
forkOrig.closeLogFile();
|
||||||
|
return new Tuple<>(currentThreadResult, prevResults.getSecond());
|
||||||
|
});
|
||||||
|
|
||||||
|
//forks.add(forkOrig);
|
||||||
|
if (typeUnifyTask.myIsCancelled()) {
|
||||||
|
throw new UnifyCancelException();
|
||||||
|
}
|
||||||
|
/* FORK ENDE */
|
||||||
|
|
||||||
|
writeLog("a in " + variance + " " + a);
|
||||||
|
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
|
||||||
|
|
||||||
|
while (!nextSetasListRest.isEmpty()) {
|
||||||
|
Set<UnifyPair> nSaL = nextSetasListRest.removeFirst();
|
||||||
|
nextSetAsList.remove(nSaL);
|
||||||
|
writeLog("0 RM" + nSaL.toString());
|
||||||
|
|
||||||
|
if (!this.isOderConstraint) {
|
||||||
|
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
||||||
|
if (!sameEqSet.isEmpty() && !typeUnifyTask.checkNoContradiction(nSaL, sameEqSet, result)) {
|
||||||
|
TypeUnifyTask.noShortendElements++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>) nSaL).getExtendConstraint());
|
||||||
|
}
|
||||||
|
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||||
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
|
newElems.add(nSaL);
|
||||||
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
||||||
|
// schedule compute() on another thread
|
||||||
|
CompletableFuture<Set<Set<UnifyPair>>> forkFuture = CompletableFuture.supplyAsync(fork::compute, context.executor()).thenCompose(f -> f);
|
||||||
|
resultValues = resultValues.thenCombine(forkFuture,
|
||||||
|
(prevResults, fork_res) -> {
|
||||||
|
if (typeUnifyTask.myIsCancelled()) {
|
||||||
|
throw new UnifyCancelException();
|
||||||
|
}
|
||||||
|
writeLog("fork_res: " + fork_res.toString());
|
||||||
|
writeLog(Boolean.valueOf((typeUnifyTask.isUndefinedPairSetSet(fork_res))).toString());
|
||||||
|
prevResults.getSecond().add(fork_res);
|
||||||
|
if (!typeUnifyTask.isUndefinedPairSetSet(fork_res)) {
|
||||||
|
aParDef.add(fork.getNextSetElement());
|
||||||
|
}
|
||||||
|
fork.writeLog("final 0");
|
||||||
|
fork.closeLogFile();
|
||||||
|
return prevResults;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (typeUnifyTask.myIsCancelled()) {
|
||||||
|
throw new UnifyCancelException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -75,7 +170,7 @@ public class Variance0Case extends VarianceCase {
|
|||||||
Set<UnifyPair> compResult,
|
Set<UnifyPair> compResult,
|
||||||
Set<UnifyPair> compRes
|
Set<UnifyPair> compRes
|
||||||
) {
|
) {
|
||||||
writeLog("RES var=1 ADD:" + result.toString() + " " + currentThreadResult.toString());
|
writeLog("RES var=0 ADD:" + result.toString() + " " + currentThreadResult.toString());
|
||||||
result.addAll(currentThreadResult);
|
result.addAll(currentThreadResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,24 +183,42 @@ public class Variance0Case extends VarianceCase {
|
|||||||
if (!this.isOderConstraint) {
|
if (!this.isOderConstraint) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
nextSetAsList.removeAll(nextSetasListOderConstraints);
|
nextSetAsList.removeAll(nextSetasListOderConstraints);
|
||||||
nextSetasListOderConstraints = new ArrayList<>();
|
nextSetasListOderConstraints = new ArrayList<>();
|
||||||
writeLog("Removed: " + nextSetasListOderConstraints);
|
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||||
List<Set<UnifyPair>> smallerSetasList = typeUnifyTask.oup.smallerThan(a, nextSetAsList);
|
final List<Set<UnifyPair>> smallerSetasList = typeUnifyTask.oup.smallerThan(a, nextSetAsList);
|
||||||
List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
|
List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
|
||||||
.filter(x -> !((Constraint<UnifyPair>) x).isInherited())
|
.filter(x -> !((Constraint<UnifyPair>) x).isInherited())
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
final List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||||
notInherited.forEach(x -> notErased.addAll(typeUnifyTask.oup.smallerEqThan(x, smallerSetasList)));
|
notInherited.forEach(x -> notErased.addAll(typeUnifyTask.oup.smallerEqThan(x, smallerSetasList)));
|
||||||
List<Set<UnifyPair>> erased = new ArrayList<>(smallerSetasList);
|
List<Set<UnifyPair>> erased = new ArrayList<>(smallerSetasList);
|
||||||
erased.removeAll(notErased);
|
erased.removeAll(notErased);
|
||||||
nextSetAsList.removeAll(erased);
|
nextSetAsList.removeAll(erased);
|
||||||
|
|
||||||
writeLog("Removed: " + erased);
|
writeLog("Removed: " + erased);
|
||||||
|
|
||||||
writeLog("Not Removed: " + nextSetAsList);
|
writeLog("Not Removed: " + nextSetAsList);
|
||||||
|
|
||||||
|
for (Set<UnifyPair> aPar : aParDef) {
|
||||||
|
nextSetAsList.removeAll(nextSetasListOderConstraints);
|
||||||
|
nextSetasListOderConstraints = new ArrayList<>();
|
||||||
|
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||||
|
smallerSetasList.clear();
|
||||||
|
smallerSetasList.addAll(typeUnifyTask.oup.smallerThan(aPar, nextSetAsList));
|
||||||
|
notInherited = smallerSetasList.stream()
|
||||||
|
.filter(x -> !((Constraint<UnifyPair>) x).isInherited())
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
notErased.clear();
|
||||||
|
notInherited.forEach(x -> notErased.addAll(typeUnifyTask.oup.smallerEqThan(x, smallerSetasList)));
|
||||||
|
erased = new ArrayList<>(smallerSetasList);
|
||||||
|
erased.removeAll(notErased);
|
||||||
|
nextSetAsList.removeAll(erased);
|
||||||
|
writeLog("Removed: " + erased);
|
||||||
|
writeLog("Not Removed: " + nextSetAsList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user