Avoid unnecessary freshTypeConstructor() calls

This commit is contained in:
Ilya Chernikov
2020-03-06 14:18:53 +01:00
parent 54f10a709a
commit 357ceeae19
4 changed files with 16 additions and 9 deletions
@@ -229,8 +229,9 @@ class CompletionModeCalculator {
constraint: Constraint, constraint: Constraint,
variable: TypeVariableMarker variable: TypeVariableMarker
): Boolean { ): Boolean {
val defaultType = variable.defaultType()
return constraint.kind.isLower() && postponedAtoms.any { atom -> return constraint.kind.isLower() && postponedAtoms.any { atom ->
atom.expectedType?.contains { type -> variable.defaultType() == type } ?: false atom.expectedType?.contains { type -> defaultType == type } ?: false
} }
} }
} }
@@ -41,7 +41,8 @@ class ConstraintIncorporator(
fun incorporate(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) { fun incorporate(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) {
// we shouldn't incorporate recursive constraint -- It is too dangerous // we shouldn't incorporate recursive constraint -- It is too dangerous
with(c) { 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) c.directWithVariable(typeVariable, constraint)
@@ -101,9 +102,10 @@ class ConstraintIncorporator(
typeVariable: TypeVariableMarker, typeVariable: TypeVariableMarker,
constraint: Constraint constraint: Constraint
) { ) {
val freshTypeConstructor = typeVariable.freshTypeConstructor()
for (typeVariableWithConstraint in this@insideOtherConstraint.allTypeVariablesWithConstraints) { for (typeVariableWithConstraint in this@insideOtherConstraint.allTypeVariablesWithConstraints) {
val constraintsWhichConstraintMyVariable = typeVariableWithConstraint.constraints.filter { val constraintsWhichConstraintMyVariable = typeVariableWithConstraint.constraints.filter {
it.type.contains { it.typeConstructor() == typeVariable.freshTypeConstructor() } it.type.contains { it.typeConstructor() == freshTypeConstructor }
} }
constraintsWhichConstraintMyVariable.forEach { constraintsWhichConstraintMyVariable.forEach {
generateNewConstraint(typeVariableWithConstraint.typeVariable, it, typeVariable, constraint) generateNewConstraint(typeVariableWithConstraint.typeVariable, it, typeVariable, constraint)
@@ -111,7 +111,8 @@ class TypeVariableDependencyInformationProvider(
private fun KotlinTypeMarker.forAllMyTypeVariables(action: (TypeConstructorMarker) -> Unit) = private fun KotlinTypeMarker.forAllMyTypeVariables(action: (TypeConstructorMarker) -> Unit) =
with(typeSystemContext) { with(typeSystemContext) {
contains { contains {
if (isMyTypeVariable(it.typeConstructor())) action(it.typeConstructor()) val typeConstructor = it.typeConstructor()
if (isMyTypeVariable(typeConstructor)) action(typeConstructor)
false false
} }
} }
@@ -298,16 +298,18 @@ class NewConstraintSystemImpl(
this, variable.defaultType(), resultType, FixVariableConstraintPosition(variable, atom) 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) checkOnlyInputTypesAnnotation(variableWithConstraints, resultType)
for (variableWithConstraint in notFixedTypeVariables.values) { for (variableWithConstraint in notFixedTypeVariables.values) {
variableWithConstraint.removeConstrains { 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( private fun checkOnlyInputTypesAnnotation(
@@ -336,8 +338,9 @@ class NewConstraintSystemImpl(
override fun containsOnlyFixedOrPostponedVariables(type: KotlinTypeMarker): Boolean { override fun containsOnlyFixedOrPostponedVariables(type: KotlinTypeMarker): Boolean {
checkState(State.BUILDING, State.COMPLETION) checkState(State.BUILDING, State.COMPLETION)
return !type.contains { return !type.contains {
val variable = storage.notFixedTypeVariables[it.typeConstructor()]?.typeVariable val typeConstructor = it.typeConstructor()
variable !in storage.postponedTypeVariables && storage.notFixedTypeVariables.containsKey(it.typeConstructor()) val variable = storage.notFixedTypeVariables[typeConstructor]?.typeVariable
variable !in storage.postponedTypeVariables && storage.notFixedTypeVariables.containsKey(typeConstructor)
} }
} }