From 9d82eb8fe317b57b56b2e35ab6d9236dc076c692 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Mon, 25 Jul 2022 17:51:50 +0200 Subject: [PATCH] [LL FIR] do not rethrow IndexNotReadyException/ControlFlowException from caches --- .../level/api/fir/caches/ValueWithPostCompute.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/caches/ValueWithPostCompute.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/caches/ValueWithPostCompute.kt index 97e24b27f63..35d8dcf158e 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/caches/ValueWithPostCompute.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/caches/ValueWithPostCompute.kt @@ -6,6 +6,8 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.fir.caches import com.intellij.openapi.progress.ProcessCanceledException +import com.intellij.openapi.project.IndexNotReadyException +import com.intellij.openapi.diagnostic.ControlFlowException /** * Lazily calculated value which runs postCompute in the same thread, @@ -78,10 +80,10 @@ internal class ValueWithPostCompute( _postCompute!!(key, calculated, data) calculated } catch (e: Throwable) { - if (e is ProcessCanceledException) { - value = ValueIsNotComputed - } else { + if (exceptionShouldBeSavedInCache(e)) { value = ExceptionWasThrownDuringValueComputation(e) + } else { + value = ValueIsNotComputed } throw e } @@ -99,6 +101,13 @@ internal class ValueWithPostCompute( } } + private fun exceptionShouldBeSavedInCache(e: Throwable): Boolean = when (e) { + is IndexNotReadyException -> false + is ControlFlowException -> false + else -> true + } + + @Suppress("UNCHECKED_CAST") fun getValueIfComputed(): VALUE? = when (val snapshot = value) { ValueIsNotComputed -> null