From 790cafa6718198f084d708ecb5e9b6e164796196 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Sun, 4 Apr 2021 17:38:26 +0200 Subject: [PATCH] FIR IDE: fix deadlock in symbol providers --- .../idea/fir/low/level/api/fir/caches/FirThreadSafeCache.kt | 2 +- .../level/api/fir/caches/FirThreadSafeCacheWithPostCompute.kt | 2 +- .../kotlin/idea/fir/low/level/api/fir/caches/NullValue.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/FirThreadSafeCache.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/FirThreadSafeCache.kt index 5e53fb30510..261009948d6 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/FirThreadSafeCache.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/FirThreadSafeCache.kt @@ -14,7 +14,7 @@ internal class FirThreadSafeCache( private val map = ConcurrentHashMap() override fun getValue(key: K, context: CONTEXT): V = - map.computeIfAbsentWithNullableValue(key) { createValue(it, context) } + map.getOrPutWithNullableValue(key) { createValue(it, context) } override fun getValueIfComputed(key: K): V? = map[key]?.nullValueToNull() diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/FirThreadSafeCacheWithPostCompute.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/FirThreadSafeCacheWithPostCompute.kt index a378e2b807a..a04fb5c590c 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/FirThreadSafeCacheWithPostCompute.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/FirThreadSafeCacheWithPostCompute.kt @@ -16,7 +16,7 @@ internal class FirThreadSafeCacheWithPostCompute( @Suppress("UNCHECKED_CAST") override fun getValue(key: K, context: CONTEXT): V = - map.computeIfAbsent(key) { + map.getOrPut(key) { ValueWithPostCompute( key, calculate = { createValue(it, context) }, diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/NullValue.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/NullValue.kt index 67b4e2863c5..d5f8935862f 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/NullValue.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/fir/caches/NullValue.kt @@ -15,10 +15,10 @@ internal inline fun Any.nullValueToNull(): VALUE = when (this) { else -> this } as VALUE -internal inline fun ConcurrentMap.computeIfAbsentWithNullableValue( +internal inline fun ConcurrentMap.getOrPutWithNullableValue( key: KEY, crossinline compute: (KEY) -> Any? ): RESULT { - val value = computeIfAbsent(key) { k -> compute(k) ?: NullValue } + val value = getOrPut(key) { compute(key) ?: NullValue } return value.nullValueToNull() } \ No newline at end of file