modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Variance auf PlacehloderType uebertragen
This commit is contained in:
parent
dbe05bb718
commit
95e9b2dbda
@ -126,28 +126,20 @@ public class JavaTXCompiler {
|
|||||||
|
|
||||||
xConsSet = xConsSet.stream().map(x -> {
|
xConsSet = xConsSet.stream().map(x -> {
|
||||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
if ((x.getLhsType() instanceof PlaceholderType)) {
|
||||||
if (paraTypeVarNames.contains(x.getLhsType().getName())
|
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
||||||
&& (!(x.getRhsType() instanceof PlaceholderType)
|
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
||||||
|| ((x.getRhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getRhsType().getName()) && !returnTypeVarNames.contains(x.getRhsType().getName())))) {
|
|
||||||
x.setVariance((byte)1);
|
|
||||||
}
|
}
|
||||||
if (returnTypeVarNames.contains(x.getLhsType().getName())
|
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
||||||
&& (!(x.getRhsType() instanceof PlaceholderType)
|
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
||||||
|| ((x.getRhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getRhsType().getName()) && !returnTypeVarNames.contains(x.getRhsType().getName())))) {
|
|
||||||
x.setVariance((byte)-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
if ((x.getRhsType() instanceof PlaceholderType)) {
|
||||||
if (paraTypeVarNames.contains(x.getRhsType().getName())
|
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
||||||
&& (!(x.getLhsType() instanceof PlaceholderType)
|
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
||||||
|| ((x.getLhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getLhsType().getName()) && !returnTypeVarNames.contains(x.getLhsType().getName())))) {
|
}
|
||||||
x.setVariance((byte)1);
|
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
||||||
}
|
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
||||||
if (returnTypeVarNames.contains(x.getRhsType().getName())
|
}
|
||||||
&& (!(x.getLhsType() instanceof PlaceholderType)
|
|
||||||
|| ((x.getLhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getLhsType().getName()) && !returnTypeVarNames.contains(x.getLhsType().getName())))) {
|
|
||||||
x.setVariance((byte)-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
@ -314,7 +314,17 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("nextSet: " + nextSet.toString());
|
writeLog("nextSet: " + nextSet.toString());
|
||||||
List<Set<UnifyPair>> nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
List<Set<UnifyPair>> nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
byte variance = nextSetasList.iterator().next().iterator().next().getVariance();
|
int variance = 0;
|
||||||
|
Optional<Integer> xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType)
|
||||||
|
.filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0)
|
||||||
|
.map(c -> ((PlaceholderType)c.getLhsType()).getVariance())
|
||||||
|
.reduce((a,b)-> a*b))
|
||||||
|
.filter(d -> d.isPresent())
|
||||||
|
.map(e -> e.get())
|
||||||
|
.findAny();
|
||||||
|
if (xi.isPresent()) {
|
||||||
|
variance = xi.get();
|
||||||
|
}
|
||||||
if (variance == 1 && nextSetasList.size() > 1) {
|
if (variance == 1 && nextSetasList.size() > 1) {
|
||||||
List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
|
List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
|
||||||
for (int ii = 0; ii < nextSetasList.size();ii++) {
|
for (int ii = 0; ii < nextSetasList.size();ii++) {
|
||||||
|
@ -37,6 +37,15 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
*/
|
*/
|
||||||
private final boolean IsGenerated;
|
private final boolean IsGenerated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* variance shows the variance of the pair
|
||||||
|
* -1: contravariant
|
||||||
|
* 1 covariant
|
||||||
|
* 0 invariant
|
||||||
|
* PL 2018-03-21
|
||||||
|
*/
|
||||||
|
private int variance = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new placeholder type with the specified name.
|
* Creates a new placeholder type with the specified name.
|
||||||
*/
|
*/
|
||||||
@ -80,6 +89,14 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
return IsGenerated;
|
return IsGenerated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setVariance(int v) {
|
||||||
|
variance = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVariance() {
|
||||||
|
return variance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> smArg(IFiniteClosure fc) {
|
Set<UnifyType> smArg(IFiniteClosure fc) {
|
||||||
return fc.smArg(this);
|
return fc.smArg(this);
|
||||||
|
@ -72,6 +72,7 @@ public class UnifyPair {
|
|||||||
pairOp = op;
|
pairOp = op;
|
||||||
unifier = uni;
|
unifier = uni;
|
||||||
basePair = base;
|
basePair = base;
|
||||||
|
this.variance = variance;
|
||||||
|
|
||||||
|
|
||||||
// Caching hashcode
|
// Caching hashcode
|
||||||
|
Loading…
Reference in New Issue
Block a user