From 02f3cedcf4bfd65292bafa239c56330ac9f38a62 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 16 Dec 2019 20:20:12 +0300 Subject: [PATCH] FIR: Optimize ConeInferenceContext::typeDepth --- .../fir/resolve/calls/ConeInferenceContext.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeInferenceContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeInferenceContext.kt index 5fe64534154..a1b2ee13922 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeInferenceContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeInferenceContext.kt @@ -96,15 +96,25 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo || this is ConeTypeParameterType } + override fun KotlinTypeMarker.typeDepth() = when (this) { + is ConeSimpleKotlinType -> typeDepth() + is ConeFlexibleType -> maxOf(lowerBound().typeDepth(), upperBound().typeDepth()) + else -> error("Type should be simple or flexible: $this") + } + override fun SimpleTypeMarker.typeDepth(): Int { require(this is ConeKotlinType) // if (this is TypeUtils.SpecialType) return 0 // TODO: WTF? - val maxInArguments = this.typeArguments.asSequence().map { - if (it.isStarProjection()) 1 else it.getType().typeDepth() - }.max() ?: 0 + var result = 0 + for (arg in typeArguments) { + val current = if (arg is ConeStarProjection) 1 else (arg as ConeTypedProjection).type.typeDepth() + if (current > result) { + result = current + } + } - return maxInArguments + 1 + return result + 1 } override fun KotlinTypeMarker.contains(predicate: (KotlinTypeMarker) -> Boolean): Boolean {