[IR] Refactoring: Clean-up in ExternalDependenciesGenerator
Note: There is no need to catch KotlinIrLinkerInternalException and re-throw it as CompilationErrorException since the fix of KT-53649.
This commit is contained in:
committed by
Space Team
parent
eec511a767
commit
c38d0d7359
+13
-28
@@ -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<IrProvider>
|
||||
) {
|
||||
|
||||
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<DeclarationStubGenerator>().singleOrNull()?.run { unboundSymbolGeneration = true }
|
||||
|
||||
// Deserializing a reference may lead to new unbound references, so we loop until none are left.
|
||||
try {
|
||||
var unbound = setOf<IrSymbol>()
|
||||
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<IrSymbol>()
|
||||
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<IrProvider>.getDeclaration(symbol: IrSymbol): IrDeclaration? =
|
||||
firstNotNullOfOrNull { provider ->
|
||||
provider.getDeclaration(symbol)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user