From 81385b73b7d94933df8509f83c2e36fdcf561587 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 17 Mar 2020 12:24:45 +0300 Subject: [PATCH] NI: limit cache size for approximated types during incorporation --- .../src/org/jetbrains/kotlin/types/TypeApproximator.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt index 1c52648e60d..0b12c3cf5bf 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt @@ -134,6 +134,10 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon private val referenceApproximateToSuperType = this::approximateSimpleToSuperType private val referenceApproximateToSubType = this::approximateSimpleToSubType + companion object { + const val CACHE_FOR_INCORPORATION_MAX_SIZE = 500 + } + open fun createErrorType(message: String): SimpleTypeMarker = ErrorUtils.createErrorType(message) @@ -183,6 +187,9 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon if (conf !is TypeApproximatorConfiguration.IncorporationConfiguration) return approximate() val cache = if (toSuper) cacheForIncorporationConfigToSuperDirection else cacheForIncorporationConfigToSubtypeDirection + + if (cache.size > CACHE_FOR_INCORPORATION_MAX_SIZE) return approximate() + return cache.getOrPut(type, { approximate().toApproximationResult() }).type }