From 32a80bf38e5cc7d070c8d06872fae88d9d20a19d Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 13 Dec 2021 13:20:32 +0300 Subject: [PATCH] FIR: Add fast-path for getOrderedAllTypeVariables if no synthetics --- .../kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt | 4 +++- .../fir/resolve/inference/FirBuilderInferenceSession.kt | 2 ++ .../resolve/inference/FirDelegatedPropertyInferenceSession.kt | 3 +++ .../kotlin/fir/resolve/inference/FirInferenceSession.kt | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index 772980d53bb..2b32d680f19 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -391,7 +391,9 @@ class ConstraintSystemCompleter(private val components: BodyResolveComponents, p topLevel.collectAllTypeVariables() } - result.addAll(c.notFixedTypeVariables.filter { context.inferenceSession.isSyntheticTypeVariable(it.value.typeVariable) }.keys.asIterable()) + if (context.inferenceSession.hasSyntheticTypeVariables()) { + result.addAll(c.notFixedTypeVariables.filter { context.inferenceSession.isSyntheticTypeVariable(it.value.typeVariable) }.keys.asIterable()) + } require(result.size == c.notFixedTypeVariables.size) { val notFoundTypeVariables = c.notFixedTypeVariables.keys.toMutableSet().apply { removeAll(result) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt index 6069a3a5220..b7af1fa5db5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt @@ -41,6 +41,8 @@ class FirBuilderInferenceSession( override val currentConstraintStorage: ConstraintStorage get() = ConstraintStorage.Empty + override fun hasSyntheticTypeVariables(): Boolean = false + override fun isSyntheticTypeVariable(typeVariable: TypeVariableMarker): Boolean { return false } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt index 57cfe387f35..2e8857d725a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt @@ -144,6 +144,9 @@ class FirDelegatedPropertyInferenceSession( return typeContext.typeSubstitutorByTypeConstructor(bindings) } + override fun hasSyntheticTypeVariables(): Boolean { + return syntheticTypeVariableByTypeVariable.isNotEmpty() + } override fun isSyntheticTypeVariable(typeVariable: TypeVariableMarker): Boolean { return typeVariable in syntheticTypeVariableByTypeVariable.values diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt index 21b446cf1f8..123b800602a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt @@ -32,6 +32,7 @@ abstract class FirInferenceSession { abstract fun registerStubTypes(map: Map) + abstract fun hasSyntheticTypeVariables(): Boolean abstract fun isSyntheticTypeVariable(typeVariable: TypeVariableMarker): Boolean abstract fun fixSyntheticTypeVariableWithNotEnoughInformation( typeVariable: TypeVariableMarker, @@ -66,6 +67,7 @@ abstract class FirStubInferenceSession : FirInferenceSession() { override fun registerStubTypes(map: Map) {} + override fun hasSyntheticTypeVariables(): Boolean = false override fun isSyntheticTypeVariable(typeVariable: TypeVariableMarker): Boolean = false override fun fixSyntheticTypeVariableWithNotEnoughInformation( typeVariable: TypeVariableMarker,