diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index 1ef4b0b148b..1fb6f80b485 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -43,7 +43,6 @@ import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics import org.jetbrains.kotlin.resolve.diagnostics.OnDemandSuppressCache -import org.jetbrains.kotlin.resolve.diagnostics.PrecomputedSuppressCache import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.* diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/PrecomputedSuppressCache.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/OnDemandSuppressCache.kt similarity index 53% rename from compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/PrecomputedSuppressCache.kt rename to compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/OnDemandSuppressCache.kt index 2a29f0a052a..54091873634 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/PrecomputedSuppressCache.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/OnDemandSuppressCache.kt @@ -14,54 +14,7 @@ import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtTreeVisitorVoid import org.jetbrains.kotlin.resolve.BindingContext -/** - * A [KotlinSuppressCache] implementation that computes all suppressions at the moment of instantiation. - * This is useful in the IR backend, where we clear the main binding context after psi2ir to avoid taking extra memory. - * To make suppression of errors reported from backend possible though, we need to precompute all resolved `@Suppress` annotations, - * and store this information outside of the binding context, which is going to be cleared. - * - * @param context the binding context where the data should be loaded from. Note that it shouldn't be stored as a property because the - * primary use case of this class is when that binding context is cleared and thus is useless after a certain point. - */ -class PrecomputedSuppressCache(context: BindingContext, files: List) : KotlinSuppressCache() { - val storage: Map> = - mutableMapOf>().also { storage -> - val visitor = PrecomputingVisitor(storage, BindingContextSuppressCache(context)) - for (file in files) { - file.accept(visitor, null) - } - } - - private class PrecomputingVisitor( - val storage: MutableMap>, - val computer: KotlinSuppressCache, - ) : KtTreeVisitorVoid() { - override fun visitKtElement(element: KtElement) { - super.visitKtElement(element) - if (element is KtAnnotated) { - computeAnnotations(element) - } - } - - override fun visitKtFile(file: KtFile) { - super.visitKtFile(file) - computeAnnotations(file) - } - - private fun computeAnnotations(element: KtAnnotated) { - val suppressions = computer.getSuppressionAnnotations(element).filter { it.fqName == StandardNames.FqNames.suppress } - if (suppressions.isNotEmpty()) { - storage[element] = suppressions - } - } - } - - override fun getSuppressionAnnotations(annotated: PsiElement): List = - storage[annotated].orEmpty() -} - class OnDemandSuppressCache(private val context: BindingContext) : KotlinSuppressCache() { - private val processedRoots = mutableSetOf() private val storage = mutableMapOf>()