diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/ExternalDependenciesGenerator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/ExternalDependenciesGenerator.kt index c3a3b82c13a..17ff84d6cc1 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/ExternalDependenciesGenerator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/ExternalDependenciesGenerator.kt @@ -15,44 +15,29 @@ */ package org.jetbrains.kotlin.ir.util -import org.jetbrains.kotlin.analyzer.CompilationErrorException -import org.jetbrains.kotlin.ir.declarations.IrDeclaration import org.jetbrains.kotlin.ir.linkage.IrProvider -import org.jetbrains.kotlin.ir.linkage.KotlinIrLinkerInternalException import org.jetbrains.kotlin.ir.symbols.IrSymbol class ExternalDependenciesGenerator( - val symbolTable: SymbolTable, + private val symbolTable: SymbolTable, private val irProviders: List ) { - fun generateUnboundSymbolsAsDependencies() { // There should be at most one DeclarationStubGenerator (none in closed world?) - irProviders.singleOrNull { it is DeclarationStubGenerator }?.let { - (it as DeclarationStubGenerator).unboundSymbolGeneration = true - } + irProviders.filterIsInstance().singleOrNull()?.run { unboundSymbolGeneration = true } // Deserializing a reference may lead to new unbound references, so we loop until none are left. - try { - var unbound = setOf() - do { - val prevUnbound = unbound - unbound = symbolTable.allUnbound - for (symbol in unbound) { - // Symbol could get bound as a side effect of deserializing other symbols. - if (!symbol.isBound) { - irProviders.getDeclaration(symbol) - } + var unbound = emptySet() + do { + val prevUnbound = unbound + unbound = symbolTable.allUnbound + for (symbol in unbound) { + // Symbol could get bound as a side effect of deserializing other symbols. + if (!symbol.isBound) { + irProviders.firstNotNullOfOrNull { provider -> provider.getDeclaration(symbol) } } - // We wait for the unbound to stabilize on fake overrides. - } while (unbound != prevUnbound) - } catch (ex: KotlinIrLinkerInternalException) { - throw CompilationErrorException() - } + } + // We wait for the unbound to stabilize on fake overrides. + } while (unbound != prevUnbound) } } - -fun List.getDeclaration(symbol: IrSymbol): IrDeclaration? = - firstNotNullOfOrNull { provider -> - provider.getDeclaration(symbol) - }