From e83d59d97d3d1cbda70544b50cb1a70a3642e744 Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Thu, 24 Jan 2019 11:16:26 +0100 Subject: [PATCH 01/15] =?UTF-8?q?Observer=20Pattern=20f=C3=BCr=20ResultSet?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 7 +++++++ .../typeinference/unify/UnifyResultEvent.java | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index f339af1a..d7915f3f 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -33,6 +33,7 @@ import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; +import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; import java.io.File; import java.io.FileOutputStream; @@ -43,6 +44,8 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; + public class JavaTXCompiler { final CompilationEnvironment environment; @@ -268,6 +271,10 @@ public class JavaTXCompiler { } */ + public UnifyResultModel typeInferenceAsync() throws ClassNotFoundException { + return new UnifyResultModel(); + } + public List typeInference() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java index 05433287..a79e34ec 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java @@ -1,16 +1,18 @@ package de.dhbwstuttgart.typeinference.unify; +import java.util.List; + import de.dhbwstuttgart.typeinference.result.ResultSet; public class UnifyResultEvent { - private ResultSet newTypeResult; + private List newTypeResult; - public UnifyResultEvent(ResultSet newTypeResult) { + public UnifyResultEvent(List newTypeResult) { this.newTypeResult = newTypeResult; } - public ResultSet getNewTypeResult() { + public List getNewTypeResult() { return newTypeResult; } } From 3c0beabc1b1a27855b9279a250be07fccb2399d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 25 Jan 2019 22:19:32 +0100 Subject: [PATCH 02/15] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java reduce2 nochmals angepasst modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java - Fehler behoben - In den Thread nur noch Element von nextSet verschieben, die auf alle Faele berechnet werdne muessen --- .../typeinference/unify/RuleSet.java | 3 +- .../typeinference/unify/TypeUnifyTask.java | 47 +++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index a3430577..a8c0675d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -326,7 +326,8 @@ public class RuleSet implements IRuleSet{ lhsSType = (ReferenceType) lhsType; rhsSType = (ReferenceType) rhsType; } - else if ((lhsType instanceof WildcardType) && (rhsType instanceof WildcardType)) { + else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType)) + || ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) { UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType(); UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType(); if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8b2c7c3c..da3d508b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -810,6 +810,23 @@ public class TypeUnifyTask extends RecursiveTask>> { nextSetasListRest.remove(a_next); } } + //Alle maximale Elemente in nextSetasListRest bestimmen + List> nextSetasListRestTest; + do { + nextSetasListRestTest = new ArrayList>(nextSetasListRest); + if (!nextSetasListRest.isEmpty()) { + Set max = oup.max(nextSetasListRest.iterator()); + Iterator> nextSetasListItRest2 = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest2.hasNext()) { + Set a_nextRest = nextSetasListItRest2.next(); + if (//a.equals(a_next) || + (oup.compare(max, a_nextRest) == 1)) { + nextSetasListRest.remove(a_nextRest); + } + + }} + } while(!nextSetasListRestTest.equals(nextSetasListRest)); + } else if (variance == -1) { a = oup.min(nextSetasList.iterator()); @@ -823,6 +840,23 @@ public class TypeUnifyTask extends RecursiveTask>> { nextSetasListRest.remove(a_next); } } + //Alle minimalen Elemente in nextSetasListRest bestimmen + + List> nextSetasListRestTest; + do { + nextSetasListRestTest = new ArrayList>(nextSetasListRest); + if (!nextSetasListRest.isEmpty()) { + Set min = oup.min(nextSetasListRest.iterator()); + Iterator> nextSetasListItRest2 = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest2.hasNext()) { + Set a_nextRest = nextSetasListItRest2.next(); + if (//a.equals(a_next) || + (oup.compare(min, a_nextRest) == -1)) { + nextSetasListRest.remove(a_nextRest); + } + + }} + } while(!nextSetasListRestTest.equals(nextSetasListRest)); } else if (variance == 2) { a = nextSetasList.remove(0); @@ -1860,13 +1894,17 @@ public class TypeUnifyTask extends RecursiveTask>> { for(UnifyType c : csPHRenamed) { //PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt. - Set thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new)); + Set thetaQs = new HashSet<>(); + //TODO smaller wieder reinnehmen? + //thetaQs.add(c);// + thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new)); //Set thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new)); //thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert, //da children offensichtlich ein echtes kleiner und kein kleinergleich ist //PL 18-02-06: eingefuegt, thetaQs der Form V> <. V'> werden entfernt + //TODO PL 19-01-14 wieder reinnehmen kurzfristig auskommentiert thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new)); //PL 18-02-06: eingefuegt @@ -1931,13 +1969,16 @@ public class TypeUnifyTask extends RecursiveTask>> { if(allGen) { UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); - while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor + while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance());//((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } else { UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); - while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); + distributeVariance dv = new distributeVariance(); + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor + while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance()); //((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } resultPrime.addAll(substitutionSet); From 9dcb1f76cab606a7356b4baaa3a5590d8a9fb427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 25 Jan 2019 22:22:16 +0100 Subject: [PATCH 03/15] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java --- .../de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java index a5919c18..dc600939 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -17,7 +17,7 @@ public class UnifyResultModel { listeners.remove(listenerToRemove); } - public void notify(ResultSet newResult) { + public void notify(Set newResult) { UnifyResultEvent evt = new UnifyResultEvent(newResult); for (UnifyResultListener listener : listeners) { From 26634bb03842b55e9884b85c01d65ceb911e310e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 25 Jan 2019 22:26:38 +0100 Subject: [PATCH 04/15] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java --- .../de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java index dc600939..fe72bfea 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; import java.util.List; +import java.util.Set; import de.dhbwstuttgart.typeinference.result.ResultSet; @@ -17,7 +18,7 @@ public class UnifyResultModel { listeners.remove(listenerToRemove); } - public void notify(Set newResult) { + public void notify(List newResult) { UnifyResultEvent evt = new UnifyResultEvent(newResult); for (UnifyResultListener listener : listeners) { From ca7c76a99af59c6fc6eb3fd6886c6721391e258e Mon Sep 17 00:00:00 2001 From: Pluemicke Martin Date: Tue, 29 Jan 2019 14:47:20 +0100 Subject: [PATCH 05/15] =?UTF-8?q?=09ge=C3=A4ndert:=20=20=20=20=20=20=20src?= =?UTF-8?q?/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java=20=09ge?= =?UTF-8?q?=C3=A4ndert:=20=20=20=20=20=20=20src/main/java/de/dhbwstuttgart?= =?UTF-8?q?/typeinference/constraints/ConstraintSet.java=20=09ge=C3=A4nder?= =?UTF-8?q?t:=20=20=20=20=20=20=20src/main/java/de/dhbwstuttgart/typeinfer?= =?UTF-8?q?ence/constraints/Pair.java=20=09ge=C3=A4ndert:=20=20=20=20=20?= =?UTF-8?q?=20=20src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUn?= =?UTF-8?q?ify.java=20=09ge=C3=A4ndert:=20=20=20=20=20=20=20src/main/java/?= =?UTF-8?q?de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java=20=09g?= =?UTF-8?q?e=C3=A4ndert:=20=20=20=20=20=20=20src/main/java/de/dhbwstuttgar?= =?UTF-8?q?t/typeinference/unify/TypeUnifyTask.java=20=09ge=C3=A4ndert:=20?= =?UTF-8?q?=20=20=20=20=20=20src/main/java/de/dhbwstuttgart/typeinference/?= =?UTF-8?q?unify/UnifyResultModel.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 24 +++++------------ .../constraints/ConstraintSet.java | 1 + .../typeinference/constraints/Pair.java | 18 +++++++++++++ .../typeinference/unify/TypeUnify.java | 19 ++++++++++--- .../typeinference/unify/TypeUnify2Task.java | 6 +++-- .../typeinference/unify/TypeUnifyTask.java | 27 ++++++++++++++++--- .../typeinference/unify/UnifyResultModel.java | 2 +- 7 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index d7915f3f..5a749dcc 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -27,6 +27,7 @@ import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; import de.dhbwstuttgart.typeinference.unify.distributeVariance; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; @@ -289,7 +290,7 @@ public class JavaTXCompiler { try { FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); - FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); + IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); @@ -402,8 +403,9 @@ public class JavaTXCompiler { } return ret; }).collect(Collectors.toCollection(ArrayList::new)); - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log); + unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); @@ -430,7 +432,7 @@ public class JavaTXCompiler { System.err.println("kein LogFile"); } return results.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); + new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()); } @@ -479,19 +481,7 @@ public class JavaTXCompiler { } - private Map generateTPHMap(ConstraintSet constraints) { - HashMap ret = new HashMap<>(); - constraints.map((Pair p) -> { - if (p.TA1 instanceof TypePlaceholder) { - ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1); - } - if (p.TA2 instanceof TypePlaceholder) { - ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2); - } - return null; - }); - return ret; - } + private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException { CompilationUnitContext tree = JavaTXParser.parse(sourceFile); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 4d1f076f..1dda8dc5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.constraints; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java index 98679f7d..0c8ad7a5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java @@ -1,7 +1,10 @@ package de.dhbwstuttgart.typeinference.constraints; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; @@ -110,5 +113,20 @@ public class Pair implements Serializable public boolean OperatorSmallerDot() { return eOperator == PairOperator.SMALLERDOT; } + + + static public Map generateTPHMap(ConstraintSet constraints) { + HashMap ret = new HashMap<>(); + constraints.map((Pair p) -> { + if (p.TA1 instanceof TypePlaceholder) { + ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1); + } + if (p.TA2 instanceof TypePlaceholder) { + ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2); + } + return null; + }); + return ret; + } } // ino.end diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index fecd28fe..aa7fe5ea 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -6,18 +6,29 @@ import java.util.Set; import java.util.concurrent.ForkJoinPool; import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0); + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, new UnifyResultModel(), cons); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { + UnifyResultModel ret = new UnifyResultModel(); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(unifyTask); + return ret; + } + /* public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); @@ -26,8 +37,8 @@ public class TypeUnify { } */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0); + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, new UnifyResultModel(), cons); Set> res = unifyTask.compute(); return res; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 95ccdf07..7c0a587d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Set; import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; @@ -13,8 +15,8 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe); + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); this.setToFlatten = setToFlatten; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8b2c7c3c..5b043b27 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -19,7 +19,10 @@ import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; @@ -59,6 +62,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Fuer die Threads */ + UnifyResultModel urm; + ConstraintSet cons; private static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; @@ -123,7 +128,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons2) { synchronized (this) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); @@ -144,6 +149,8 @@ public class TypeUnifyTask extends RecursiveTask>> { this.log = log; rules = new RuleSet(logFile); this.rekTiefeField = rekTiefe; + this.urm = urm; + this.cons = cons2; noOfThread++; totalnoOfThread++; @@ -688,6 +695,18 @@ public class TypeUnifyTask extends RecursiveTask>> { System.err.println("log-File nicht vorhanden"); } eqPrimePrimeSet.add(eqPrime); + Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { + Optional> res = new RuleSet().subst(x.stream().map(y -> { + if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); + return y; //alle Paare a <.? b erden durch a =. b ersetzt + }).collect(Collectors.toCollection(HashSet::new))); + if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert + return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc); + } + else return x; //wenn nichts veraendert wurde wird x zurueckgegeben + }).collect(Collectors.toCollection(HashSet::new)); + urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList())); } else if(eqPrimePrime.isPresent()) { Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), oderConstraints, fc, parallel, rekTiefe); @@ -901,7 +920,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -952,7 +971,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -1002,7 +1021,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java index a5919c18..fc04c8e7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -17,7 +17,7 @@ public class UnifyResultModel { listeners.remove(listenerToRemove); } - public void notify(ResultSet newResult) { + public void notify(List newResult) { UnifyResultEvent evt = new UnifyResultEvent(newResult); for (UnifyResultListener listener : listeners) { From 9e1d58f4b17e1a6ffc82971674ec6e18ac452860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 29 Jan 2019 14:51:19 +0100 Subject: [PATCH 06/15] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Threads soweit fertig --- .../typeinference/unify/TypeUnify2Task.java | 1 + .../typeinference/unify/TypeUnifyTask.java | 60 ++++++++----------- .../unify/model/FiniteClosure.java | 29 ++++++++- .../unify/model/OrderingUnifyPair.java | 2 +- 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 95ccdf07..a8f446c9 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -29,6 +29,7 @@ public class TypeUnify2Task extends TypeUnifyTask { return new HashSet<>(); } else */ + noOfThread--; return res; } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index da3d508b..acbabdd2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -59,11 +59,11 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Fuer die Threads */ - private static int noOfThread = 0; + protected static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; protected boolean one = false; - Integer MaxNoOfThreads = 4; + Integer MaxNoOfThreads = 8; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; FileWriter logFile; @@ -200,6 +200,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField); + noOfThread--; if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } @@ -891,7 +892,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); - writeLog("a1: " + rekTiefe + " "+ a.toString()+ "\n"); + writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); //elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall //im else-Zweig //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt @@ -899,28 +900,17 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { - /* - elems.add(a); - TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); - fork.fork(); - res = fork.join(); - */ - Set forks = new HashSet<>(); - - //TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); - - Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); - /* FORK ANFANG + /* FORK ANFANG */ TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); //forks.add(forkOrig); forkOrig.fork(); - FORK ENDE */ + /* FORK ENDE */ synchronized (this) { writeLog("a in " + variance + " "+ a); @@ -939,23 +929,23 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - /* FORK ANFANG + /* FORK ANFANG */ synchronized (this) { res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); }; - FORK ENDE */ + /* FORK ENDE */ for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); }; } @@ -967,11 +957,11 @@ public class TypeUnifyTask extends RecursiveTask>> { List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); - /* FORK ANFANG + /* FORK ANFANG */ TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); //forks.add(forkOrig); forkOrig.fork(); - FORK ENDE */ + /* FORK ENDE */ synchronized (this) { writeLog("a in " + variance + " "+ a); @@ -990,23 +980,23 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - /* FORK ANFANG + /* FORK ANFANG */ synchronized (this) { res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); }; - FORK ENDE */ + /* FORK ENDE */ for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); }; } @@ -1019,11 +1009,11 @@ public class TypeUnifyTask extends RecursiveTask>> { List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); - /* FORK ANFANG + /* FORK ANFANG */ TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); //forks.add(forkOrig); forkOrig.fork(); - FORK ENDE */ + /* FORK ENDE */ synchronized (this) { writeLog("a in " + variance + " "+ a); @@ -1040,23 +1030,23 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - /* FORK ANFANG + /* FORK ANFANG */ synchronized (this) { res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); //vermutlich falsch }; - FORK ENDE */ + /* FORK ENDE */ for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); }; }} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 07c86457..c52f47a7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -109,6 +109,18 @@ implements IFiniteClosure { strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key)); } } + + void testSmaller() { + UnifyType tq1, tq2, tq3; + tq1 = new ExtendsType(PlaceholderType.freshPlaceholder()); + List l1 = new ArrayList<>(); + List l2 = new ArrayList<>(); + l1.add(tq1); + tq2 = new ReferenceType("java.util.Vector", new TypeParams(l1)); + l2.add(tq2); + tq3 = new ReferenceType("java.util.Vector", new TypeParams(l2)); + Set smaller = smaller(tq3, new HashSet<>()); + } /** * Returns all types of the finite closure that are subtypes of the argument. @@ -641,8 +653,7 @@ implements IFiniteClosure { */ public int compare (UnifyType left, UnifyType right, PairOperator pairop) { - if ((left instanceof ExtendsType && right instanceof ReferenceType) - || (right instanceof ExtendsType && left instanceof ReferenceType)) + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) System.out.println(""); /* List al = new ArrayList<>(); @@ -693,6 +704,13 @@ implements IFiniteClosure { HashSet hs = new HashSet<>(); hs.add(up); Set smallerRes = unifyTask.applyTypeUnificationRules(hs, this); + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) + {try { + logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile");}} //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); if (smallerLen == 0) return -1; @@ -702,6 +720,13 @@ implements IFiniteClosure { hs = new HashSet<>(); hs.add(up); Set greaterRes = unifyTask.applyTypeUnificationRules(hs, this); + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) + {try { + logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile");}} //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); if (greaterLen == 0) return 1; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 73d73578..490826cc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -229,7 +229,7 @@ public class OrderingUnifyPair extends Ordering> { if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) { hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null)); - si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); } //4. Fall else { From aa0b1573743b0aa73b8473c7184ca7b686d6fb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 30 Jan 2019 09:11:33 +0100 Subject: [PATCH 07/15] modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java new file: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java modified: src/test/resources/bytecode/javFiles/MatrixOP.jav Erster Ansatz asyncrone Threads --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 73 +++++++++++-------- .../typeinference/unify/TypeUnify.java | 11 ++- .../typeinference/unify/TypeUnifyTask.java | 17 +++-- .../unify/UnifyResultListenerImpl.java | 21 ++++++ .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 5 files changed, 84 insertions(+), 40 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 5a749dcc..b9d1da90 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -34,6 +34,7 @@ import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; +import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl; import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; import java.io.File; @@ -50,6 +51,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; + Boolean resultmodel = true; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -403,37 +405,50 @@ public class JavaTXCompiler { } return ret; }).collect(Collectors.toCollection(ArrayList::new)); - unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); - System.out.println("RESULT: " + result); - logFile.write("RES: " + result.toString()+"\n"); - logFile.flush(); - results.addAll(result); + if (resultmodel) { + /* UnifyResultModel Anfang */ + UnifyResultModel urm = new UnifyResultModel(); + UnifyResultListenerImpl li = new UnifyResultListenerImpl(); + urm.addUnifyResultListener(li); + unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm); + System.out.println("RESULT Final: " + li.getResults()); + logFile.write("RES_FINAL: " + li.getResults().toString()+"\n"); + logFile.flush(); + return li.getResults(); + } + /* UnifyResultModel End */ + else { + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + System.out.println("RESULT: " + result); + logFile.write("RES: " + result.toString()+"\n"); + logFile.flush(); + results.addAll(result); - results = results.stream().map(x -> { - Optional> res = new RuleSet().subst(x.stream().map(y -> { - if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); - return y; //alle Paare a <.? b erden durch a =. b ersetzt - }).collect(Collectors.toCollection(HashSet::new))); - if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert - return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); - } - else return x; //wenn nichts veraendert wurde wird x zurueckgegeben - }).collect(Collectors.toCollection(HashSet::new)); - System.out.println("RESULT Final: " + results); - logFile.write("RES_FINAL: " + results.toString()+"\n"); - logFile.flush(); - logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); - logFile.flush(); - } - catch (IOException e) { - System.err.println("kein LogFile"); - } - return results.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()); - } + results = results.stream().map(x -> { + Optional> res = new RuleSet().subst(x.stream().map(y -> { + if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); + return y; //alle Paare a <.? b erden durch a =. b ersetzt + }).collect(Collectors.toCollection(HashSet::new))); + if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert + return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); + } + else return x; //wenn nichts veraendert wurde wird x zurueckgegeben + }).collect(Collectors.toCollection(HashSet::new)); + System.out.println("RESULT Final: " + results); + logFile.write("RES_FINAL: " + results.toString()+"\n"); + logFile.flush(); + logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); + logFile.flush(); + }} + catch (IOException e) { + System.err.println("kein LogFile"); + } + return results.stream().map((unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()); + } + /** diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index aa7fe5ea..d1fc2afe 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -21,14 +21,21 @@ public class TypeUnify { return res; } - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { - UnifyResultModel ret = new UnifyResultModel(); + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); return ret; } + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(unifyTask); + Set> res = unifyTask.join(); + return ret; + } + /* public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 904959bb..d8588ae4 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -926,7 +926,7 @@ public class TypeUnifyTask extends RecursiveTask>> { 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, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -977,7 +977,7 @@ public class TypeUnifyTask extends RecursiveTask>> { 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, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1029,7 +1029,7 @@ public class TypeUnifyTask extends RecursiveTask>> { 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, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1878,12 +1878,13 @@ public class TypeUnifyTask extends RecursiveTask>> { allGen = false; break; } - //if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 - // && thetaPrime instanceof ReferenceType - // && ((ReferenceType)thetaPrime).getTypeParams().iterator().next().getName().equals("java.util.Vector") + if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 + && thetaPrime instanceof ReferenceType + && ((ReferenceType)thetaPrime).getTypeParams().iterator().next().getName().equals("java.util.Vector")) // && ((ReferenceType)((ReferenceType)thetaPrime).getTypeParams().iterator().next()).getTypeParams().iterator().next().getName().equals("java.lang.Integer")) { - // System.out.println(""); - //} + { + System.out.println(""); + } Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java new file mode 100644 index 00000000..16133a3f --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java @@ -0,0 +1,21 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.List; + +import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; + +public class UnifyResultListenerImpl implements UnifyResultListener { + + List results = new ArrayList<>(); + + public void onNewTypeResultFound(UnifyResultEvent evt) { + results.addAll(evt.getNewTypeResult()); + } + + public List getResults() { + return results; + } + +} diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index c78c42c7..828a270b 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.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 MatrixOP extends Vector> { From 33f2bf3d217a94a16f43d82cb167bb419736bbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 31 Jan 2019 15:08:36 +0100 Subject: [PATCH 08/15] modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java Asynchrone Variante soweit ok --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 133 +++++++++++++++++- .../typeinference/unify/TypeUnifyTask.java | 16 +-- .../unify/UnifyResultListenerImpl.java | 2 +- 3 files changed, 141 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index b9d1da90..2c19d8b3 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -275,7 +275,138 @@ public class JavaTXCompiler { */ public UnifyResultModel typeInferenceAsync() throws ClassNotFoundException { - return new UnifyResultModel(); + List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); + //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC + for(SourceFile sf : this.sourceFiles.values()) { + allClasses.addAll(getAvailableClasses(sf)); + allClasses.addAll(sf.getClasses()); + } + + final ConstraintSet cons = getConstraints(); + Set> results = new HashSet<>(); + UnifyResultModel urm = new UnifyResultModel(); + try { + FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + + IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); + System.out.println(finiteClosure); + ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); + + Function distributeInnerVars = + x -> { + UnifyType lhs, rhs; + if (((lhs = x.getLhsType()) instanceof PlaceholderType) + && ((rhs = x.getRhsType()) instanceof PlaceholderType) + && (((PlaceholderType)lhs).isInnerType() + || ((PlaceholderType)rhs).isInnerType())) + { + ((PlaceholderType)lhs).setInnerType(true); + ((PlaceholderType)rhs).setInnerType(true); + } + return x; + + }; + logFile.write(unifyCons.toString()); + unifyCons = unifyCons.map(distributeInnerVars); + logFile.write(unifyCons.toString()); + TypeUnify unify = new TypeUnify(); + //Set> results = new HashSet<>(); Nach vorne gezogen + logFile.write("FC:\\" + finiteClosure.toString()+"\n"); + for(SourceFile sf : this.sourceFiles.values()) { + logFile.write(ASTTypePrinter.print(sf)); + } + logFile.flush(); + + Set methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist() + .stream().filter(z -> z.getType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} ); + + Set constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist() + .stream().filter(z -> z.getType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} ); + + Set paraTypeVarNames = methodParaTypeVarNames; + paraTypeVarNames.addAll(constructorParaTypeVarNames); + + + Set returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get(); + + Set fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get(); + + returnTypeVarNames.addAll(fieldTypeVarNames); + + unifyCons = unifyCons.map(x -> { + //Hier muss ueberlegt werden, ob + //1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs + // mit disableWildcardtable() werden. + //2. alle Typvariablen mit Argument- oder Retuntyp-Variablen + //in Beziehung auch auf disableWildcardtable() gesetzt werden muessen + //PL 2018-04-23 + if ((x.getLhsType() instanceof PlaceholderType)) { + if (paraTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + } + if (returnTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + } + } + if ((x.getRhsType() instanceof PlaceholderType)) { + if (paraTypeVarNames.contains(x.getRhsType().getName())) { + ((PlaceholderType)x.getRhsType()).setVariance((byte)1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); + } + if (returnTypeVarNames.contains(x.getRhsType().getName())) { + ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); + } + } + return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE + }); + Set varianceTPHold; + Set varianceTPH = new HashSet<>(); + varianceTPH = varianceInheritanceConstraintSet(unifyCons); + + /* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt + do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen + //anderen Seite übertragen + varianceTPHold = new HashSet<>(varianceTPH); + varianceTPH = varianceInheritanceConstraintSet(unifyCons); + unifyCons.map( y -> { + if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { + if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) { + ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance()); + } + if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { + ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance()); + } + } + return y; } ); } + while (!varianceTPHold.equals(varianceTPH)); + */ + + //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> result = unify.unify(xConsSet, finiteClosure); + List>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> { + Set> ret = new HashSet<>(); + for (Constraint y : x) { + ret.add(new HashSet<>(y)); + } + return ret; + }).collect(Collectors.toCollection(ArrayList::new)); + unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm); + } + catch (IOException e) { + System.err.println("kein LogFile"); + } + return urm; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index d8588ae4..eb81e200 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -1878,13 +1878,13 @@ public class TypeUnifyTask extends RecursiveTask>> { allGen = false; break; } - if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 - && thetaPrime instanceof ReferenceType - && ((ReferenceType)thetaPrime).getTypeParams().iterator().next().getName().equals("java.util.Vector")) + //if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 + // && thetaPrime instanceof ReferenceType + // && ((ReferenceType)thetaPrime).getTypeParams().iterator().next() instanceof PlaceholderType) //.getName().equals("java.util.Vector")) // && ((ReferenceType)((ReferenceType)thetaPrime).getTypeParams().iterator().next()).getTypeParams().iterator().next().getName().equals("java.lang.Integer")) { - { - System.out.println(""); - } + // { + // System.out.println(""); + //} Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] @@ -1979,7 +1979,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if(allGen) { UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); - //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance());//((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } @@ -1987,7 +1987,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); distributeVariance dv = new distributeVariance(); - //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance()); //((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java index 16133a3f..ea34728b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java @@ -10,7 +10,7 @@ public class UnifyResultListenerImpl implements UnifyResultListener { List results = new ArrayList<>(); - public void onNewTypeResultFound(UnifyResultEvent evt) { + public synchronized void onNewTypeResultFound(UnifyResultEvent evt) { results.addAll(evt.getNewTypeResult()); } From e52181a0c7325fecf329a3c5c7e31f48f767be28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 4 Feb 2019 23:32:52 +0100 Subject: [PATCH 09/15] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../resources/bytecode/javFiles/Matrix.jav --- .../typeinference/unify/TypeUnify2Task.java | 7 +- .../typeinference/unify/TypeUnifyTask.java | 87 ++++++++++++------- .../resources/bytecode/javFiles/Matrix.jav | 2 +- 3 files changed, 63 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 6916f6dc..cdc1e040 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -15,9 +15,14 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); this.setToFlatten = setToFlatten; + this.nextSetElement = nextSetElement; + } + + Set getNextSetElement() { + return nextSetElement; } @Override diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index eb81e200..1e762b8a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -59,6 +59,11 @@ public class TypeUnifyTask extends RecursiveTask>> { private boolean printtag = false; Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? + /** + * Element, das aus dem nextSet den Gleichunen dieses Threads hinzugefuegt wurde + */ + Set nextSetElement; + /** * Fuer die Threads */ @@ -142,6 +147,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); + this.nextSetElement = nextSetElement; this.fc = fc; this.oup = new OrderingUnifyPair(fc); this.parallel = parallel; @@ -918,15 +924,16 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("Vor unify2 Aufruf: " + elems.toString()); Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); + Set> aParDef = new HashSet<>(); if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { - Set forks = new HashSet<>(); + Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -944,7 +951,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -960,24 +967,27 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ - for(TypeUnifyTask fork : forks) { + for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); + if (!isUndefinedPairSetSet(fork_res)) { + aParDef.add(fork.getNextSetElement()); + } }; } } else { if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { - Set forks = new HashSet<>(); + Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -995,7 +1005,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -1011,12 +1021,15 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ - for(TypeUnifyTask fork : forks) { + for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); + if (!isUndefinedPairSetSet(fork_res)) { + aParDef.add(fork.getNextSetElement()); + } }; } } else { @@ -1029,7 +1042,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1045,7 +1058,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -1230,18 +1243,24 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == 1)) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); + writeLog("aParDef: " + aParDef.toString()); + aParDef.add(a); + Iterator> aParDefIt = aParDef.iterator(); + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a_new.equals(a_next) || + (oup.compare(a_new, a_next) == 1)) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); + } + else { + writeLog("Not Removed: " + a_next.toString()); + System.out.println(""); + } } - else { - writeLog("Not Removed: " + a_next.toString()); - System.out.println(""); - } - } + } } else { if (variance == -1) { /* vorgezogen vor das if @@ -1272,19 +1291,25 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == -1)) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); //PL geaendert 2019-01-09 - } - else { - System.out.println(""); - writeLog("Not Removed: " + a_next.toString()); + writeLog("aParDef: " + aParDef.toString()); + aParDef.add(a); + Iterator> aParDefIt = aParDef.iterator(); + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a_new.equals(a_next) || + (oup.compare(a_new, a_next) == -1)) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); //PL geaendert 2019-01-09 + } + else { + System.out.println(""); + writeLog("Not Removed: " + a_next.toString()); } } } + } else { if (variance == 0) { writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); break; } diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 29505161..9e87c1e6 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -import java.lang.Float; +//import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; From db91e737500bb400ec6d25d02d871a4a31128b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 6 Feb 2019 18:15:39 +0100 Subject: [PATCH 10/15] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java aParDef wird auch ausgewertet modified: src/test/resources/bytecode/javFiles/MatrixOP.jav --- .../typeinference/unify/TypeUnifyTask.java | 21 +++++++++++-------- .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1e762b8a..5a3d4862 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -692,15 +692,14 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst //eqPrimePrime Veraenderungen in subst repraesentieren. - try { + //try { if (isSolvedForm(eqPrime)) { - logFile.write("eqPrime:" + eqPrime.toString()+"\n"); - logFile.flush(); + writeLog("eqPrime:" + eqPrime.toString()+"\n"); } - } - catch (IOException e) { + //} + //catch (IOException e) { System.err.println("log-File nicht vorhanden"); - } + //} eqPrimePrimeSet.add(eqPrime); Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { Optional> res = new RuleSet().subst(x.stream().map(y -> { @@ -971,7 +970,9 @@ public class TypeUnifyTask extends RecursiveTask>> { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben + //noOfThread--; an das Ende von compute verschoben + writeLog("fork_res: " + fork_res.toString()); + writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); add_res.add(fork_res); if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); @@ -1026,6 +1027,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben + writeLog("fork_res: " + fork_res.toString()); + writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); add_res.add(fork_res); if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); @@ -1209,7 +1212,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ - if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { + if (!result.isEmpty() && (!isUndefinedPairSetSet(res) || !aParDef.isEmpty())) { if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); @@ -1343,7 +1346,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ - if (isUndefinedPairSetSet(res)) { + if (isUndefinedPairSetSet(res) && aParDef.isEmpty()) { int nofstred= 0; Set abhSubst = res.stream() .map(b -> diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 828a270b..c78c42c7 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.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 MatrixOP extends Vector> { From 396efb52de12c53413c7eb3bfccb138fbb051f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 15 Feb 2019 00:00:41 +0100 Subject: [PATCH 11/15] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java subst-Anwendung auf oderconstraints eingebaut --- .../typeinference/unify/RuleSet.java | 30 +++++++++++++++++-- .../typeinference/unify/TypeUnifyTask.java | 5 +++- .../unify/interfaces/IRuleSet.java | 8 +++++ .../resources/bytecode/javFiles/Matrix.jav | 2 +- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index a8c0675d..bd35376d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -4,10 +4,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Optional; import java.util.Queue; import java.util.Set; import java.util.Stack; +import java.util.function.Function; import java.util.stream.Collectors; import de.dhbwstuttgart.exceptions.DebugException; @@ -619,8 +621,12 @@ public class RuleSet implements IRuleSet{ return succ ? permutation : new int[0]; } - @Override public Optional> subst(Set pairs) { + return subst(pairs, new ArrayList<>()); + } + + @Override + public Optional> subst(Set pairs, List>> oderConstraints) { HashMap typeMap = new HashMap<>(); Stack occuringTypes = new Stack<>(); @@ -664,9 +670,29 @@ public class RuleSet implements IRuleSet{ Unifier uni = new Unifier(lhsType, rhsType); result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); + + Function,? extends HashSet> applyUni = b -> b.stream().map( + x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new)); + List>> oderConstraintsRet = new ArrayList<>(); + for(Set> oc : oderConstraints) { + //Set> ocRet = new HashSet<>(); + //for(Set cs : oc) { + Set> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)); + oderConstraintsRet.add(csRet); + //} + } + oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); + /* + oderConstraints = oderConstraints.stream().map( + a -> a.stream().map(applyUni + //b -> b.stream().map( + // x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new) ) + ).collect(Collectors.toCollection(HashSet::new)) + ).collect(Collectors.toList(ArrayList::new)); + } + */ applied = true; } - result.add(pair); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 5a3d4862..59dd208a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -656,9 +656,12 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 5: Substitution */ //writeLog("vor Subst: " + eqPrime); - Optional> eqPrimePrime = rules.subst(eqPrime); + writeLog("vor Subst: " + oderConstraints); + String ocString = oderConstraints.toString(); + Optional> eqPrimePrime = rules.subst(eqPrime, oderConstraints); Set> unifyres1 = null; Set> unifyres2 = null; + if (!ocString.equals(oderConstraints.toString())) writeLog("nach Subst: " + oderConstraints); //writeLog("nach Subst: " + eqPrimePrime); /* * Step 6 a) Restart (fork) for pairs where subst was applied diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java index a2b647c6..1ed46cb0 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.interfaces; +import java.util.List; import java.util.Optional; import java.util.Set; @@ -85,6 +86,13 @@ public interface IRuleSet { public Optional adaptExt(UnifyPair pair, IFiniteClosure fc); public Optional adaptSup(UnifyPair pair, IFiniteClosure fc); + /** + * Applies the subst-Rule to a set of pairs (usually Eq'). + * @param pairs The set of pairs where the subst rule should apply. + * @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions. + */ + public Optional> subst(Set pairs, List>> oderConstraints); + /** * Applies the subst-Rule to a set of pairs (usually Eq'). * @param pairs The set of pairs where the subst rule should apply. diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 9e87c1e6..29505161 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Float; +import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; From 08d69ce6e385d3ec707e279a7b170dc946b52536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 17 Feb 2019 08:51:23 +0100 Subject: [PATCH 12/15] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java zurueckumwandlung von den Unifytypen in UnifyResultModel verlegt. --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 13 ++-- .../typeinference/unify/TypeUnify.java | 59 +++++++++++++--- .../typeinference/unify/TypeUnify2Task.java | 4 +- .../typeinference/unify/TypeUnifyTask.java | 68 ++++++++++++------- .../typeinference/unify/UnifyResultModel.java | 33 ++++++++- .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 6 files changed, 136 insertions(+), 43 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 2c19d8b3..1dfa1163 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -284,12 +284,13 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); - UnifyResultModel urm = new UnifyResultModel(); + UnifyResultModel urm = null; try { FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); + urm = new UnifyResultModel(cons, finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); Function distributeInnerVars = @@ -401,7 +402,7 @@ public class JavaTXCompiler { } return ret; }).collect(Collectors.toCollection(ArrayList::new)); - unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm); + unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm); } catch (IOException e) { System.err.println("kein LogFile"); @@ -538,10 +539,10 @@ public class JavaTXCompiler { }).collect(Collectors.toCollection(ArrayList::new)); if (resultmodel) { /* UnifyResultModel Anfang */ - UnifyResultModel urm = new UnifyResultModel(); + UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure); UnifyResultListenerImpl li = new UnifyResultListenerImpl(); urm.addUnifyResultListener(li); - unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm); + unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm); System.out.println("RESULT Final: " + li.getResults()); logFile.write("RES_FINAL: " + li.getResults().toString()+"\n"); logFile.flush(); @@ -549,8 +550,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index d1fc2afe..75012b64 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -13,23 +13,56 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, new UnifyResultModel(), cons); + + /** + * unify parallel ohne result modell + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @return + */ + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); + /** + * unify asynchron mit Rückgabe UnifyResultModel ohne dass alle results gesammelt sind + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @param ret + * @return + */ + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); return ret; } - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); + /** + * unify parallel mit Rückgabe UnifyResultModel nachdem alle results gesammelt sind + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @param ret + * @return + */ + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -44,8 +77,18 @@ public class TypeUnify { } */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, new UnifyResultModel(), cons); + /** + * unify sequentiell mit oderconstraints + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @return + */ + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret); Set> res = unifyTask.compute(); return res; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index cdc1e040..0ed9fb5c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -15,8 +15,8 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 59dd208a..1f5dec47 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -68,7 +68,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * Fuer die Threads */ UnifyResultModel urm; - ConstraintSet cons; + //ConstraintSet cons; protected static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; @@ -133,7 +133,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons2) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { synchronized (this) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); @@ -153,16 +153,21 @@ public class TypeUnifyTask extends RecursiveTask>> { this.parallel = parallel; this.logFile = logFile; this.log = log; + + noOfThread++; + totalnoOfThread++; + //writeLog("thNo1 " + thNo); + thNo = totalnoOfThread; + writeLog("thNo2 " + thNo); + try { + this.logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo)); + } + catch (IOException e) { + System.err.println("log-File nicht vorhanden"); + } rules = new RuleSet(logFile); this.rekTiefeField = rekTiefe; this.urm = urm; - this.cons = cons2; - - noOfThread++; - totalnoOfThread++; - writeLog("thNo1 " + thNo); - thNo = totalnoOfThread; - writeLog("thNo2 " + thNo); } } @@ -658,10 +663,11 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("vor Subst: " + eqPrime); writeLog("vor Subst: " + oderConstraints); String ocString = oderConstraints.toString(); - Optional> eqPrimePrime = rules.subst(eqPrime, oderConstraints); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + Optional> eqPrimePrime = rules.subst(eqPrime, newOderConstraints); Set> unifyres1 = null; Set> unifyres2 = null; - if (!ocString.equals(oderConstraints.toString())) writeLog("nach Subst: " + oderConstraints); + if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints); //writeLog("nach Subst: " + eqPrimePrime); /* * Step 6 a) Restart (fork) for pairs where subst was applied @@ -714,16 +720,17 @@ public class TypeUnifyTask extends RecursiveTask>> { } else return x; //wenn nichts veraendert wurde wird x zurueckgegeben }).collect(Collectors.toCollection(HashSet::new)); - urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList())); + urm.notify(eqPrimePrimeSetRet); + //urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs -> + // new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList())); } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), oderConstraints, fc, parallel, rekTiefe); + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unifyres2 = unify(eqPrime, oderConstraints, fc, parallel, rekTiefe); + Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe); eqPrimePrimeSet.addAll(unifyres); @@ -935,7 +942,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -953,7 +960,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm); forks.add(fork); fork.fork(); } @@ -961,6 +968,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); @@ -969,6 +978,7 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ + forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -981,7 +991,8 @@ public class TypeUnifyTask extends RecursiveTask>> { aParDef.add(fork.getNextSetElement()); } }; - } + } + noOfThread++; } else { if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { Set forks = new HashSet<>(); @@ -991,7 +1002,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1009,7 +1020,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm); forks.add(fork); fork.fork(); } @@ -1017,6 +1028,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); @@ -1025,6 +1038,7 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ + forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -1038,6 +1052,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } }; } + noOfThread++; } else { if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { writeLog("var2einstieg"); @@ -1048,7 +1063,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1064,7 +1079,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm); forks.add(fork); fork.fork(); } @@ -1072,6 +1087,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); @@ -1079,7 +1096,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //add_res.add(fork_res); //vermutlich falsch }; /* FORK ENDE */ - + forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -1087,8 +1104,9 @@ public class TypeUnifyTask extends RecursiveTask>> { //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); }; - }} - else { + } + noOfThread++; + } else { //parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java index fe72bfea..7a4f0ccf 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -1,13 +1,31 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class UnifyResultModel { + ConstraintSet cons; + + IFiniteClosure fc; + + public UnifyResultModel(ConstraintSet cons, + IFiniteClosure fc) { + this.cons = cons; + this.fc = fc; + } + private List listeners = new ArrayList<>(); public void addUnifyResultListener(UnifyResultListener listenerToAdd) { @@ -18,7 +36,20 @@ public class UnifyResultModel { listeners.remove(listenerToRemove); } - public void notify(List newResult) { + public void notify(Set> eqPrimePrimeSet) { + Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { + Optional> res = new RuleSet().subst(x.stream().map(y -> { + if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); + return y; //alle Paare a <.? b erden durch a =. b ersetzt + }).collect(Collectors.toCollection(HashSet::new))); + if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert + return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc); + } + else return x; //wenn nichts veraendert wurde wird x zurueckgegeben + }).collect(Collectors.toCollection(HashSet::new)); + List newResult = eqPrimePrimeSetRet.stream().map(unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons)))) + .collect(Collectors.toList()); UnifyResultEvent evt = new UnifyResultEvent(newResult); for (UnifyResultListener listener : listeners) { diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index c78c42c7..828a270b 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.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 MatrixOP extends Vector> { From 1f12aaec8213e48f099450fba0f57a812d9b88b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 18 Feb 2019 22:36:06 +0100 Subject: [PATCH 13/15] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Einen Fall ? extends/super a <.? a ergaenzt bei dem compare falsches Ergbnis geliefret hat --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +-- .../typeinference/unify/RuleSet.java | 8 +++- .../typeinference/unify/TypeUnifyTask.java | 18 ++------ .../unify/model/FiniteClosure.java | 19 +++++++-- .../unify/model/OrderingUnifyPair.java | 42 ++++++++++++++++++- 5 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 1dfa1163..bc2265bf 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -51,7 +51,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; - Boolean resultmodel = true; + Boolean resultmodel = false; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -550,8 +550,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index bd35376d..2e77b787 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -666,7 +666,9 @@ public class RuleSet implements IRuleSet{ if(lhsType != null //&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden. && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair. - && !rhsType.getTypeParams().occurs(lhsType)) { + && !rhsType.getTypeParams().occurs(lhsType) + && !((rhsType instanceof WildcardType) && ((WildcardType)rhsType).getWildcardedType().equals(lhsType))) //PL eigefuegt 2018-02-18 + { Unifier uni = new Unifier(lhsType, rhsType); result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); @@ -971,6 +973,8 @@ public class RuleSet implements IRuleSet{ UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType(); + if (extendedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? extends a <.? a + boolean isGen = extendedType instanceof PlaceholderType && !((PlaceholderType) extendedType).isGenerated(); Set result = new HashSet<>(); @@ -997,6 +1001,8 @@ public class RuleSet implements IRuleSet{ UnifyType superedType = ((SuperType)lhsType).getSuperedType(); + if (superedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? super a <.? a + boolean isGen = superedType instanceof PlaceholderType && !((PlaceholderType) superedType).isGenerated(); Set result = new HashSet<>(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1f5dec47..d726544e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -68,7 +68,6 @@ public class TypeUnifyTask extends RecursiveTask>> { * Fuer die Threads */ UnifyResultModel urm; - //ConstraintSet cons; protected static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; @@ -553,6 +552,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Add the set of [a =. Theta | (a=. Theta) in Eq2'] + //TODO: Occurscheck anwenden als Fehler identifizieren Set bufferSet = eq2s.stream() .filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType) .collect(Collectors.toSet()); @@ -707,22 +707,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } //} //catch (IOException e) { - System.err.println("log-File nicht vorhanden"); + // System.err.println("log-File nicht vorhanden"); //} eqPrimePrimeSet.add(eqPrime); - Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { - Optional> res = new RuleSet().subst(x.stream().map(y -> { - if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); - return y; //alle Paare a <.? b erden durch a =. b ersetzt - }).collect(Collectors.toCollection(HashSet::new))); - if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert - return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc); - } - else return x; //wenn nichts veraendert wurde wird x zurueckgegeben - }).collect(Collectors.toCollection(HashSet::new)); - urm.notify(eqPrimePrimeSetRet); - //urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs -> - // new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList())); + urm.notify(eqPrimePrimeSet); } else if(eqPrimePrime.isPresent()) { Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index c52f47a7..d0497823 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -12,6 +12,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; import java.util.function.BinaryOperator; +import java.util.function.Predicate; import java.util.stream.Collectors; import com.google.common.collect.Ordering; @@ -656,11 +657,16 @@ implements IFiniteClosure { if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) System.out.println(""); /* + pairop = PairOperator.SMALLERDOTWC; List al = new ArrayList<>(); PlaceholderType xx =new PlaceholderType("xx"); al.add(xx); left = new ExtendsType(new ReferenceType("Vector", new TypeParams(al))); - right = new ReferenceType("Vector", new TypeParams(new ArrayList<>(al))); + + List alr = new ArrayList<>(); + UnifyType exx = new ExtendsType(xx); + alr.add(exx); + right = new ExtendsType(new ReferenceType("Vector", new TypeParams(alr))); */ /* List al = new ArrayList<>(); @@ -711,8 +717,13 @@ implements IFiniteClosure { } catch (IOException e) { System.err.println("no LogFile");}} - //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. - long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); + //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. + Predicate delFun = x -> !((x.getLhsType() instanceof PlaceholderType || + x.getRhsType() instanceof PlaceholderType) + && !((x.getLhsType() instanceof WildcardType) && //? extends/super a <.? a + ((WildcardType)x.getLhsType()).getWildcardedType().equals(x.getRhsType())) + ); + long smallerLen = smallerRes.stream().filter(delFun).count(); if (smallerLen == 0) return -1; else { up = new UnifyPair(right, left, pairop); @@ -728,7 +739,7 @@ implements IFiniteClosure { catch (IOException e) { System.err.println("no LogFile");}} //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. - long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); + long greaterLen = greaterRes.stream().filter(delFun).count(); if (greaterLen == 0) return 1; else return 0; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 490826cc..28da9a80 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.function.BinaryOperator; @@ -115,6 +116,43 @@ public class OrderingUnifyPair extends Ordering> { * @see com.google.common.collect.Ordering#compare(java.lang.Object, java.lang.Object) */ public int compare (Set left, Set right) { + /* + //pairop = PairOperator.SMALLERDOTWC; + List al = new ArrayList<>(); + PlaceholderType xx = PlaceholderType.freshPlaceholder(); + al.add(xx); + UnifyType t1 = new ExtendsType(new ReferenceType("Vector", new TypeParams(al))); + + //PlaceholderType yy =new PlaceholderType("yy"); + List alr = new ArrayList<>(); + UnifyType exx = new ExtendsType(xx); + alr.add(exx); + UnifyType t2 = new ExtendsType(new ReferenceType("Vector", new TypeParams(alr))); + + PlaceholderType a = PlaceholderType.freshPlaceholder(); + a.setInnerType(true); + UnifyPair p1 = new UnifyPair(a, t1, PairOperator.SMALLERDOTWC); + PlaceholderType b = PlaceholderType.freshPlaceholder(); + b.setInnerType(true); + UnifyPair p2 = new UnifyPair(b, t2, PairOperator.SMALLERDOTWC); + + List al3 = new ArrayList<>(); + al3.add(a); + + List al4 = new ArrayList<>(); + al4.add(b); + + UnifyPair p3 = new UnifyPair(new PlaceholderType("c"), new ReferenceType("Vector", new TypeParams(al3)), PairOperator.EQUALSDOT); + UnifyPair p4 = new UnifyPair(new PlaceholderType("c"), new ReferenceType("Vector", new TypeParams(al4)), PairOperator.EQUALSDOT); + + right = new HashSet<>(); + right.add(p1); + right.add(p3); + left = new HashSet<>(); + left.add(p2); + left.add(p4); + */ + if ((left.size() == 1) && right.size() == 1) { if (left.iterator().next().getLhsType().getName().equals("AFS")) { System.out.println(""); @@ -198,9 +236,9 @@ public class OrderingUnifyPair extends Ordering> { //Set varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); //Set varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); //filtern des Paares a = Theta, das durch a <. Thata' generiert wurde (nur im Fall 1 relevant) andere Substitutioen werden rausgefiltert - lefteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + lefteq.removeIf(x -> (x.getBasePair()!=null) && !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//removeIf(x -> !varsright.contains(x.getLhsType())); - righteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + righteq.removeIf(x -> (x.getBasePair()!=null) && !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//.removeIf(x -> !varsleft.contains(x.getLhsType())); UnifyPair lseq = lefteq.iterator().next(); UnifyPair rseq = righteq.iterator().next(); From 362e797b100f30541090dcff55aae6a2df32bdfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 19 Feb 2019 17:51:11 +0100 Subject: [PATCH 14/15] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +++--- .../de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index bc2265bf..1dfa1163 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -51,7 +51,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; - Boolean resultmodel = false; + Boolean resultmodel = true; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -550,8 +550,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index d726544e..3feed6cc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -959,6 +959,7 @@ public class TypeUnifyTask extends RecursiveTask>> { noOfThread--; writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); + forkOrig.writeLog("final Orig 1"); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -978,6 +979,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); } + fork.writeLog("final 1"); }; } noOfThread++; @@ -1019,6 +1021,7 @@ public class TypeUnifyTask extends RecursiveTask>> { noOfThread--; writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); + forkOrig.writeLog("final Orig -1"); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1038,6 +1041,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); } + fork.writeLog("final -1"); }; } noOfThread++; @@ -1078,6 +1082,7 @@ public class TypeUnifyTask extends RecursiveTask>> { noOfThread--; writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); + forkOrig.writeLog("final Orig 2"); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1091,6 +1096,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); + fork.writeLog("final 2"); }; } noOfThread++; From 72705ac8689aa3d283d170e673ca6663b9676ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Feb 2019 09:40:06 +0100 Subject: [PATCH 15/15] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java close log-Files TypeUnifyTask in TypeUnify2Task bei Abarbeitung oderconstraints umgetauscht --- .../typeinference/unify/TypeUnify2Task.java | 14 +++++++++++++- .../typeinference/unify/TypeUnifyTask.java | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 0ed9fb5c..43b294ad 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; +import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -37,6 +38,17 @@ public class TypeUnify2Task extends TypeUnifyTask { else */ noOfThread--; - return res; + return res; + } + + public void closeLogFile() { + + try { + logFile.close(); + } + catch (IOException ioE) { + System.err.println("no log-File" + thNo); + } + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 3feed6cc..c9dcbcaa 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -218,6 +218,12 @@ public class TypeUnifyTask extends RecursiveTask>> { .collect(Collectors.toCollection(ArrayList::new)); Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField); noOfThread--; + try { + logFile.close(); + } + catch (IOException ioE) { + System.err.println("no log-File"); + } if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } @@ -960,6 +966,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); forkOrig.writeLog("final Orig 1"); + forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -980,6 +987,7 @@ public class TypeUnifyTask extends RecursiveTask>> { aParDef.add(fork.getNextSetElement()); } fork.writeLog("final 1"); + fork.closeLogFile(); }; } noOfThread++; @@ -1022,6 +1030,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); forkOrig.writeLog("final Orig -1"); + forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1042,13 +1051,14 @@ public class TypeUnifyTask extends RecursiveTask>> { aParDef.add(fork.getNextSetElement()); } fork.writeLog("final -1"); + fork.closeLogFile(); }; } noOfThread++; } else { if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { writeLog("var2einstieg"); - Set forks = new HashSet<>(); + Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); @@ -1083,6 +1093,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); forkOrig.writeLog("final Orig 2"); + forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1090,13 +1101,14 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ forks.forEach(x -> writeLog("wait: " + x.thNo)); - for(TypeUnifyTask fork : forks) { + for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); fork.writeLog("final 2"); + fork.closeLogFile(); }; } noOfThread++;