[NI] There is no need in copying constraint storage as it read-only

This commit is contained in:
Mikhail Zarechenskiy
2018-04-25 12:31:49 +03:00
parent e0ca3421ca
commit 99a95f31d3
4 changed files with 4 additions and 32 deletions
@@ -102,7 +102,7 @@ class PostponedArgumentsAnalyzer(
}
if (inferenceSession != null) {
val storageSnapshot = c.getBuilder().copyCurrentStorage()
val storageSnapshot = c.getBuilder().currentStorage()
val postponedVariables = inferenceSession.inferPostponedVariables(storageSnapshot)
@@ -49,7 +49,7 @@ interface ConstraintSystemBuilder : ConstraintSystemOperation {
fun buildCurrentSubstitutor(): NewTypeSubstitutor
fun copyCurrentStorage(): ConstraintStorage
fun currentStorage(): ConstraintStorage
}
fun ConstraintSystemBuilder.addSubtypeConstraintIfCompatible(
@@ -97,32 +97,4 @@ internal class MutableConstraintStorage : ConstraintStorage {
override val hasContradiction: Boolean get() = errors.any { !it.candidateApplicability.isSuccess }
override val fixedTypeVariables: MutableMap<TypeConstructor, UnwrappedType> = LinkedHashMap()
override val postponedTypeVariables: ArrayList<NewTypeVariable> = ArrayList()
fun copy(): ConstraintStorage {
return object : ConstraintStorage {
override val allTypeVariables: Map<TypeConstructor, NewTypeVariable> =
this@MutableConstraintStorage.allTypeVariables.toMap()
override val notFixedTypeVariables: Map<TypeConstructor, VariableWithConstraints> =
this@MutableConstraintStorage.notFixedTypeVariables.toMap()
override val initialConstraints: List<InitialConstraint> =
this@MutableConstraintStorage.initialConstraints.toList()
override val maxTypeDepthFromInitialConstraints: Int =
this@MutableConstraintStorage.maxTypeDepthFromInitialConstraints
override val errors: List<KotlinCallDiagnostic> =
this@MutableConstraintStorage.errors.toList()
override val hasContradiction: Boolean =
this@MutableConstraintStorage.hasContradiction
override val fixedTypeVariables: Map<TypeConstructor, UnwrappedType> =
this@MutableConstraintStorage.fixedTypeVariables.toMap()
override val postponedTypeVariables: List<NewTypeVariable> =
this@MutableConstraintStorage.postponedTypeVariables.toList()
}
}
}
@@ -278,9 +278,9 @@ class NewConstraintSystemImpl(
return storage.postponedTypeVariables.associate { it to NonFixedType(it.freshTypeConstructor, it.defaultType.isMarkedNullable) }
}
override fun copyCurrentStorage(): ConstraintStorage {
override fun currentStorage(): ConstraintStorage {
checkState(State.BUILDING, State.COMPLETION)
return storage.copy()
return storage
}
// PostponedArgumentsAnalyzer.Context