type constraints rollback
This commit is contained in:
+6
-11
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.Variance;
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
|
|
||||||
@@ -27,21 +26,17 @@ import java.util.Set;
|
|||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public interface TypeConstraints {
|
public interface TypeConstraints {
|
||||||
|
@NotNull
|
||||||
@Nullable
|
Set<JetType> getLowerBounds();
|
||||||
JetType getLowerConstraint();
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
JetType getUpperConstraint();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Set<JetType> getConflicts();
|
Set<JetType> getUpperBounds();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Variance getVariance();
|
Set<JetType> getExactBounds();
|
||||||
|
|
||||||
boolean isSuccessful();
|
@NotNull
|
||||||
|
Variance getVarianceOfPosition();
|
||||||
|
|
||||||
boolean isEmpty();
|
boolean isEmpty();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-125
@@ -16,160 +16,65 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.types.CommonSupertypes;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.Variance;
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class TypeConstraintsImpl implements TypeConstraints {
|
public class TypeConstraintsImpl implements TypeConstraints {
|
||||||
private static final TypeConstraintsData EMPTY_CONSTRAINTS_DATA = new TypeConstraintsData(null, null, Collections.<JetType>emptySet());
|
private final Variance varianceOfPosition;
|
||||||
private static class TypeConstraintsData {
|
private final Set<JetType> upperBounds = Sets.newLinkedHashSet();
|
||||||
private final JetType lowerConstraint;
|
private final Set<JetType> lowerBounds = Sets.newLinkedHashSet();
|
||||||
private final JetType upperConstraint;
|
private final Set<JetType> exactBounds = Sets.newLinkedHashSet();
|
||||||
private final Set<JetType> conflicts;
|
|
||||||
|
|
||||||
private TypeConstraintsData(JetType lowerConstraint, JetType upperConstraint, Set<JetType> conflicts) {
|
public TypeConstraintsImpl(Variance varianceOfPosition) {
|
||||||
this.lowerConstraint = lowerConstraint;
|
this.varianceOfPosition = varianceOfPosition;
|
||||||
this.upperConstraint = upperConstraint;
|
|
||||||
this.conflicts = conflicts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JetType getLowerConstraint() {
|
|
||||||
return lowerConstraint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JetType getUpperConstraint() {
|
|
||||||
return upperConstraint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<JetType> getConflicts() {
|
|
||||||
return conflicts;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Variance variance;
|
|
||||||
private TypeConstraintsData typeConstraintsData = EMPTY_CONSTRAINTS_DATA;
|
|
||||||
|
|
||||||
private final Set<JetType> upperConstraints = Sets.newLinkedHashSet();
|
|
||||||
private final Set<JetType> lowerConstraints = Sets.newLinkedHashSet();
|
|
||||||
private final Set<JetType> equalConstraints = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
private boolean changed = false;
|
|
||||||
|
|
||||||
public TypeConstraintsImpl(Variance variance) {
|
|
||||||
this.variance = variance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Variance getVariance() {
|
public Variance getVarianceOfPosition() {
|
||||||
return variance;
|
return varianceOfPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUpperConstraint(@NotNull JetType constraint) {
|
public void addUpperBound(@NotNull JetType type) {
|
||||||
upperConstraints.add(constraint);
|
upperBounds.add(type);
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLowerConstraint(@NotNull JetType constraint) {
|
public void addLowerBound(@NotNull JetType type) {
|
||||||
lowerConstraints.add(constraint);
|
lowerBounds.add(type);
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEqualConstraint(@NotNull JetType constraint) {
|
public void addExactBound(@NotNull JetType type) {
|
||||||
equalConstraints.add(constraint);
|
exactBounds.add(type);
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateResult() {
|
|
||||||
if (!changed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JetType lowerConstraint = null;
|
|
||||||
JetType upperConstraint = null;
|
|
||||||
Set<JetType> conflicts = Sets.newLinkedHashSet();
|
|
||||||
if (!lowerConstraints.isEmpty()) {
|
|
||||||
lowerConstraint = CommonSupertypes.commonSupertype(lowerConstraints);
|
|
||||||
}
|
|
||||||
if (!upperConstraints.isEmpty()) {
|
|
||||||
//todo
|
|
||||||
upperConstraint = upperConstraints.iterator().next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lowerConstraint != null && upperConstraint != null && !JetTypeChecker.INSTANCE.isSubtypeOf(lowerConstraint, upperConstraint)) {
|
|
||||||
conflicts.add(lowerConstraint);
|
|
||||||
conflicts.add(upperConstraint);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (equalConstraints.size() > 1) {
|
|
||||||
conflicts.addAll(equalConstraints);
|
|
||||||
}
|
|
||||||
else if (equalConstraints.size() == 1) {
|
|
||||||
JetType value = equalConstraints.iterator().next();
|
|
||||||
if (lowerConstraint != null && !JetTypeChecker.INSTANCE.isSubtypeOf(lowerConstraint, value)) {
|
|
||||||
conflicts.add(lowerConstraint);
|
|
||||||
conflicts.add(value);
|
|
||||||
}
|
|
||||||
if (upperConstraint != null && !JetTypeChecker.INSTANCE.isSubtypeOf(value, upperConstraint)) {
|
|
||||||
conflicts.add(upperConstraint);
|
|
||||||
conflicts.add(value);
|
|
||||||
}
|
|
||||||
lowerConstraint = value;
|
|
||||||
upperConstraint = value;
|
|
||||||
}
|
|
||||||
typeConstraintsData = new TypeConstraintsData(lowerConstraint, upperConstraint, conflicts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSuccessful() {
|
|
||||||
updateResult();
|
|
||||||
return typeConstraintsData.getConflicts().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public JetType getLowerConstraint() {
|
|
||||||
updateResult();
|
|
||||||
return typeConstraintsData.getLowerConstraint();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public JetType getUpperConstraint() {
|
|
||||||
updateResult();
|
|
||||||
return typeConstraintsData.getUpperConstraint();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Set<JetType> getConflicts() {
|
|
||||||
updateResult();
|
|
||||||
return typeConstraintsData.getConflicts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
updateResult();
|
return upperBounds.isEmpty() && lowerBounds.isEmpty() && exactBounds.isEmpty();
|
||||||
return typeConstraintsData.getLowerConstraint() == null && typeConstraintsData.getUpperConstraint() == null && typeConstraintsData.getConflicts().isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public Set<JetType> getLowerBounds() {
|
||||||
return "TypeConstraints{" +
|
return lowerBounds;
|
||||||
"upper=" + getUpperConstraint() +
|
}
|
||||||
", lower=" + getLowerConstraint() +
|
|
||||||
", conflicts=" + getConflicts() +
|
@NotNull
|
||||||
'}';
|
@Override
|
||||||
|
public Set<JetType> getUpperBounds() {
|
||||||
|
return upperBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<JetType> getExactBounds() {
|
||||||
|
return exactBounds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user