[LL FIR] do not rethrow IndexNotReadyException/ControlFlowException from caches

This commit is contained in:
Ilya Kirillov
2022-07-25 17:51:50 +02:00
parent 721508f6dd
commit 9d82eb8fe3
@@ -6,6 +6,8 @@
package org.jetbrains.kotlin.analysis.low.level.api.fir.fir.caches package org.jetbrains.kotlin.analysis.low.level.api.fir.fir.caches
import com.intellij.openapi.progress.ProcessCanceledException 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, * Lazily calculated value which runs postCompute in the same thread,
@@ -78,10 +80,10 @@ internal class ValueWithPostCompute<KEY, VALUE, DATA>(
_postCompute!!(key, calculated, data) _postCompute!!(key, calculated, data)
calculated calculated
} catch (e: Throwable) { } catch (e: Throwable) {
if (e is ProcessCanceledException) { if (exceptionShouldBeSavedInCache(e)) {
value = ValueIsNotComputed
} else {
value = ExceptionWasThrownDuringValueComputation(e) value = ExceptionWasThrownDuringValueComputation(e)
} else {
value = ValueIsNotComputed
} }
throw e throw e
} }
@@ -99,6 +101,13 @@ internal class ValueWithPostCompute<KEY, VALUE, DATA>(
} }
} }
private fun exceptionShouldBeSavedInCache(e: Throwable): Boolean = when (e) {
is IndexNotReadyException -> false
is ControlFlowException -> false
else -> true
}
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
fun getValueIfComputed(): VALUE? = when (val snapshot = value) { fun getValueIfComputed(): VALUE? = when (val snapshot = value) {
ValueIsNotComputed -> null ValueIsNotComputed -> null