forked from JavaTX/JavaCompilerCore
unify case 1
This commit is contained in:
parent
d19a79bd63
commit
fa9627b883
@ -144,6 +144,7 @@ public class FiniteClosure implements IFiniteClosure {
|
|||||||
return new HashSet<Type>();
|
return new HashSet<Type>();
|
||||||
|
|
||||||
Set<Type> result = new HashSet<Type>();
|
Set<Type> result = new HashSet<Type>();
|
||||||
|
result.add(type);
|
||||||
|
|
||||||
Type t = type.getExtendedType();
|
Type t = type.getExtendedType();
|
||||||
|
|
||||||
@ -158,6 +159,7 @@ public class FiniteClosure implements IFiniteClosure {
|
|||||||
return new HashSet<Type>();
|
return new HashSet<Type>();
|
||||||
|
|
||||||
Set<Type> result = new HashSet<Type>();
|
Set<Type> result = new HashSet<Type>();
|
||||||
|
result.add(type);
|
||||||
|
|
||||||
Type t = type.getSuperedType();
|
Type t = type.getSuperedType();
|
||||||
|
|
||||||
@ -194,6 +196,7 @@ public class FiniteClosure implements IFiniteClosure {
|
|||||||
return new HashSet<Type>();
|
return new HashSet<Type>();
|
||||||
|
|
||||||
Set<Type> result = new HashSet<Type>();
|
Set<Type> result = new HashSet<Type>();
|
||||||
|
result.add(type);
|
||||||
|
|
||||||
Type t = type.getExtendedType();
|
Type t = type.getExtendedType();
|
||||||
|
|
||||||
@ -213,6 +216,7 @@ public class FiniteClosure implements IFiniteClosure {
|
|||||||
return new HashSet<Type>();
|
return new HashSet<Type>();
|
||||||
|
|
||||||
Set<Type> result = new HashSet<Type>();
|
Set<Type> result = new HashSet<Type>();
|
||||||
|
result.add(type);
|
||||||
|
|
||||||
Type t = type.getSuperedType();
|
Type t = type.getSuperedType();
|
||||||
|
|
||||||
|
@ -232,38 +232,39 @@ public class Unify {
|
|||||||
Set<MPair> set = new HashSet<>();
|
Set<MPair> set = new HashSet<>();
|
||||||
IUnify unify = new MartelliMontanariUnify();
|
IUnify unify = new MartelliMontanariUnify();
|
||||||
|
|
||||||
//Set<Type> cs = fc.getAllTypes(rhsType.getName());
|
Set<Type> cs = fc.getAllTypes(rhsType.getName());
|
||||||
Type c = rhsType;
|
|
||||||
|
|
||||||
//Set<Type> thetaQs = cs.stream().flatMap(x -> fc.smaller(x).stream()).collect(Collectors.toCollection(HashSet::new));
|
Set<Type> thetaQs = cs.stream().flatMap(
|
||||||
Set<Type> thetaQs = fc.smaller(c);
|
x -> fc.smaller(x).stream().filter(y -> y.getTypeParams().arePlaceholders())
|
||||||
|
).collect(Collectors.toCollection(HashSet::new));
|
||||||
Set<Type> thetaQPrimes = new HashSet<>();
|
|
||||||
|
for(Type c : cs) {
|
||||||
TypeParams cParams = c.getTypeParams();
|
Set<Type> thetaQPrimes = new HashSet<>();
|
||||||
if(cParams.size() == 0)
|
TypeParams cParams = c.getTypeParams();
|
||||||
thetaQPrimes.add(c);
|
if(cParams.size() == 0)
|
||||||
else {
|
thetaQPrimes.add(c);
|
||||||
ArrayList<Set<Type>> candidateParams = new ArrayList<>();
|
else {
|
||||||
for(Type param : cParams)
|
ArrayList<Set<Type>> candidateParams = new ArrayList<>();
|
||||||
candidateParams.add(fc.grArg(param));
|
for(Type param : cParams)
|
||||||
Set<TypeParams> permutations = new HashSet<TypeParams>();
|
candidateParams.add(fc.grArg(param));
|
||||||
permuteParams(candidateParams, 0, permutations, new Type[candidateParams.size()]);
|
Set<TypeParams> permutations = new HashSet<TypeParams>();
|
||||||
|
permuteParams(candidateParams, 0, permutations, new Type[candidateParams.size()]);
|
||||||
|
|
||||||
|
for(TypeParams tp : permutations)
|
||||||
|
thetaQPrimes.add(c.setTypeParams(tp));
|
||||||
|
}
|
||||||
|
|
||||||
for(TypeParams tp : permutations)
|
for(Type tqp : thetaQPrimes) {
|
||||||
thetaQPrimes.add(c.setTypeParams(tp));
|
Optional<Unifier> opt = unify.unify(tqp, thetaPrime);
|
||||||
}
|
if(opt.isPresent()) {
|
||||||
|
Unifier unifier = opt.get();
|
||||||
for(Type tqp : thetaQPrimes) {
|
Set<Entry<PlaceholderType, Type>> substitutions = unifier.getSubstitutions();
|
||||||
Optional<Unifier> opt = unify.unify(tqp, thetaPrime);
|
for(Entry<PlaceholderType, Type> sigma : substitutions)
|
||||||
if(opt.isPresent()) {
|
set.add(new MPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
|
||||||
Unifier unifier = opt.get();
|
for(Type tq : thetaQs) {
|
||||||
Set<Entry<PlaceholderType, Type>> substitutions = unifier.getSubstitutions();
|
Set<Type> smaller = fc.smaller(unifier.apply(tq));
|
||||||
for(Entry<PlaceholderType, Type> sigma : substitutions)
|
smaller.stream().map(x -> new MPair(lhsType, x, PairOperator.EQUALSDOT)).forEach(x -> set.add(x));
|
||||||
set.add(new MPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
|
}
|
||||||
for(Type tq : thetaQs) {
|
|
||||||
Set<Type> smaller = fc.smaller(unifier.apply(tq));
|
|
||||||
smaller.stream().map(x -> new MPair(lhsType, x, PairOperator.EQUALSDOT)).forEach(x -> set.add(x));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class UnifyTest extends Unify {
|
|||||||
eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT));
|
eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT));
|
||||||
//eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Number")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT));
|
//eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Number")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT));
|
||||||
//eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "C"), PairOperator.SMALLERDOT));
|
//eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "C"), PairOperator.SMALLERDOT));
|
||||||
eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("List", tf.getSimpleType("Number")), PairOperator.SMALLERDOT));
|
eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("Number"), PairOperator.SMALLERDOT));
|
||||||
//eq.add(new MPair(tf.getSimpleType("Number"), tf.getPlaceholderType("A"), PairOperator.SMALLERDOT));
|
//eq.add(new MPair(tf.getSimpleType("Number"), tf.getPlaceholderType("A"), PairOperator.SMALLERDOT));
|
||||||
//eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT));
|
//eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT));
|
||||||
//eq.add(new MPair(tf.getSimpleType("Double"), tf.getPlaceholderType("B"), PairOperator.SMALLERDOT));
|
//eq.add(new MPair(tf.getSimpleType("Double"), tf.getPlaceholderType("B"), PairOperator.SMALLERDOT));
|
||||||
|
Loading…
Reference in New Issue
Block a user