From 6ce9f4415e915af7deda3f980b8ce4cac63af942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 18 Oct 2018 23:47:38 +0200 Subject: [PATCH 01/14] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 155 ++++++++++++++++++ .../constraints/ConstraintSet.java | 18 ++ 2 files changed, 173 insertions(+) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index c09c90b01..7884b85fb 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -215,6 +215,118 @@ public class JavaTXCompiler { new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); } + + public List typeInferenceNew() throws ClassNotFoundException { + 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(); + + FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); + System.out.println(finiteClosure); + ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); + + TypeUnify unify = new TypeUnify(); + Set> results = new HashSet<>(); + try { + FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log")); + logFile.write("FC:\\" + finiteClosure.toString()+"\n"); + for(SourceFile sf : this.sourceFiles.values()) { + logFile.write(ASTTypePrinter.print(sf)); + } + logFile.flush(); + Set>> cardProd = unifyCons.cartesianProduct(); + for (List> xCons : cardProd ){ + Set xConsSet = new HashSet<>(); + for (Constraint constraint : xCons) { + xConsSet.addAll(constraint); + } + //.collect(Collectors.toCollection(ArrayList::new)))) + System.out.println(xConsSet); + Set paraTypeVarNames = 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 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 + }).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; } ); + varianceInheritanceConstrainSet(unifyCons); + Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> result = unify.unify(xConsSet, finiteClosure); + 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(); + } + catch (IOException e) { } + return results.stream().map((unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); + } + /** * Vererbt alle Variancen * @param eq The set of constraints @@ -245,6 +357,49 @@ public class JavaTXCompiler { phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } } + + /** + * Vererbt alle Variancen + * @param eq The set of constraints + */ + private void varianceInheritanceConstrainSet(ConstraintSet cons) { + Set eq = cons.getAll(); + Set usedTPH = new HashSet<>(); + Set phSet = eq.stream().map(x -> { + Set pair = new HashSet<>(); + if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); + if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType()); + return pair; + }).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;}); + + ArrayList phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0)); + while(!phSetVariance.isEmpty()) { + PlaceholderType a = phSetVariance.remove(0); + usedTPH.add(a); + //HashMap ht = new HashMap<>(); + //ht.put(a, a.getVariance()); + //ConstraintSet eq1 = cons; + //eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); + //durch if-Abfrage im foreach geloest + cons.forEach(x -> { + if (x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)) { + x.getRhsType().accept(new distributeVariance(), a.getVariance()); + } + }); + //` eq1 = new HashSet<>(eq); + //eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); + //durch if-Abfrage im foreach geloest + cons.forEach(x -> { + if (x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)) { + x.getLhsType().accept(new distributeVariance(), a.getVariance()); + } + }); + //phSetVariance = new ArrayList<>(phSet); macht vermutlich keinen Sinn PL 2018-10-18 + //phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); + } + } + private Map generateTPHMap(ConstraintSet constraints) { HashMap ret = new HashMap<>(); diff --git a/src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 01356fe9a..09984d28c 100644 --- a/src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -5,6 +5,7 @@ import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import java.util.*; +import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -52,4 +53,21 @@ public class ConstraintSet { ret.oderConstraints = newOder; return ret; } + + public void forEach (Consumer c) { + undConstraints.stream().forEach(c); + for(Set> oderConstraint : oderConstraints){ + oderConstraint.parallelStream().forEach((Constraint as) -> + as.stream().forEach(c)); + } + } + + public Set getAll () { + Set ret = new HashSet<>(); + ret.addAll(undConstraints); + for(Set> oderConstraint : oderConstraints){ + oderConstraint.parallelStream().forEach((Constraint as) -> ret.addAll(as)); + } + return ret; + } } From 6a87f443e4b5989a37296737d30097930b066a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 19 Oct 2018 13:08:37 +0200 Subject: [PATCH 02/14] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 122 ++++---- .../constraints/ConstraintSet.java | 8 + .../typeinference/unify/TypeUnify.java | 8 + .../typeinference/unify/TypeUnifyTask.java | 269 +++++++++++++++++- 4 files changed, 343 insertions(+), 64 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 7884b85fb..f984d8c8d 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -239,75 +239,69 @@ public class JavaTXCompiler { logFile.write(ASTTypePrinter.print(sf)); } logFile.flush(); - Set>> cardProd = unifyCons.cartesianProduct(); - for (List> xCons : cardProd ){ - Set xConsSet = new HashSet<>(); - for (Constraint constraint : xCons) { - xConsSet.addAll(constraint); - } - //.collect(Collectors.toCollection(ArrayList::new)))) - System.out.println(xConsSet); - Set paraTypeVarNames = 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 returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) + Set paraTypeVarNames = 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 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) + 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); + 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(); - } + 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 ((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(); - } + if (returnTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } - return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE - }).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; } ); - varianceInheritanceConstrainSet(unifyCons); - Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); - //Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result); - logFile.write("RES: " + result.toString()+"\n"); - logFile.flush(); - results.addAll(result); - } - + } + 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 + }).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; } ); + varianceInheritanceConstrainSet(unifyCons); + //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> result = unify.unify(xConsSet, finiteClosure); + Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), unifyCons.getOderConstraints(), finiteClosure, logFile, log); + 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); @@ -328,7 +322,8 @@ public class JavaTXCompiler { } /** - * Vererbt alle Variancen + * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) + * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. * @param eq The set of constraints */ private void varianceInheritance(Set eq) { @@ -359,7 +354,8 @@ public class JavaTXCompiler { } /** - * Vererbt alle Variancen + * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) + * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. * @param eq The set of constraints */ private void varianceInheritanceConstrainSet(ConstraintSet cons) { diff --git a/src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 09984d28c..4d1f076f3 100644 --- a/src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -70,4 +70,12 @@ public class ConstraintSet { } return ret; } + + public List>> getOderConstraints() { + return oderConstraints; + } + + public Set getUndConstraints() { + return undConstraints; + } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index fa190cb7f..d2428defc 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,9 +1,11 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; +import java.util.List; import java.util.Set; import java.util.concurrent.ForkJoinPool; +import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; @@ -21,5 +23,11 @@ public class TypeUnify { Set> res = unifyTask.compute(); return res; } + + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log); + Set> res = unifyTask.compute(); + return res; + } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 7864ece1b..7af531e6e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -18,6 +18,7 @@ import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; +import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; @@ -71,7 +72,9 @@ public class TypeUnifyTask extends RecursiveTask>> { */ protected IRuleSet rules; - protected Set eq; + protected Set eq; //und-constraints + + protected List>> oderConstraints; protected IFiniteClosure fc; @@ -101,6 +104,25 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(logFile); } + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) { + 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)); + this.oderConstraints = oderConstraints.stream().map(x -> { + Set> ret = new HashSet<>(); + for (Constraint y : x) { + ret.add(new HashSet<>(y)); + } + return ret; + }).collect(Collectors.toCollection(ArrayList::new)); + + //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); + this.fc = fc; + this.oup = new OrderingUnifyPair(fc); + this.parallel = parallel; + this.logFile = logFile; + this.log = log; + rules = new RuleSet(logFile); + } /** * Vererbt alle Variancen @@ -141,6 +163,251 @@ public class TypeUnifyTask extends RecursiveTask>> { else return res; } + protected Set> computeNew() { + Set> fstElems = new HashSet<>(); + fstElems.add(eq); + Set> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel); + if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } + else return res; + } + + public Set> computeCartesianRecursiveOderConstraints(Set> fstElems, List>> topLevelSets, IFiniteClosure fc, boolean parallel) { + //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); + fstElems.addAll(topLevelSets.stream() + .filter(x -> x.size()==1) + .map(y -> y.stream().findFirst().get()) + .collect(Collectors.toCollection(HashSet::new))); + ArrayList>> remainingSets = topLevelSets.stream() + .filter(x -> x.size()>1) + .collect(Collectors.toCollection(ArrayList::new)); + if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig + Set eq = new HashSet<>(); + fstElems.stream().forEach(x -> eq.addAll(x)); + Set> result = unify(eq, fc, parallel); + return result; + } + Set> nextSet = remainingSets.remove(0); + writeLog("nextSet: " + nextSet.toString()); + List> nextSetasList =new ArrayList<>(nextSet); + try { + //List> + //nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); + } + catch (java.lang.IllegalArgumentException e) { + System.out.print(""); + } + Set> result = new HashSet<>(); + int variance = 0; + Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) + .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) + .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) + .reduce((a,b)-> {if (a==b) return a; else return 0; })) + .filter(d -> d.isPresent()) + .map(e -> e.get()) + .findAny(); + if (xi.isPresent()) { + variance = xi.get(); + } + //if (variance == 1 && nextSetasList.size() > 1) { + // List> al = new ArrayList<>(nextSetasList.size()); + // for (int ii = 0; ii < nextSetasList.size();ii++) { + // al.add(0,nextSetasList.get(ii)); + // } + // nextSetasList = al; + //} + //Set a = nextSetasListIt.next(); + /*if (nextSetasList.size()>1) {zu loeschen + if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) + System.out.print(""); + if (variance == 1) { + a_next = oup.max(nextSetasList.iterator()); + } + else if (variance == -1) { + a_next = oup.min(nextSetasList.iterator()); + } + else if (variance == 0) { + a_next = nextSetasList.iterator().next(); + } + } + else { + a_next = nextSetasList.iterator().next(); + } + */ + if (!nextSetasList.iterator().hasNext()) + System.out.print(""); + if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) + System.out.print(""); + writeLog("nextSetasList: " + nextSetasList.toString()); + while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { + Set a = null; + if (variance == 1) { + a = oup.max(nextSetasList.iterator()); + nextSetasList.remove(a); + } + else if (variance == -1) { + a = oup.min(nextSetasList.iterator()); + nextSetasList.remove(a); + } + else if (variance == 0) { + a = nextSetasList.remove(0); + } + //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); + //nextSetasList.remove(a); + /* zu loeschen + if (nextSetasList.size() > 0) { + if (nextSetasList.size()>1) { + if (variance == 1) { + a_next = oup.max(nextSetasList.iterator()); + } + else if (variance == -1) { + a_next = oup.min(nextSetasList.iterator()); + } + else { + a_next = nextSetasList.iterator().next(); + } + } + else { + a_next = nextSetasList.iterator().next(); + } + } + */ + //PL 2018-03-01 + //TODO: 1. Maximum und Minimum unterscheiden + //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern + //for(Set a : newSet) { + i++; + Set> elems = new HashSet>(fstElems); + elems.add(a); + if (remainingSets.isEmpty()) { + writeLog("Vor unify Aufruf: " + eq.toString()); + Set eq = new HashSet<>(); + fstElems.stream().forEach(x -> eq.addAll(x)); + Set> res = unify(eq, fc, parallel); + if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = res; + } + else { + if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + result.addAll(res); + } + //else { + //wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren + // if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) { + // result = result; + // } + //} + } + + + /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ + if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { + if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) + System.out.print(""); + Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); + if (variance == 1) { + System.out.println(""); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a.equals(a_next) || + (oup.compare(a, a_next) == 1)) { + nextSetasList.remove(a_next); + } + else { + System.out.println(""); + } + } + } + else { if (variance == -1) { + System.out.println(""); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a.equals(a_next) || + (oup.compare(a, a_next) == -1)) { + nextSetasList.remove(0); + } + else { + System.out.println(""); + } + } + } + else if (variance == 0) { + break; + }} + } + /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ + + if (isUndefinedPairSetSet(res)) { + int nofstred= 0; + Set abhSubst = res.stream() + .map(b -> + b.stream() + .map(x -> x.getAllSubstitutions()) + .reduce((y,z) -> { y.addAll(z); return y;}).get()) + .reduce((y,z) -> { y.addAll(z); return y;}).get(); + Set b = a;//effective final a + Set durchschnitt = abhSubst.stream() + .filter(x -> b.contains(x)) + //.filter(y -> abhSubst.contains(y)) + .collect(Collectors.toCollection(HashSet::new)); + //Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + int len = nextSetasList.size(); + Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results + Set, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream() + .map(x -> { Set su = x.getAllSubstitutions(); //alle benutzten Substitutionen + su.add(x.getGroundBasePair()); // urspruengliches Paar + su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen + return new Pair<>(su, x.getGroundBasePair());}) + .collect(Collectors.toCollection(HashSet::new)); + if (res.size() > 1) { + System.out.println(); + } + nextSetasList = nextSetasList.stream().filter(x -> { + //Boolean ret = false; + //for (PlaceholderType var : vars) { + // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); + //} + return (!x.containsAll(durchschnitt)); + })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10 + .collect(Collectors.toCollection(ArrayList::new)); + nofstred = nextSetasList.size(); + //NOCH NICHT korrekt PL 2018-10-12 + //nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) + // .collect(Collectors.toCollection(ArrayList::new)); + writeLog("res (undef): " + res.toString()); + writeLog("abhSubst: " + abhSubst.toString()); + writeLog("a: " + a.toString()); + writeLog("Durchschnitt: " + durchschnitt.toString()); + writeLog("nextSet: " + nextSet.toString()); + writeLog("nextSetasList: " + nextSetasList.toString()); + writeLog("Number first erased Elements (undef): " + (len - nofstred)); + writeLog("Number second erased Elements (undef): " + (nofstred- nextSetasList.size())); + writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); + noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); + writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString()); + noBacktracking++; + writeLog("Number of Backtracking: " + noBacktracking); + System.out.println(""); + } + //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { + // return result; + //} + //else { + // result.removeIf(y -> isUndefinedPairSet(y)); + //} + //else result.stream().filter(y -> !isUndefinedPairSet(y)); + } + else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 + result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); + } + return result; + } + } + + /** * Computes all principal type unifiers for a set of constraints. * @param eq The set of constraints From 225f380735ab78f71e05334c707dd0c599e62ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 19 Oct 2018 16:09:59 +0200 Subject: [PATCH 03/14] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java letzte Version bevor computeCartesianRecursiveOderConstraints aktiviert wird --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 7af531e6e..4ed9f8fbc 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -399,12 +399,13 @@ public class TypeUnifyTask extends RecursiveTask>> { // result.removeIf(y -> isUndefinedPairSet(y)); //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); - } + } // End of if (remainingSets.isEmpty()) else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } return result; - } + } // End of while (nextSetasList.size() > 0) + return null; //kann nicht erreicht werden, da der Fall bei dem nextSet == empty bereits am Anfang abgefangen wird } From 6dce7058a00dde7125213a5e0bbb16fe5acbb8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 19 Oct 2018 16:24:00 +0200 Subject: [PATCH 04/14] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java typeInference <-> typeInferenceOld modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java compute <-> computeOld --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 74 ++++++++++--------- .../typeinference/unify/TypeUnifyTask.java | 9 ++- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index f984d8c8d..74bb67c60 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -103,7 +103,7 @@ public class JavaTXCompiler { return new ArrayList<>(allClasses); } - public List typeInference() throws ClassNotFoundException { + public List typeInferenceOld() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf : this.sourceFiles.values()) { @@ -215,8 +215,41 @@ public class JavaTXCompiler { new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); } + /** + * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) + * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. + * @param eq The set of constraints + */ + private void varianceInheritance(Set eq) { + Set usedTPH = new HashSet<>(); + Set phSet = eq.stream().map(x -> { + Set pair = new HashSet<>(); + if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); + if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType()); + return pair; + }).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;}); + + ArrayList phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0)); + while(!phSetVariance.isEmpty()) { + PlaceholderType a = phSetVariance.remove(0); + usedTPH.add(a); + //HashMap ht = new HashMap<>(); + //ht.put(a, a.getVariance()); + Set eq1 = new HashSet<>(eq); + eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); + eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());}); + eq1 = new HashSet<>(eq); + eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); + eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); + phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); + } + } + - public List typeInferenceNew() throws ClassNotFoundException { + + public List typeInference() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf : this.sourceFiles.values()) { @@ -292,7 +325,7 @@ public class JavaTXCompiler { } } return y; } ); - varianceInheritanceConstrainSet(unifyCons); + varianceInheritanceConstraintSet(unifyCons); //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); //Set> result = unify.unify(xConsSet, finiteClosure); Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), unifyCons.getOderConstraints(), finiteClosure, logFile, log); @@ -321,44 +354,13 @@ public class JavaTXCompiler { new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); } - /** - * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) - * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. - * @param eq The set of constraints - */ - private void varianceInheritance(Set eq) { - Set usedTPH = new HashSet<>(); - Set phSet = eq.stream().map(x -> { - Set pair = new HashSet<>(); - if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); - if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType()); - return pair; - }).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;}); - - ArrayList phSetVariance = new ArrayList<>(phSet); - phSetVariance.removeIf(x -> (x.getVariance() == 0)); - while(!phSetVariance.isEmpty()) { - PlaceholderType a = phSetVariance.remove(0); - usedTPH.add(a); - //HashMap ht = new HashMap<>(); - //ht.put(a, a.getVariance()); - Set eq1 = new HashSet<>(eq); - eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); - eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());}); - eq1 = new HashSet<>(eq); - eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); - eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); - phSetVariance = new ArrayList<>(phSet); - phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); - } - } - + /** * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. * @param eq The set of constraints */ - private void varianceInheritanceConstrainSet(ConstraintSet cons) { + private void varianceInheritanceConstraintSet(ConstraintSet cons) { Set eq = cons.getAll(); Set usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x -> { diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 4ed9f8fbc..24900e58a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -156,14 +156,15 @@ public class TypeUnifyTask extends RecursiveTask>> { } } */ - @Override - protected Set> compute() { + + protected Set> computeOld() { Set> res = unify(eq, fc, parallel); if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } - protected Set> computeNew() { + @Override + protected Set> compute() { Set> fstElems = new HashSet<>(); fstElems.add(eq); Set> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel); @@ -401,7 +402,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //else result.stream().filter(y -> !isUndefinedPairSet(y)); } // End of if (remainingSets.isEmpty()) else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 - result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); + result.addAll(computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel)); } return result; } // End of while (nextSetasList.size() > 0) From 141194c983db65f8c7ca3a5ea708d6d1e4828aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 19 Oct 2018 17:36:23 +0200 Subject: [PATCH 05/14] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java erste version mit computeCartesianRecursiveOderConstraints aktiviert Fehler bei durchschnitt leer wird Element geloescht. --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 24900e58a..94487f9c6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -371,7 +371,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //for (PlaceholderType var : vars) { // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); //} - return (!x.containsAll(durchschnitt)); + return (!x.containsAll(durchschnitt));//Was passiert wenn durchschnitt leer ist?? })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10 .collect(Collectors.toCollection(ArrayList::new)); nofstred = nextSetasList.size(); From d7e59ecdc7899b964ff1dcb0473d403d310d73d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 20 Oct 2018 17:42:44 +0200 Subject: [PATCH 06/14] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Erste Version mit Recursiv oder modified: ../bytecode/javFiles/Matrix.jav --- .../typeinference/unify/TypeUnifyTask.java | 26 +++++++++++++------ test/bytecode/javFiles/Matrix.jav | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 94487f9c6..866c16639 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -88,6 +88,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Integer noAllErasedElements = 0; + static Integer noou = 0; + static int noBacktracking; public TypeUnifyTask() { @@ -279,11 +281,20 @@ public class TypeUnifyTask extends RecursiveTask>> { i++; Set> elems = new HashSet>(fstElems); elems.add(a); + Set> res = new HashSet<>(); if (remainingSets.isEmpty()) { + noou++; writeLog("Vor unify Aufruf: " + eq.toString()); + writeLog("No of Unify " + noou); + System.out.println(noou); Set eq = new HashSet<>(); fstElems.stream().forEach(x -> eq.addAll(x)); - Set> res = unify(eq, fc, parallel); + res = unify(eq, fc, parallel); + } + else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 + res = computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel); + + } if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; @@ -301,7 +312,9 @@ public class TypeUnifyTask extends RecursiveTask>> { // result = result; // } //} - } + } + + /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ @@ -400,13 +413,10 @@ public class TypeUnifyTask extends RecursiveTask>> { // result.removeIf(y -> isUndefinedPairSet(y)); //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); - } // End of if (remainingSets.isEmpty()) - else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 - result.addAll(computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel)); - } - return result; + + } // End of while (nextSetasList.size() > 0) - return null; //kann nicht erreicht werden, da der Fall bei dem nextSet == empty bereits am Anfang abgefangen wird + return result; } diff --git a/test/bytecode/javFiles/Matrix.jav b/test/bytecode/javFiles/Matrix.jav index 6eae34288..b3857744d 100644 --- a/test/bytecode/javFiles/Matrix.jav +++ b/test/bytecode/javFiles/Matrix.jav @@ -18,7 +18,7 @@ public class Matrix extends Vector> { } } - Matrix mul(java.util.Vector> m) { + mul(m) { var ret = new Matrix(); var i = 0; while(i < size()) { From e6d8b92ffacdb7c64a8c2a2c00977c1d298b7bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 24 Oct 2018 14:05:20 +0200 Subject: [PATCH 07/14] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java kleine Fehler --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 866c16639..f969baffb 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -288,7 +288,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("No of Unify " + noou); System.out.println(noou); Set eq = new HashSet<>(); - fstElems.stream().forEach(x -> eq.addAll(x)); + elems.stream().forEach(x -> eq.addAll(x)); res = unify(eq, fc, parallel); } else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 @@ -349,7 +349,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else if (variance == 0) { - break; + //break; }} } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ From d08708878fb769e4b6383380204b9525a47293ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 5 Nov 2018 23:28:08 +0100 Subject: [PATCH 08/14] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java Variance distribut korrigiert modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Fehler im computeCartesianRecursiveOderConstraints beseitigt modified: ../bytecode/javFiles/Matrix.jav --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 32 ++++++++++++------- .../typeinference/unify/TypeUnifyTask.java | 2 ++ test/bytecode/javFiles/Matrix.jav | 4 +-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 74bb67c60..212dafad6 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -315,17 +315,24 @@ public class JavaTXCompiler { } } return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE - }).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; } ); - varianceInheritanceConstraintSet(unifyCons); + }); + Set varianceTPHold; + Set varianceTPH = new HashSet<>(); + 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); Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), unifyCons.getOderConstraints(), finiteClosure, logFile, log); @@ -360,7 +367,7 @@ public class JavaTXCompiler { * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. * @param eq The set of constraints */ - private void varianceInheritanceConstraintSet(ConstraintSet cons) { + private Set varianceInheritanceConstraintSet(ConstraintSet cons) { Set eq = cons.getAll(); Set usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x -> { @@ -396,6 +403,7 @@ public class JavaTXCompiler { //phSetVariance = new ArrayList<>(phSet); macht vermutlich keinen Sinn PL 2018-10-18 //phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } + return usedTPH; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index f969baffb..6a2ef3959 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -354,6 +354,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ + /* PL 2018-11-05 wird falsch weil es auf der obersten Ebene ist. if (isUndefinedPairSetSet(res)) { int nofstred= 0; Set abhSubst = res.stream() @@ -406,6 +407,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Number of Backtracking: " + noBacktracking); System.out.println(""); } + */ //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { // return result; //} diff --git a/test/bytecode/javFiles/Matrix.jav b/test/bytecode/javFiles/Matrix.jav index f2073b26d..295051617 100644 --- a/test/bytecode/javFiles/Matrix.jav +++ b/test/bytecode/javFiles/Matrix.jav @@ -1,8 +1,8 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Float; +import java.lang.Float; //import java.lang.Byte; -import java.lang.Boolean; +//import java.lang.Boolean; public class Matrix extends Vector> { From fc3331d810923399be4f1ed81217a192a01d66bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 6 Nov 2018 23:35:57 +0100 Subject: [PATCH 09/14] modified: src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java OderConstraints in Unify integriert --- .../typeinference/typeAlgo/TYPEStmt.java | 3 +- .../typeinference/unify/TypeUnifyTask.java | 83 ++++++++++++++----- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 609600cd1..df57fa5ec 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -228,7 +228,8 @@ public class TYPEStmt implements StatementVisitor{ binary.operation.equals(BinaryExpr.Operator.ADD)|| binary.operation.equals(BinaryExpr.Operator.SUB)){ Set> numericAdditionOrStringConcatenation = new HashSet<>(); - + - Auf importierte Typen einschraenken + - pruefen, ob die Typen richtig bestimmt werden. //Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer: //see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17 //Expression muss zu Numeric Convertierbar sein. also von Numeric erben diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 6a2ef3959..5ee0a27d3 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -159,12 +159,20 @@ public class TypeUnifyTask extends RecursiveTask>> { } */ - protected Set> computeOld() { - Set> res = unify(eq, fc, parallel); + protected Set> compute() { + Set neweq = new HashSet<>(eq); + /* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */ + oderConstraints.stream() + .filter(x -> x.size()==1) + .map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x)); + ArrayList>> remainingOderconstraints = oderConstraints.stream() + .filter(x -> x.size()>1) + .collect(Collectors.toCollection(ArrayList::new)); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel); if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } - +/* @Override protected Set> compute() { Set> fstElems = new HashSet<>(); @@ -173,7 +181,9 @@ public class TypeUnifyTask extends RecursiveTask>> { if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } - +*/ + + public Set> computeCartesianRecursiveOderConstraints(Set> fstElems, List>> topLevelSets, IFiniteClosure fc, boolean parallel) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() @@ -186,7 +196,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig Set eq = new HashSet<>(); fstElems.stream().forEach(x -> eq.addAll(x)); - Set> result = unify(eq, fc, parallel); + Set> result = unify(eq, new ArrayList<>(), fc, parallel); return result; } Set> nextSet = remainingSets.remove(0); @@ -289,7 +299,7 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(noou); Set eq = new HashSet<>(); elems.stream().forEach(x -> eq.addAll(x)); - res = unify(eq, fc, parallel); + res = unify(eq, new ArrayList<>(), fc, parallel); } else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 res = computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel); @@ -428,18 +438,21 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(Set eq, IFiniteClosure fc, boolean parallel) { + protected Set> unify(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel) { //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) // ).collect(Collectors.toCollection(HashSet::new)); //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); //if (aas.isEmpty()) { // System.out.println(""); //} + + //.collect(Collectors.toCollection(HashSet::new))); /* * Step 1: Repeated application of reduce, adapt, erase, swap */ nOfUnify++; writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); + writeLog(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString()); //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); /* @@ -505,7 +518,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set undefinedPairs = new HashSet<>(); if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); - Set>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs); + Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs); //PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer //nicht ausgewertet Faculty Beispiel im 1. Schritt //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren @@ -561,12 +574,12 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraints, fc, parallel); } - Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -634,12 +647,12 @@ public class TypeUnifyTask extends RecursiveTask>> { eqPrimePrimeSet.add(eqPrime); } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unify(eqPrimePrime.get(), fc, false); + Set> unifyres = unify(eqPrimePrime.get(), oderConstraints, fc, false); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unify(eqPrime, fc, false); + Set> unifyres = unify(eqPrime, oderConstraints, fc, false); eqPrimePrimeSet.addAll(unifyres); @@ -668,7 +681,7 @@ public class TypeUnifyTask extends RecursiveTask>> { - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, IFiniteClosure fc, boolean parallel) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -678,7 +691,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig - Set> result = unify2(fstElems, eq, fc, parallel); + Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel); return result; } Set> nextSet = remainingSets.remove(0); @@ -775,7 +788,7 @@ public class TypeUnifyTask extends RecursiveTask>> { elems.add(a); //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt //writeLog("Vor unify2 Aufruf: " + eq.toString()); - Set> res = unify2(elems, eq, fc, parallel); + Set> res = unify2(elems, eq, oderConstraints, fc, parallel); if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; @@ -1174,15 +1187,17 @@ public class TypeUnifyTask extends RecursiveTask>> { * from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements * (as in case 1 where sigma is added to the innermost set). */ - protected Set>>> calculatePairSets(Set eq2s, IFiniteClosure fc, Set undefined) { - List>>> result = new ArrayList<>(8); + protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraints, IFiniteClosure fc, Set undefined) { + List>>> result = new ArrayList<>(9); - // Init all 8 cases - for(int i = 0; i < 8; i++) + // Init all 8 cases + 9. Case: oderConstraints + for(int i = 0; i < 9; i++) result.add(new HashSet<>()); + ArrayList eq2sprime = new ArrayList<>(eq2s); Iterator eq2sprimeit = eq2sprime.iterator(); ArrayList eq2sAsList = new ArrayList<>(); + Boolean first = true; while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben UnifyPair up = eq2sprimeit.next(); if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0) @@ -1191,8 +1206,36 @@ public class TypeUnifyTask extends RecursiveTask>> { eq2s.remove(up); } } + if (eq2sAsList.isEmpty()) { + List>> oderConstraintsVariance = oderConstraints.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind + .filter(x -> x.stream() + .filter(y -> + y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getLhsType())).getVariance() != 0)) + || ((z.getRhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getRhsType())).getVariance() != 0)) + ).findFirst().isPresent() + ).findFirst().isPresent()).collect(Collectors.toList()); + if (!oderConstraintsVariance.isEmpty()) { + Set> ret = oderConstraintsVariance.get(0); + oderConstraints.remove(ret); + result.get(8).add(ret); + first = false; + } + } + eq2sAsList.addAll(eq2s); - Boolean first = true; + + if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet + if (!oderConstraints.isEmpty()) { + result.get(8).add(oderConstraints.remove(0)); + first = false; + } + } + + - Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution + hinzufuegen + for(UnifyPair pair : eq2sAsList) { PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); From 0a9e325f547a8b961134e60230392ed551170005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 7 Nov 2018 17:49:12 +0100 Subject: [PATCH 10/14] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 11 +++-- .../typeinference/typeAlgo/TYPEStmt.java | 10 ++++- .../typeinference/unify/TypeUnifyTask.java | 40 ++++++++++++------- .../typeinference/unify/model/UnifyPair.java | 9 +++++ 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 212dafad6..5387e2a11 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -318,6 +318,9 @@ public class JavaTXCompiler { }); 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); @@ -332,7 +335,9 @@ public class JavaTXCompiler { } } return y; } ); } - while (!varianceTPHold.equals(varianceTPH)); + while (!varianceTPHold.equals(varianceTPH)); + */ + //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); //Set> result = unify.unify(xConsSet, finiteClosure); Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), unifyCons.getOderConstraints(), finiteClosure, logFile, log); @@ -400,8 +405,8 @@ public class JavaTXCompiler { x.getLhsType().accept(new distributeVariance(), a.getVariance()); } }); - //phSetVariance = new ArrayList<>(phSet); macht vermutlich keinen Sinn PL 2018-10-18 - //phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); + phSetVariance = new ArrayList<>(phSet); //macht vermutlich keinen Sinn PL 2018-10-18, doch, es koennen neue TPHs mit Variancen dazugekommen sein PL 2018-11-07 + phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } return usedTPH; } diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index df57fa5ec..e06669505 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -228,8 +228,14 @@ public class TYPEStmt implements StatementVisitor{ binary.operation.equals(BinaryExpr.Operator.ADD)|| binary.operation.equals(BinaryExpr.Operator.SUB)){ Set> numericAdditionOrStringConcatenation = new HashSet<>(); - - Auf importierte Typen einschraenken - - pruefen, ob die Typen richtig bestimmt werden. + +// TODO PL 2018-11-06 + + // Auf importierte Typen einschraenken + // pruefen, ob Typen richtig bestimmt werden. + + + //Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer: //see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17 //Expression muss zu Numeric Convertierbar sein. also von Numeric erben diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 5ee0a27d3..aabd27927 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -74,7 +74,7 @@ public class TypeUnifyTask extends RecursiveTask>> { protected Set eq; //und-constraints - protected List>> oderConstraints; + protected List>> oderConstraintsField; protected IFiniteClosure fc; @@ -109,7 +109,7 @@ public class TypeUnifyTask extends RecursiveTask>> { public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) { 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)); - this.oderConstraints = oderConstraints.stream().map(x -> { + this.oderConstraintsField = oderConstraints.stream().map(x -> { Set> ret = new HashSet<>(); for (Constraint y : x) { ret.add(new HashSet<>(y)); @@ -162,10 +162,10 @@ public class TypeUnifyTask extends RecursiveTask>> { protected Set> compute() { Set neweq = new HashSet<>(eq); /* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */ - oderConstraints.stream() + oderConstraintsField.stream() .filter(x -> x.size()==1) .map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x)); - ArrayList>> remainingOderconstraints = oderConstraints.stream() + ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); Set> res = unify(neweq, remainingOderconstraints, fc, parallel); @@ -518,7 +518,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Set undefinedPairs = new HashSet<>(); if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); - Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs); + List>> oderConstraintsOutput = new ArrayList<>(oderConstraints); + Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput); //PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer //nicht ausgewertet Faculty Beispiel im 1. Schritt //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren @@ -574,7 +575,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraints, fc, parallel); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel); } @@ -859,6 +860,14 @@ public class TypeUnifyTask extends RecursiveTask>> { .map(x -> x.getAllSubstitutions()) .reduce((y,z) -> { y.addAll(z); return y;}).get()) .reduce((y,z) -> { y.addAll(z); return y;}).get(); + abhSubst.addAll( + res.stream() + .map(b -> + b.stream() + .map(x -> x.getAllBases()) + .reduce((y,z) -> { y.addAll(z); return y;}).get()) + .reduce((y,z) -> { y.addAll(z); return y;}).get() + ); Set b = a;//effective final a Set durchschnitt = abhSubst.stream() .filter(x -> b.contains(x)) @@ -1187,7 +1196,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements * (as in case 1 where sigma is added to the innermost set). */ - protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraints, IFiniteClosure fc, Set undefined) { + protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { List>>> result = new ArrayList<>(9); // Init all 8 cases + 9. Case: oderConstraints @@ -1207,7 +1216,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } if (eq2sAsList.isEmpty()) { - List>> oderConstraintsVariance = oderConstraints.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind + List>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind .filter(x -> x.stream() .filter(y -> y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType) @@ -1218,7 +1227,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ).findFirst().isPresent()).collect(Collectors.toList()); if (!oderConstraintsVariance.isEmpty()) { Set> ret = oderConstraintsVariance.get(0); - oderConstraints.remove(ret); + oderConstraintsOutput.remove(ret); result.get(8).add(ret); first = false; } @@ -1227,15 +1236,15 @@ public class TypeUnifyTask extends RecursiveTask>> { eq2sAsList.addAll(eq2s); if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet - if (!oderConstraints.isEmpty()) { - result.get(8).add(oderConstraints.remove(0)); + if (!oderConstraintsOutput.isEmpty()) { + result.get(8).add(oderConstraintsOutput.remove(0)); first = false; } } - - - Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution + /* + Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution hinzufuegen - + */ for(UnifyPair pair : eq2sAsList) { PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); @@ -1245,6 +1254,9 @@ public class TypeUnifyTask extends RecursiveTask>> { if (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); + if (((PlaceholderType)(pair.getLhsType())).getName().equals("AR")) { + System.out.println("AR"); + } Set> x1 = unifyCase1(pair, fc); if (pairOp == PairOperator.SMALLERNEQDOT) { Set remElem = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index d69138a72..729f7f4a6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -152,6 +152,15 @@ public class UnifyPair { return ret; } + public Set getAllBases () { + Set ret = new HashSet<>(); + if (basePair != null) { + ret.add(getBasePair()); + ret.addAll(basePair.getAllBases()); + } + return ret; + } + public UnifyPair getGroundBasePair () { if (basePair == null) { return this; From 3ce60eec8d87b7b1369cef70399438f5feb5e78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 12 Nov 2018 11:55:37 +0100 Subject: [PATCH 11/14] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Rekursionstife dokumentieten eingefuegt. --- .../typeinference/unify/TypeUnifyTask.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index aabd27927..bb36c5b41 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -168,7 +168,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); - Set> res = unify(neweq, remainingOderconstraints, fc, parallel); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel, 0); if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } @@ -184,7 +184,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ - public Set> computeCartesianRecursiveOderConstraints(Set> fstElems, List>> topLevelSets, IFiniteClosure fc, boolean parallel) { + public Set> computeCartesianRecursiveOderConstraints(Set> fstElems, List>> topLevelSets, IFiniteClosure fc, boolean parallel, int rekTiefe) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -196,7 +196,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig Set eq = new HashSet<>(); fstElems.stream().forEach(x -> eq.addAll(x)); - Set> result = unify(eq, new ArrayList<>(), fc, parallel); + Set> result = unify(eq, new ArrayList<>(), fc, parallel, rekTiefe); return result; } Set> nextSet = remainingSets.remove(0); @@ -299,10 +299,10 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(noou); Set eq = new HashSet<>(); elems.stream().forEach(x -> eq.addAll(x)); - res = unify(eq, new ArrayList<>(), fc, parallel); + res = unify(eq, new ArrayList<>(), fc, parallel, rekTiefe); } else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 - res = computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel); + res = computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel, rekTiefe); } if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { @@ -438,7 +438,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel) { + protected Set> unify(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) // ).collect(Collectors.toCollection(HashSet::new)); //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); @@ -450,6 +450,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 1: Repeated application of reduce, adapt, erase, swap */ + rekTiefe++; nOfUnify++; writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); writeLog(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString()); @@ -575,12 +576,12 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe); } - Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -648,12 +649,12 @@ public class TypeUnifyTask extends RecursiveTask>> { eqPrimePrimeSet.add(eqPrime); } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unify(eqPrimePrime.get(), oderConstraints, fc, false); + Set> unifyres = unify(eqPrimePrime.get(), oderConstraints, fc, false, rekTiefe); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unify(eqPrime, oderConstraints, fc, false); + Set> unifyres = unify(eqPrime, oderConstraints, fc, false, rekTiefe); eqPrimePrimeSet.addAll(unifyres); @@ -682,7 +683,7 @@ public class TypeUnifyTask extends RecursiveTask>> { - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -692,7 +693,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig - Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel); + Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe); return result; } Set> nextSet = remainingSets.remove(0); @@ -786,10 +787,11 @@ public class TypeUnifyTask extends RecursiveTask>> { //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); + writeLog("a1: " + rekTiefe + " "+ a.toString()+ "\n"); elems.add(a); //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt //writeLog("Vor unify2 Aufruf: " + eq.toString()); - Set> res = unify2(elems, eq, oderConstraints, fc, parallel); + Set> res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; @@ -899,7 +901,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // .collect(Collectors.toCollection(ArrayList::new)); writeLog("res (undef): " + res.toString()); writeLog("abhSubst: " + abhSubst.toString()); - writeLog("a: " + a.toString()); + writeLog("a2: " + rekTiefe + " " + a.toString()); writeLog("Durchschnitt: " + durchschnitt.toString()); writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); @@ -919,7 +921,10 @@ public class TypeUnifyTask extends RecursiveTask>> { // result.removeIf(y -> isUndefinedPairSet(y)); //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); + writeLog("res: " + res.toString()); } + + writeLog("Return computeCR: " + result.toString()); return result; } From e72310278da7f13bb74eee66c344dbded9d9ce77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 12 Nov 2018 17:57:51 +0100 Subject: [PATCH 12/14] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Oder-Constraints als Subsitutions zu den Substitutions der UnifyPairs hinzugefuegt. --- .../dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 9 ++++++++- .../typeinference/unify/model/UnifyPair.java | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index bb36c5b41..fa84a8d9e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -1233,6 +1233,9 @@ public class TypeUnifyTask extends RecursiveTask>> { if (!oderConstraintsVariance.isEmpty()) { Set> ret = oderConstraintsVariance.get(0); oderConstraintsOutput.remove(ret); + //Set retFlat = new HashSet<>(); + //ret.stream().forEach(x -> retFlat.addAll(x)); + ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); result.get(8).add(ret); first = false; } @@ -1242,7 +1245,11 @@ public class TypeUnifyTask extends RecursiveTask>> { if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet if (!oderConstraintsOutput.isEmpty()) { - result.get(8).add(oderConstraintsOutput.remove(0)); + Set> ret = oderConstraintsOutput.remove(0); + //Set retFlat = new HashSet<>(); + //ret.stream().forEach(x -> retFlat.addAll(x)); + ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); + result.get(8).add(ret); first = false; } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 729f7f4a6..57b4e61ed 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -121,6 +121,10 @@ public class UnifyPair { pairOp = po; } + public void addSubstitutions(Set sup) { + substitution.addAll(sup); + } + public byte getVariance() { return variance; } From 74ad081e78efebe81fecc6e60adb478669c8fc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 13 Nov 2018 14:28:33 +0100 Subject: [PATCH 13/14] modified: JavaTXCompiler.java wieder das aus uniy-test hinkopiert --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index f0dcf69db..5387e2a11 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -176,10 +176,7 @@ public class JavaTXCompiler { } } return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE - }) - /* PL 2018-11-07 wird in varianceInheritance erledigt - .map( y -> { - + }).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()); @@ -189,20 +186,16 @@ public class JavaTXCompiler { } } return y; } ) - */ .collect(Collectors.toCollection(HashSet::new)); - varianceInheritance(xConsSet); - - - - Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); - //Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result); - logFile.write("RES: " + result.toString()+"\n"); - logFile.flush(); - results.addAll(result); + varianceInheritance(xConsSet); + Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> result = unify.unify(xConsSet, finiteClosure); + 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); @@ -227,7 +220,7 @@ public class JavaTXCompiler { * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. * @param eq The set of constraints */ - private void varianceInheritance(Set eq) { + private void varianceInheritance(Set eq) { Set usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x -> { Set pair = new HashSet<>(); From 07c679a598d248d1e430c5728cbade0913681a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 13 Nov 2018 16:08:07 +0100 Subject: [PATCH 14/14] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Variance =2 eingefuehrt, wenn Variancen einer Menge unterschiedlich sind (Oer-Constraints) modified: ../bytecode/MatrixOpTest.java wieder zum Ausfuehren eingeschaltet --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 4 ++-- test/bytecode/MatrixOpTest.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index fa84a8d9e..fbf354d0e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -711,7 +711,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) - .reduce((a,b)-> {if (a==b) return a; else return 0; })) + .reduce((a,b)-> {if (a==b) return a; else return 2; })) //2 kommt insbesondere bei Oder-Constraints vor .filter(d -> d.isPresent()) .map(e -> e.get()) .findAny(); @@ -758,7 +758,7 @@ public class TypeUnifyTask extends RecursiveTask>> { a = oup.min(nextSetasList.iterator()); nextSetasList.remove(a); } - else if (variance == 0) { + else if (variance == 0 || variance == 2) { a = nextSetasList.remove(0); } //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); diff --git a/test/bytecode/MatrixOpTest.java b/test/bytecode/MatrixOpTest.java index 8fe538aaf..178aa43e5 100644 --- a/test/bytecode/MatrixOpTest.java +++ b/test/bytecode/MatrixOpTest.java @@ -32,9 +32,9 @@ public class MatrixOpTest { fileToTest = new File(path); compiler = new JavaTXCompiler(fileToTest); pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; -// compiler.generateBytecode(pathToClassFile); -// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); -// classToTest = loader.loadClass("MatrixOP"); + compiler.generateBytecode(pathToClassFile); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("MatrixOP"); /* Vector> vv = new Vector>(); Vector v1 = new Vector ();