Skip duplicates removal on constraints simplification
It is already coveren on addition. Speeds up inference a bit.
This commit is contained in:
+2
-25
@@ -103,33 +103,10 @@ class MutableVariableWithConstraints(
|
||||
}
|
||||
|
||||
private fun simplifyConstraints(): List<Constraint> {
|
||||
val distinctConstraints = removeDuplicatesFromDeclaredUpperBoundConstraints(mutableConstraints)
|
||||
|
||||
val equalityConstraints = distinctConstraints
|
||||
val equalityConstraints = mutableConstraints
|
||||
.filter { it.kind == ConstraintKind.EQUALITY }
|
||||
.groupBy { it.typeHashCode }
|
||||
return distinctConstraints.filter { isUsefulConstraint(it, equalityConstraints) }
|
||||
}
|
||||
|
||||
private fun removeDuplicatesFromDeclaredUpperBoundConstraints(constraints: List<Constraint>): MutableList<Constraint> {
|
||||
val currentConstraints = constraints.toMutableList()
|
||||
val iterator = currentConstraints.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val potentialDuplicate = iterator.next()
|
||||
|
||||
if (potentialDuplicate.position.from !is DeclaredUpperBoundConstraintPosition) continue
|
||||
val hasDuplicate = currentConstraints.any { other ->
|
||||
potentialDuplicate !== other &&
|
||||
potentialDuplicate.typeHashCode == other.typeHashCode &&
|
||||
potentialDuplicate.type == other.type &&
|
||||
potentialDuplicate.kind == other.kind
|
||||
}
|
||||
|
||||
if (hasDuplicate)
|
||||
iterator.remove()
|
||||
}
|
||||
|
||||
return currentConstraints
|
||||
return mutableConstraints.filter { isUsefulConstraint(it, equalityConstraints) }
|
||||
}
|
||||
|
||||
private fun isUsefulConstraint(constraint: Constraint, equalityConstraints: Map<Int, List<Constraint>>): Boolean {
|
||||
|
||||
+1
-1
@@ -22,5 +22,5 @@ val foofoo: Foo = <!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>run<!> {
|
||||
val bar: Bar = <!NI;TYPE_MISMATCH!><!OI;TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>run<!> {
|
||||
val x = foo()
|
||||
if (x == null) throw Exception()
|
||||
<!NI;DEBUG_INFO_SMARTCAST, TYPE_MISMATCH!>x<!>
|
||||
<!NI;DEBUG_INFO_SMARTCAST, NI;TYPE_MISMATCH, TYPE_MISMATCH!>x<!>
|
||||
}<!>
|
||||
|
||||
Reference in New Issue
Block a user