Avoid unnecessary freshTypeConstructor() calls
This commit is contained in:
+2
-1
@@ -229,8 +229,9 @@ class CompletionModeCalculator {
|
||||
constraint: Constraint,
|
||||
variable: TypeVariableMarker
|
||||
): Boolean {
|
||||
val defaultType = variable.defaultType()
|
||||
return constraint.kind.isLower() && postponedAtoms.any { atom ->
|
||||
atom.expectedType?.contains { type -> variable.defaultType() == type } ?: false
|
||||
atom.expectedType?.contains { type -> defaultType == type } ?: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -41,7 +41,8 @@ class ConstraintIncorporator(
|
||||
fun incorporate(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) {
|
||||
// we shouldn't incorporate recursive constraint -- It is too dangerous
|
||||
with(c) {
|
||||
if (constraint.type.contains { it.typeConstructor() == typeVariable.freshTypeConstructor() }) return
|
||||
val freshTypeConstructor = typeVariable.freshTypeConstructor()
|
||||
if (constraint.type.contains { it.typeConstructor() == freshTypeConstructor }) return
|
||||
}
|
||||
|
||||
c.directWithVariable(typeVariable, constraint)
|
||||
@@ -101,9 +102,10 @@ class ConstraintIncorporator(
|
||||
typeVariable: TypeVariableMarker,
|
||||
constraint: Constraint
|
||||
) {
|
||||
val freshTypeConstructor = typeVariable.freshTypeConstructor()
|
||||
for (typeVariableWithConstraint in this@insideOtherConstraint.allTypeVariablesWithConstraints) {
|
||||
val constraintsWhichConstraintMyVariable = typeVariableWithConstraint.constraints.filter {
|
||||
it.type.contains { it.typeConstructor() == typeVariable.freshTypeConstructor() }
|
||||
it.type.contains { it.typeConstructor() == freshTypeConstructor }
|
||||
}
|
||||
constraintsWhichConstraintMyVariable.forEach {
|
||||
generateNewConstraint(typeVariableWithConstraint.typeVariable, it, typeVariable, constraint)
|
||||
|
||||
+2
-1
@@ -111,7 +111,8 @@ class TypeVariableDependencyInformationProvider(
|
||||
private fun KotlinTypeMarker.forAllMyTypeVariables(action: (TypeConstructorMarker) -> Unit) =
|
||||
with(typeSystemContext) {
|
||||
contains {
|
||||
if (isMyTypeVariable(it.typeConstructor())) action(it.typeConstructor())
|
||||
val typeConstructor = it.typeConstructor()
|
||||
if (isMyTypeVariable(typeConstructor)) action(typeConstructor)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
+8
-5
@@ -298,16 +298,18 @@ class NewConstraintSystemImpl(
|
||||
this, variable.defaultType(), resultType, FixVariableConstraintPosition(variable, atom)
|
||||
)
|
||||
|
||||
val variableWithConstraints = notFixedTypeVariables.remove(variable.freshTypeConstructor())
|
||||
val freshTypeConstructor = variable.freshTypeConstructor()
|
||||
|
||||
val variableWithConstraints = notFixedTypeVariables.remove(freshTypeConstructor)
|
||||
checkOnlyInputTypesAnnotation(variableWithConstraints, resultType)
|
||||
|
||||
for (variableWithConstraint in notFixedTypeVariables.values) {
|
||||
variableWithConstraint.removeConstrains {
|
||||
it.type.contains { it.typeConstructor() == variable.freshTypeConstructor() }
|
||||
it.type.contains { it.typeConstructor() == freshTypeConstructor }
|
||||
}
|
||||
}
|
||||
|
||||
storage.fixedTypeVariables[variable.freshTypeConstructor()] = resultType
|
||||
storage.fixedTypeVariables[freshTypeConstructor] = resultType
|
||||
}
|
||||
|
||||
private fun checkOnlyInputTypesAnnotation(
|
||||
@@ -336,8 +338,9 @@ class NewConstraintSystemImpl(
|
||||
override fun containsOnlyFixedOrPostponedVariables(type: KotlinTypeMarker): Boolean {
|
||||
checkState(State.BUILDING, State.COMPLETION)
|
||||
return !type.contains {
|
||||
val variable = storage.notFixedTypeVariables[it.typeConstructor()]?.typeVariable
|
||||
variable !in storage.postponedTypeVariables && storage.notFixedTypeVariables.containsKey(it.typeConstructor())
|
||||
val typeConstructor = it.typeConstructor()
|
||||
val variable = storage.notFixedTypeVariables[typeConstructor]?.typeVariable
|
||||
variable !in storage.postponedTypeVariables && storage.notFixedTypeVariables.containsKey(typeConstructor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user