From 3e4e66d60d0db1f2d5b78192f19e5c5ca6ed58cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 5 Aug 2018 15:05:17 +0200 Subject: [PATCH] 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 --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 46 +++++++++++++---- .../syntaxtree/factory/UnifyTypeFactory.java | 4 +- .../typeinference/unify/TypeUnify2Task.java | 4 ++ .../typeinference/unify/TypeUnifyTask.java | 49 +++++++++++++++---- test/bytecode/javFiles/Matrix.jav | 2 +- test/bytecode/javFiles/applyLambda.jav | 4 +- 6 files changed, 85 insertions(+), 24 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index fd6af924..f97d9657 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -24,6 +24,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; import de.dhbwstuttgart.typeinference.unify.distributeVariance; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; @@ -38,7 +39,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; public class JavaTXCompiler { - + final boolean parallel = false; final CompilationEnvironment environment; public final Map sourceFiles = new HashMap<>(); 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.flush(); + Set forks = new HashSet<>(); Set>> cardProd = unifyCons.cartesianProduct(); for (List> xCons : cardProd ){ Set xConsSet = new HashSet<>(); @@ -175,15 +177,39 @@ public class JavaTXCompiler { return y; } ) .collect(Collectors.toCollection(HashSet::new)); varianceInheritance(xConsSet); - //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); - Set> result = unify.unify(xConsSet, finiteClosure, logFile, log); - System.out.println("RESULT: " + result); - logFile.write("RES: " + result.toString()+"\n"); - logFile.flush(); - results.addAll(result); - } - } - catch (IOException e) { } + if (parallel) { + //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + Set eq = new HashSet<>(xConsSet); + TypeUnifyTask fork = new TypeUnifyTask(eq, finiteClosure, true, logFile, log); + forks.add(fork); + fork.fork(); + } + else { + Set> 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> 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 -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 71985334..d495a979 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -198,7 +198,9 @@ public class UnifyTypeFactory { }else if(tr instanceof WildcardType){ return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr); }else throw new NotImplementedException(); - }else throw new NotImplementedException(); + }else { + throw new NotImplementedException(); + } } public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map tphs) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 873ad423..1ca45584 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -18,6 +18,10 @@ public class TypeUnify2Task extends TypeUnifyTask { @Override protected Set> compute() { + if (one) { + System.out.println("two"); + } + one = true; Set> res = unify2(setToFlatten, eq, fc, parallel); /*if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 16201b54..0af05b05 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams; import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import de.dhbwstuttgart.typeinference.unify.model.WildcardType; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; import java.io.File; @@ -54,6 +55,8 @@ public class TypeUnifyTask extends RecursiveTask>> { public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; FileWriter logFile; + + protected boolean one = false; /** * The implementation of setOps that will be used during the unification @@ -139,6 +142,10 @@ public class TypeUnifyTask extends RecursiveTask>> { */ @Override protected Set> compute() { + if (one) { + System.out.println("two"); + } + one = true; Set> res = unify(eq, fc, parallel); if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; @@ -317,6 +324,8 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //System.out.println("vor Subst: " + eqPrime); Optional> eqPrimePrime = rules.subst(eqPrime); + Set> unifyres1 = null; + Set> unifyres2 = null; /* * Step 6 a) Restart (fork) for pairs where subst was applied @@ -358,12 +367,12 @@ public class TypeUnifyTask extends RecursiveTask>> { eqPrimePrimeSet.add(eqPrime); } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unify(eqPrimePrime.get(), fc, parallel); + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), fc, parallel); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unify(eqPrime, fc, parallel); + Set> unifyres = unifyres2 = unify(eqPrime, fc, parallel); eqPrimePrimeSet.addAll(unifyres); @@ -386,8 +395,14 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 7: Filter empty sets; */ 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()); + Iterator upit = eqPrimePrimeSet.iterator().next().iterator(); + if (upit.next().getLhsType() instanceof WildcardType + || upit.next().getLhsType() instanceof WildcardType) { + System.out.println(""); + } + } return eqPrimePrimeSet; } @@ -523,16 +538,26 @@ public class TypeUnifyTask extends RecursiveTask>> { Set forks = new HashSet<>(); //TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); - Set newEq = new HashSet<>(eq); - for(Set nSaL : nextSetasListRest) { + + + Set newEqOrig = new HashSet<>(eq); + Set> 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 nSaL = nextSetasListRest.remove(0); + Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); newElems.add(nSaL); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, fc, parallel, logFile, log); forks.add(fork); fork.fork(); } - res = unify2(elems, eq, fc, parallel); - //res = fork1.join(); + //res = unify2(elems, eq, fc, parallel); + res = forkOrig.join(); for(TypeUnifyTask fork : forks) { Set> fork_res = fork.join(); add_res.addAll(fork_res); @@ -546,12 +571,16 @@ public class TypeUnifyTask extends RecursiveTask>> { if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; + if (res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } } else { if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) || result.isEmpty()) { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RESADD:" + result.toString() + " " + res.toString()); result.addAll(res); } //else { @@ -1189,8 +1218,8 @@ public class TypeUnifyTask extends RecursiveTask>> { allGen = false; break; } - - for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { + Set fBounded = new HashSet<>(pair.getfBounded()); + for(UnifyType thetaS : fc.greater(theta, fBounded/*pair.getfBounded()*/)) { Set resultPrime = new HashSet<>(); Match match = new Match(); @@ -1198,7 +1227,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(int i = 0; !allGen && i < freshTphs.length; i++) { freshTphs[i] = PlaceholderType.freshPlaceholder(); ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance()); - Set fBounded = pair.getfBounded(); + //Set fBounded = pair.getfBounded(); int i_ef = i; BiFunction f = (x,y) -> diff --git a/test/bytecode/javFiles/Matrix.jav b/test/bytecode/javFiles/Matrix.jav index 5600ad88..2ba7f307 100644 --- a/test/bytecode/javFiles/Matrix.jav +++ b/test/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -import java.lang.Byte; +//import java.lang.Byte; import java.lang.Boolean; public class Matrix extends Vector> { diff --git a/test/bytecode/javFiles/applyLambda.jav b/test/bytecode/javFiles/applyLambda.jav index 331bfbfe..97a25c87 100644 --- a/test/bytecode/javFiles/applyLambda.jav +++ b/test/bytecode/javFiles/applyLambda.jav @@ -8,8 +8,8 @@ public class applyLambda { return x; }; - return lam1.apply(new Apply()); - //return lam1; + //return lam1.apply(new Apply()); + return lam1; //return new Vector(); } }