[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
|
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.IrProvider
|
||||||
import org.jetbrains.kotlin.ir.linkage.KotlinIrLinkerInternalException
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
|
|
||||||
class ExternalDependenciesGenerator(
|
class ExternalDependenciesGenerator(
|
||||||
val symbolTable: SymbolTable,
|
private val symbolTable: SymbolTable,
|
||||||
private val irProviders: List<IrProvider>
|
private val irProviders: List<IrProvider>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun generateUnboundSymbolsAsDependencies() {
|
fun generateUnboundSymbolsAsDependencies() {
|
||||||
// There should be at most one DeclarationStubGenerator (none in closed world?)
|
// There should be at most one DeclarationStubGenerator (none in closed world?)
|
||||||
irProviders.singleOrNull { it is DeclarationStubGenerator }?.let {
|
irProviders.filterIsInstance<DeclarationStubGenerator>().singleOrNull()?.run { unboundSymbolGeneration = true }
|
||||||
(it as DeclarationStubGenerator).unboundSymbolGeneration = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deserializing a reference may lead to new unbound references, so we loop until none are left.
|
// Deserializing a reference may lead to new unbound references, so we loop until none are left.
|
||||||
try {
|
var unbound = emptySet<IrSymbol>()
|
||||||
var unbound = setOf<IrSymbol>()
|
do {
|
||||||
do {
|
val prevUnbound = unbound
|
||||||
val prevUnbound = unbound
|
unbound = symbolTable.allUnbound
|
||||||
unbound = symbolTable.allUnbound
|
for (symbol in unbound) {
|
||||||
for (symbol in unbound) {
|
// Symbol could get bound as a side effect of deserializing other symbols.
|
||||||
// Symbol could get bound as a side effect of deserializing other symbols.
|
if (!symbol.isBound) {
|
||||||
if (!symbol.isBound) {
|
irProviders.firstNotNullOfOrNull { provider -> provider.getDeclaration(symbol) }
|
||||||
irProviders.getDeclaration(symbol)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// We wait for the unbound to stabilize on fake overrides.
|
}
|
||||||
} while (unbound != prevUnbound)
|
// We wait for the unbound to stabilize on fake overrides.
|
||||||
} catch (ex: KotlinIrLinkerInternalException) {
|
} while (unbound != prevUnbound)
|
||||||
throw CompilationErrorException()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun List<IrProvider>.getDeclaration(symbol: IrSymbol): IrDeclaration? =
|
|
||||||
firstNotNullOfOrNull { provider ->
|
|
||||||
provider.getDeclaration(symbol)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user