From 1a9c389b0e5a4ca3269346a37d283642db42dcd5 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Mon, 27 Dec 2021 18:21:11 +0300 Subject: [PATCH] FIR: Refactor ConeSubstitutorByMap Add explicit equals and cached hashCode instead of implicit ones from data class --- .../fir/resolve/substitution/Substitutors.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt index d143765b01f..4d79446dcb8 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt @@ -176,10 +176,16 @@ fun ConeSubstitutor.chain(other: ConeSubstitutor): ConeSubstitutor { return ChainedSubstitutor(this, other) } -data class ConeSubstitutorByMap( +class ConeSubstitutorByMap( + // Used only for sake of optimizations at org.jetbrains.kotlin.analysis.api.fir.types.KtFirMapBackedSubstitutor val substitution: Map, - val useSiteSession: FirSession + private val useSiteSession: FirSession ) : AbstractConeSubstitutor(useSiteSession.typeContext) { + + private val hashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { + substitution.hashCode() + } + override fun substituteType(type: ConeKotlinType): ConeKotlinType? { if (type !is ConeTypeParameterType) return null val result = @@ -193,6 +199,19 @@ data class ConeSubstitutorByMap( } return result } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is ConeSubstitutorByMap) return false + + if (hashCode != other.hashCode) return false + if (substitution != other.substitution) return false + if (useSiteSession != other.useSiteSession) return false + + return true + } + + override fun hashCode() = hashCode } fun createTypeSubstitutorByTypeConstructor(map: Map, context: ConeTypeContext): ConeSubstitutor {