From 752723020ecefcb856944186b0c5437ef34a59e7 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Fri, 22 Apr 2016 15:45:20 +0200 Subject: [PATCH] pipe execution --- .../typeinference/unify/TypeUnify.java | 88 +++++-------------- 1 file changed, 24 insertions(+), 64 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 031576d9..5d51f137 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -3,7 +3,6 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -11,7 +10,6 @@ import java.util.List; import java.util.Map.Entry; import java.util.Optional; import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -19,13 +17,13 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.SuperType; -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.TypeParams; import de.dhbwstuttgart.typeinference.unify.model.Unifier; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; /** @@ -49,10 +47,6 @@ public class TypeUnify { */ protected IRuleSet rules = new RuleSet(); - // Scheint momentan eher zu verlangsamen, vermutlich zu viele threads, - // threadpool und task-queue einbauen und minimale problemgröße für neuen thread - protected boolean parallel = false; - /** * Computes all principal type unifiers for a set of constraints. * @param eq The set of constraints @@ -138,66 +132,32 @@ public class TypeUnify { .collect(Collectors.toCollection(HashSet::new)); //System.out.println(result); - // Flatten the cartesian product - // TODO parallelisierung möglich (scheint sich nicht zu lohnen) - Set> eqPrimeSetFlat = new HashSet<>(); - for(Set> setToFlatten : eqPrimeSet) { - Set buffer = new HashSet<>(); - setToFlatten.stream().forEach(x -> buffer.addAll(x)); - eqPrimeSetFlat.add(buffer); - } - - - /* - * Step 5: Substitution - */ - Set> restartSet = new HashSet<>(); Set> eqPrimePrimeSet = new HashSet<>(); - - if(parallel) { - Set> restartSetSync = Collections.synchronizedSet(restartSet); - Set> eqPrimePrimeSetSync = Collections.synchronizedSet(eqPrimePrimeSet); + // Flatten the cartesian product + // TODO parallelisierung möglich (scheint sich nicht zu lohnen) + for(Set> setToFlatten : eqPrimeSet) { + Set eqPrime = new HashSet<>(); + setToFlatten.stream().forEach(x -> eqPrime.addAll(x)); + + /* + * Step 5: Substitution + */ + Optional> eqPrimePrime = rules.subst(eqPrime); - eqPrimeSetFlat.parallelStream().forEach(eqPrime -> { - Optional> eqPrimePrime = rules.subst(eqPrime); - - if (eqPrime.equals(eq)) - eqPrimePrimeSetSync.add(eqPrime); - else if(eqPrimePrime.isPresent()) - restartSetSync.add(eqPrimePrime.get()); - else - restartSetSync.add(eqPrime); - }); + + /* + * Step 6 a) Restart for pairs where subst was applied + * b) Build the union over everything + */ + if (eqPrime.equals(eq)) + eqPrimePrimeSet.add(eqPrime); + else if(eqPrimePrime.isPresent()) + eqPrimePrimeSet.addAll(this.unify(eqPrimePrime.get(), fc)); + else + eqPrimePrimeSet.addAll(this.unify(eqPrime, fc)); } - else { - for(Set eqPrime : eqPrimeSetFlat) { - Optional> eqPrimePrime = rules.subst(eqPrime); - - if (eqPrime.equals(eq)) - eqPrimePrimeSet.add(eqPrime); - else if(eqPrimePrime.isPresent()) - restartSet.add(eqPrimePrime.get()); - else - restartSet.add(eqPrime); - } - } - - /* - * Step 6 a) Restart for pairs where subst was applied - * b) Build the union over everything - */ - // TODO parallelisierung möglich (lohnt sich vermutlich) - if(parallel) { - Set> eqPrimePrimeSetSync = Collections.synchronizedSet(eqPrimePrimeSet); - restartSet.parallelStream().forEach( x -> eqPrimePrimeSetSync.addAll(unify(x, fc))); - } - else { - for(Set eqss : restartSet) - eqPrimePrimeSet.addAll(this.unify(eqss, fc)); - } - /* * Step 7: Filter empty sets; */