modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java

modified:   ../../src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   ../../test/bytecode/javFiles/Matrix.jav
	modified:   ../../test/bytecode/javFiles/applyLambda.jav
? extends gen_nv =. ? super gen_nv sind in den RES
This commit is contained in:
Martin Plümicke 2018-08-05 15:05:17 +02:00
parent 883ab50f94
commit 3e4e66d60d
6 changed files with 85 additions and 24 deletions

View File

@ -24,6 +24,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.RuleSet;
import de.dhbwstuttgart.typeinference.unify.TypeUnify; import de.dhbwstuttgart.typeinference.unify.TypeUnify;
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
import de.dhbwstuttgart.typeinference.unify.distributeVariance; import de.dhbwstuttgart.typeinference.unify.distributeVariance;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
@ -38,7 +39,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class JavaTXCompiler { public class JavaTXCompiler {
final boolean parallel = false;
final CompilationEnvironment environment; final CompilationEnvironment environment;
public final Map<File, SourceFile> sourceFiles = new HashMap<>(); public final Map<File, SourceFile> sourceFiles = new HashMap<>();
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
@ -117,6 +118,7 @@ public class JavaTXCompiler {
logFile.write(ASTTypePrinter.print(sf)); logFile.write(ASTTypePrinter.print(sf));
} }
logFile.flush(); logFile.flush();
Set<TypeUnifyTask> forks = new HashSet<>();
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct(); Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
for (List<Constraint<UnifyPair>> xCons : cardProd ){ for (List<Constraint<UnifyPair>> xCons : cardProd ){
Set<UnifyPair> xConsSet = new HashSet<>(); Set<UnifyPair> xConsSet = new HashSet<>();
@ -175,15 +177,39 @@ public class JavaTXCompiler {
return y; } ) return y; } )
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
varianceInheritance(xConsSet); varianceInheritance(xConsSet);
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); if (parallel) {
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure, logFile, log); //Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
System.out.println("RESULT: " + result); Set<UnifyPair> eq = new HashSet<>(xConsSet);
logFile.write("RES: " + result.toString()+"\n"); TypeUnifyTask fork = new TypeUnifyTask(eq, finiteClosure, true, logFile, log);
logFile.flush(); forks.add(fork);
results.addAll(result); fork.fork();
} }
} else {
catch (IOException e) { } Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
System.out.println("RESULT: " + result);
logFile.write("RES: " + result.toString()+"\n");
logFile.flush();
results.addAll(result);
}
}
for (TypeUnifyTask fork : forks) {
try {
Set<Set<UnifyPair>> result = fork.join();
System.out.println("RESULT: " + result);
logFile.write("RES: " + result.toString()+"\n");
logFile.flush();
results.addAll(result);
}
catch (ConcurrentModificationException v) {
v.printStackTrace();
while (v.getCause() instanceof ConcurrentModificationException) {
v = (ConcurrentModificationException)v.getCause();
}
System.out.println(v);
}
}
}
catch (IOException e) { }
return results.stream().map((unifyPairs -> return results.stream().map((unifyPairs ->
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());

View File

@ -198,7 +198,9 @@ public class UnifyTypeFactory {
}else if(tr instanceof WildcardType){ }else if(tr instanceof WildcardType){
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr); return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
}else throw new NotImplementedException(); }else throw new NotImplementedException();
}else throw new NotImplementedException(); }else {
throw new NotImplementedException();
}
} }
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) { public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {

View File

@ -18,6 +18,10 @@ public class TypeUnify2Task extends TypeUnifyTask {
@Override @Override
protected Set<Set<UnifyPair>> compute() { protected Set<Set<UnifyPair>> compute() {
if (one) {
System.out.println("two");
}
one = true;
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, fc, parallel); Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, fc, parallel);
/*if (isUndefinedPairSetSet(res)) { /*if (isUndefinedPairSetSet(res)) {
return new HashSet<>(); } return new HashSet<>(); }

View File

@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
import java.io.File; import java.io.File;
@ -54,6 +55,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
FileWriter logFile; FileWriter logFile;
protected boolean one = false;
/** /**
* The implementation of setOps that will be used during the unification * The implementation of setOps that will be used during the unification
@ -139,6 +142,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/ */
@Override @Override
protected Set<Set<UnifyPair>> compute() { protected Set<Set<UnifyPair>> compute() {
if (one) {
System.out.println("two");
}
one = true;
Set<Set<UnifyPair>> res = unify(eq, fc, parallel); Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
else return res; else return res;
@ -317,6 +324,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/ */
//System.out.println("vor Subst: " + eqPrime); //System.out.println("vor Subst: " + eqPrime);
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime); Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
Set<Set<UnifyPair>> unifyres1 = null;
Set<Set<UnifyPair>> unifyres2 = null;
/* /*
* Step 6 a) Restart (fork) for pairs where subst was applied * Step 6 a) Restart (fork) for pairs where subst was applied
@ -358,12 +367,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
eqPrimePrimeSet.add(eqPrime); eqPrimePrimeSet.add(eqPrime);
} }
else if(eqPrimePrime.isPresent()) { else if(eqPrimePrime.isPresent()) {
Set<Set<UnifyPair>> unifyres = unify(eqPrimePrime.get(), fc, parallel); Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), fc, parallel);
eqPrimePrimeSet.addAll(unifyres); eqPrimePrimeSet.addAll(unifyres);
} }
else { else {
Set<Set<UnifyPair>> unifyres = unify(eqPrime, fc, parallel); Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, fc, parallel);
eqPrimePrimeSet.addAll(unifyres); eqPrimePrimeSet.addAll(unifyres);
@ -386,8 +395,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* Step 7: Filter empty sets; * Step 7: Filter empty sets;
*/ */
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) {
writeLog("Result1 " + eqPrimePrimeSet.toString()); writeLog("Result1 " + eqPrimePrimeSet.toString());
Iterator<UnifyPair> upit = eqPrimePrimeSet.iterator().next().iterator();
if (upit.next().getLhsType() instanceof WildcardType
|| upit.next().getLhsType() instanceof WildcardType) {
System.out.println("");
}
}
return eqPrimePrimeSet; return eqPrimePrimeSet;
} }
@ -523,16 +538,26 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<TypeUnifyTask> forks = new HashSet<>(); Set<TypeUnifyTask> forks = new HashSet<>();
//TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); //TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
Set<UnifyPair> newEq = new HashSet<>(eq);
for(Set<UnifyPair> nSaL : nextSetasListRest) {
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
newElemsOrig.add(a);
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, fc, parallel, logFile, log);
forks.add(forkOrig);
forkOrig.fork();
while (!nextSetasListRest.isEmpty()) {
Set<UnifyPair> nSaL = nextSetasListRest.remove(0);
Set<UnifyPair> newEq = new HashSet<>(eq);
Set<Set<UnifyPair>> newElems = new HashSet<>(elems); Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
newElems.add(nSaL); newElems.add(nSaL);
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, fc, parallel, logFile, log); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, fc, parallel, logFile, log);
forks.add(fork); forks.add(fork);
fork.fork(); fork.fork();
} }
res = unify2(elems, eq, fc, parallel); //res = unify2(elems, eq, fc, parallel);
//res = fork1.join(); res = forkOrig.join();
for(TypeUnifyTask fork : forks) { for(TypeUnifyTask fork : forks) {
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
add_res.addAll(fork_res); add_res.addAll(fork_res);
@ -546,12 +571,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
result = res; result = res;
if (res.iterator().next() instanceof WildcardType) {
System.out.println("");
}
} }
else { else {
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|| result.isEmpty()) { || result.isEmpty()) {
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
writeLog("RESADD:" + result.toString() + " " + res.toString());
result.addAll(res); result.addAll(res);
} }
//else { //else {
@ -1189,8 +1218,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
allGen = false; allGen = false;
break; break;
} }
Set<UnifyType> fBounded = new HashSet<>(pair.getfBounded());
for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { for(UnifyType thetaS : fc.greater(theta, fBounded/*pair.getfBounded()*/)) {
Set<UnifyPair> resultPrime = new HashSet<>(); Set<UnifyPair> resultPrime = new HashSet<>();
Match match = new Match(); Match match = new Match();
@ -1198,7 +1227,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
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()); ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
Set<UnifyType> fBounded = pair.getfBounded(); //Set<UnifyType> fBounded = pair.getfBounded();
int i_ef = i; int i_ef = i;
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) -> BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->

View File

@ -1,6 +1,6 @@
import java.util.Vector; import java.util.Vector;
import java.lang.Integer; import java.lang.Integer;
import java.lang.Byte; //import java.lang.Byte;
import java.lang.Boolean; import java.lang.Boolean;
public class Matrix extends Vector<Vector<Integer>> { public class Matrix extends Vector<Vector<Integer>> {

View File

@ -8,8 +8,8 @@ public class applyLambda {
return x; return x;
}; };
return lam1.apply(new Apply()); //return lam1.apply(new Apply());
//return lam1; return lam1;
//return new Vector(); //return new Vector();
} }
} }