pipe execution

This commit is contained in:
Florian Steurer 2016-04-22 15:45:20 +02:00
parent 6eb7f2d1bb
commit 752723020e

View File

@ -3,7 +3,6 @@ package de.dhbwstuttgart.typeinference.unify;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
@ -11,7 +10,6 @@ import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; 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.ISetOperations;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; 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.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.SuperType; 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.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
/** /**
@ -49,10 +47,6 @@ public class TypeUnify {
*/ */
protected IRuleSet rules = new RuleSet(); 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. * Computes all principal type unifiers for a set of constraints.
* @param eq The set of constraints * @param eq The set of constraints
@ -138,64 +132,30 @@ public class TypeUnify {
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
//System.out.println(result); //System.out.println(result);
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
// Flatten the cartesian product // Flatten the cartesian product
// TODO parallelisierung möglich (scheint sich nicht zu lohnen) // TODO parallelisierung möglich (scheint sich nicht zu lohnen)
Set<Set<UnifyPair>> eqPrimeSetFlat = new HashSet<>();
for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) { for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) {
Set<UnifyPair> buffer = new HashSet<>(); Set<UnifyPair> eqPrime = new HashSet<>();
setToFlatten.stream().forEach(x -> buffer.addAll(x)); setToFlatten.stream().forEach(x -> eqPrime.addAll(x));
eqPrimeSetFlat.add(buffer);
}
/* /*
* Step 5: Substitution * Step 5: Substitution
*/ */
Set<Set<UnifyPair>> restartSet = new HashSet<>();
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
if(parallel) {
Set<Set<UnifyPair>> restartSetSync = Collections.synchronizedSet(restartSet);
Set<Set<UnifyPair>> eqPrimePrimeSetSync = Collections.synchronizedSet(eqPrimePrimeSet);
eqPrimeSetFlat.parallelStream().forEach(eqPrime -> {
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime); Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
if (eqPrime.equals(eq))
eqPrimePrimeSetSync.add(eqPrime);
else if(eqPrimePrime.isPresent())
restartSetSync.add(eqPrimePrime.get());
else
restartSetSync.add(eqPrime);
});
}
else {
for(Set<UnifyPair> eqPrime : eqPrimeSetFlat) {
Optional<Set<UnifyPair>> 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 * Step 6 a) Restart for pairs where subst was applied
* b) Build the union over everything * b) Build the union over everything
*/ */
// TODO parallelisierung möglich (lohnt sich vermutlich) if (eqPrime.equals(eq))
eqPrimePrimeSet.add(eqPrime);
if(parallel) { else if(eqPrimePrime.isPresent())
Set<Set<UnifyPair>> eqPrimePrimeSetSync = Collections.synchronizedSet(eqPrimePrimeSet); eqPrimePrimeSet.addAll(this.unify(eqPrimePrime.get(), fc));
restartSet.parallelStream().forEach( x -> eqPrimePrimeSetSync.addAll(unify(x, fc))); else
} eqPrimePrimeSet.addAll(this.unify(eqPrime, fc));
else {
for(Set<UnifyPair> eqss : restartSet)
eqPrimePrimeSet.addAll(this.unify(eqss, fc));
} }
/* /*