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.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,66 +132,32 @@ public class TypeUnify {
|
|||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
//System.out.println(result);
|
//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<>();
|
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||||
|
|
||||||
|
// Flatten the cartesian product
|
||||||
if(parallel) {
|
// TODO parallelisierung möglich (scheint sich nicht zu lohnen)
|
||||||
Set<Set<UnifyPair>> restartSetSync = Collections.synchronizedSet(restartSet);
|
for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) {
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSetSync = Collections.synchronizedSet(eqPrimePrimeSet);
|
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);
|
/*
|
||||||
|
* Step 6 a) Restart for pairs where subst was applied
|
||||||
if (eqPrime.equals(eq))
|
* b) Build the union over everything
|
||||||
eqPrimePrimeSetSync.add(eqPrime);
|
*/
|
||||||
else if(eqPrimePrime.isPresent())
|
if (eqPrime.equals(eq))
|
||||||
restartSetSync.add(eqPrimePrime.get());
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
else
|
else if(eqPrimePrime.isPresent())
|
||||||
restartSetSync.add(eqPrime);
|
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;
|
* Step 7: Filter empty sets;
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user