fixed long running times for lambda tests

This commit is contained in:
Florian Steurer 2016-05-03 13:42:14 +02:00
parent 4f265b56a4
commit da49e42515
2 changed files with 48 additions and 20 deletions

View File

@ -10,20 +10,20 @@ import java.util.Set;
import java.util.Stack; import java.util.Stack;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import junit.framework.Assert;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.FunNType; import de.dhbwstuttgart.typeinference.unify.model.FunNType;
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.ReferenceType; import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
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.WildcardType;
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.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
import junit.framework.Assert;
/** /**
* Implementation of the type inference rules. * Implementation of the type inference rules.
@ -789,12 +789,18 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof PlaceholderType)) if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof PlaceholderType))
return Optional.empty(); return Optional.empty();
UnifyType freshTph = PlaceholderType.freshPlaceholder();
UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType(); UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType();
boolean isGen = extendedType instanceof PlaceholderType && !((PlaceholderType) extendedType).isGenerated();
Set<UnifyPair> result = new HashSet<>(); Set<UnifyPair> result = new HashSet<>();
result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT)); if(isGen)
result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT)); result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT));
else {
UnifyType freshTph = PlaceholderType.freshPlaceholder();
result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT));
result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT));
}
return Optional.of(result); return Optional.of(result);
} }
@ -809,12 +815,18 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof SuperType) || !(rhsType instanceof PlaceholderType)) if(!(lhsType instanceof SuperType) || !(rhsType instanceof PlaceholderType))
return Optional.empty(); return Optional.empty();
UnifyType freshTph = PlaceholderType.freshPlaceholder();
UnifyType superedType = ((SuperType)lhsType).getSuperedType(); UnifyType superedType = ((SuperType)lhsType).getSuperedType();
boolean isGen = superedType instanceof PlaceholderType && !((PlaceholderType) superedType).isGenerated();
Set<UnifyPair> result = new HashSet<>(); Set<UnifyPair> result = new HashSet<>();
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT)); if(isGen)
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT)); result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT));
else {
UnifyType freshTph = PlaceholderType.freshPlaceholder();
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT));
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT));
}
return Optional.of(result); return Optional.of(result);
} }

View File

@ -425,6 +425,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) { protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>(); Set<Set<UnifyPair>> result = new HashSet<>();
boolean allGen = true;
for(UnifyType t : thetaPrime.getTypeParams())
if(t instanceof PlaceholderType && !((PlaceholderType) t).isGenerated()) {
allGen = false;
break;
}
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName()); Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
cs.add(thetaPrime); cs.add(thetaPrime);
@ -442,11 +449,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
candidateParams.add(fc.grArg(param)); candidateParams.add(fc.grArg(param));
for(TypeParams tp : permuteParams(candidateParams)) for(TypeParams tp : permuteParams(candidateParams))
try {
thetaQPrimes.add(c.setTypeParams(tp)); thetaQPrimes.add(c.setTypeParams(tp));
} catch(Exception e) {
System.out.println("f");
}
} }
for(UnifyType tqp : thetaQPrimes) { for(UnifyType tqp : thetaQPrimes) {
@ -466,14 +469,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
for(UnifyType theta : smaller) { for(UnifyType theta : smaller) {
Set<UnifyPair> resultPrime = new HashSet<>(); Set<UnifyPair> resultPrime = new HashSet<>();
for(int i = 0; i < theta.getTypeParams().size(); i++) { for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {
if(freshTphs.size()-1 < i) if(freshTphs.size()-1 < i)
freshTphs.add(PlaceholderType.freshPlaceholder()); freshTphs.add(PlaceholderType.freshPlaceholder());
resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC)); resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC));
} }
UnifyType freshTheta = theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))); if(allGen)
resultPrime.add(new UnifyPair(a, freshTheta, PairOperator.EQUALSDOT)); resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
else
resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT));
resultPrime.addAll(substitutionSet); resultPrime.addAll(substitutionSet);
result.add(resultPrime); result.add(resultPrime);
} }
@ -543,16 +548,27 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/ */
protected Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) { protected Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>(); Set<Set<UnifyPair>> result = new HashSet<>();
boolean allGen = true;
for(UnifyType t : theta.getTypeParams())
if(t instanceof PlaceholderType && !((PlaceholderType) t).isGenerated()) {
allGen = false;
break;
}
for(UnifyType thetaS : fc.greater(theta)) { for(UnifyType thetaS : fc.greater(theta)) {
Set<UnifyPair> resultPrime = new HashSet<>(); Set<UnifyPair> resultPrime = new HashSet<>();
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
for(int i = 0; i < freshTphs.length; i++) { for(int i = 0; !allGen && i < freshTphs.length; i++) {
freshTphs[i] = PlaceholderType.freshPlaceholder(); freshTphs[i] = PlaceholderType.freshPlaceholder();
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC)); resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC));
} }
resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT)); if(allGen)
resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT));
else
resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT));
result.add(resultPrime); result.add(resultPrime);
} }