[FIR] make FirCorrespondingSupertypesCache to be thread safe
^KT-50244
This commit is contained in:
+10
-5
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.types
|
|||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||||
import org.jetbrains.kotlin.fir.ThreadSafeMutableState
|
import org.jetbrains.kotlin.fir.ThreadSafeMutableState
|
||||||
|
import org.jetbrains.kotlin.fir.caches.firCachesFactory
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
@@ -20,7 +21,13 @@ import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
|||||||
|
|
||||||
@ThreadSafeMutableState
|
@ThreadSafeMutableState
|
||||||
class FirCorrespondingSupertypesCache(private val session: FirSession) : FirSessionComponent {
|
class FirCorrespondingSupertypesCache(private val session: FirSession) : FirSessionComponent {
|
||||||
private val cache = HashMap<ConeClassLikeLookupTag, Map<ConeClassLikeLookupTag, List<ConeClassLikeType>>?>(1000, 0.5f)
|
private val cache =
|
||||||
|
session.firCachesFactory.createCache<ConeClassLikeLookupTag, Map<ConeClassLikeLookupTag, List<ConeClassLikeType>>?, TypeCheckerState>(
|
||||||
|
initialCapacity = 1000,
|
||||||
|
loadFactor = 0.5f
|
||||||
|
) { lookupTag, typeCheckerState ->
|
||||||
|
computeSupertypesMap(lookupTag, typeCheckerState)
|
||||||
|
}
|
||||||
|
|
||||||
fun getCorrespondingSupertypes(
|
fun getCorrespondingSupertypes(
|
||||||
type: ConeKotlinType,
|
type: ConeKotlinType,
|
||||||
@@ -36,11 +43,9 @@ class FirCorrespondingSupertypesCache(private val session: FirSession) : FirSess
|
|||||||
|
|
||||||
val lookupTag = type.lookupTag
|
val lookupTag = type.lookupTag
|
||||||
if (lookupTag == supertypeConstructor) return listOf(captureType(type, typeContext))
|
if (lookupTag == supertypeConstructor) return listOf(captureType(type, typeContext))
|
||||||
if (lookupTag !in cache) {
|
|
||||||
cache[lookupTag] = computeSupertypesMap(lookupTag, typeCheckerState)
|
|
||||||
}
|
|
||||||
|
|
||||||
val resultTypes = cache[lookupTag]?.getOrDefault(supertypeConstructor, emptyList()) ?: return null
|
val resultTypes =
|
||||||
|
cache.getValue(lookupTag, typeCheckerState)?.getOrDefault(supertypeConstructor, emptyList()) ?: return null
|
||||||
if (type.typeArguments.isEmpty()) return resultTypes
|
if (type.typeArguments.isEmpty()) return resultTypes
|
||||||
|
|
||||||
val capturedType = captureType(type, typeContext)
|
val capturedType = captureType(type, typeContext)
|
||||||
|
|||||||
Reference in New Issue
Block a user