pipe execution
This commit is contained in:
parent
6eb7f2d1bb
commit
752723020e
@ -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<Set<UnifyPair>> eqPrimeSetFlat = new HashSet<>();
|
||||
for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) {
|
||||
Set<UnifyPair> buffer = new HashSet<>();
|
||||
setToFlatten.stream().forEach(x -> buffer.addAll(x));
|
||||
eqPrimeSetFlat.add(buffer);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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);
|
||||
// Flatten the cartesian product
|
||||
// TODO parallelisierung möglich (scheint sich nicht zu lohnen)
|
||||
for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) {
|
||||
Set<UnifyPair> eqPrime = new HashSet<>();
|
||||
setToFlatten.stream().forEach(x -> eqPrime.addAll(x));
|
||||
|
||||
/*
|
||||
* Step 5: Substitution
|
||||
*/
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||
|
||||
eqPrimeSetFlat.parallelStream().forEach(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);
|
||||
});
|
||||
|
||||
/*
|
||||
* 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<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
|
||||
* b) Build the union over everything
|
||||
*/
|
||||
// TODO parallelisierung möglich (lohnt sich vermutlich)
|
||||
|
||||
if(parallel) {
|
||||
Set<Set<UnifyPair>> eqPrimePrimeSetSync = Collections.synchronizedSet(eqPrimePrimeSet);
|
||||
restartSet.parallelStream().forEach( x -> eqPrimePrimeSetSync.addAll(unify(x, fc)));
|
||||
}
|
||||
else {
|
||||
for(Set<UnifyPair> eqss : restartSet)
|
||||
eqPrimePrimeSet.addAll(this.unify(eqss, fc));
|
||||
}
|
||||
|
||||
/*
|
||||
* Step 7: Filter empty sets;
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user