[IR BE] Add the ability to collect PL stubbed symbols

^KT-57347 related
This commit is contained in:
Alexander Korepanov
2023-05-08 16:40:15 +02:00
committed by Space Team
parent aef8ece123
commit 22dfe07580
3 changed files with 18 additions and 0 deletions
@@ -38,6 +38,10 @@ internal class MissingDeclarationStubGenerator(private val builtIns: IrBuiltIns)
private var declarationsToPatch = arrayListOf<IrDeclaration>()
private val stubbedSymbols = hashSetOf<IrSymbol>()
val allStubbedSymbols: Set<IrSymbol> get() = stubbedSymbols
fun grabDeclarationsToPatch(): Collection<IrDeclaration> {
val result = declarationsToPatch
declarationsToPatch = arrayListOf()
@@ -47,6 +51,8 @@ internal class MissingDeclarationStubGenerator(private val builtIns: IrBuiltIns)
override fun getDeclaration(symbol: IrSymbol): IrDeclaration {
require(!symbol.isBound)
stubbedSymbols.add(symbol)
return when (symbol) {
is IrClassSymbol -> generateClass(symbol)
is IrSimpleFunctionSymbol -> generateSimpleFunction(symbol)
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.SymbolTable
interface PartialLinkageSupportForLinker {
@@ -48,6 +49,11 @@ interface PartialLinkageSupportForLinker {
fun generateStubsAndPatchUsages(symbolTable: SymbolTable, roots: () -> Sequence<IrModuleFragment>)
fun generateStubsAndPatchUsages(symbolTable: SymbolTable, root: IrDeclaration)
/**
* Collect all symbols which were stubbed
*/
fun collectAllStubbedSymbols(): Set<IrSymbol>
companion object {
val DISABLED = object : PartialLinkageSupportForLinker {
override val isEnabled get() = false
@@ -56,6 +62,7 @@ interface PartialLinkageSupportForLinker {
override fun exploreClassifiersInInlineLazyIrFunction(function: IrFunction) = Unit
override fun generateStubsAndPatchUsages(symbolTable: SymbolTable, roots: () -> Sequence<IrModuleFragment>) = Unit
override fun generateStubsAndPatchUsages(symbolTable: SymbolTable, root: IrDeclaration) = Unit
override fun collectAllStubbedSymbols(): Set<IrSymbol> = emptySet()
}
}
}
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageConfig
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageLogger
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.IrMessageLogger
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.util.allUnbound
@@ -66,6 +67,10 @@ internal class PartialLinkageSupportForLinkerImpl(
generateStubsAndPatchUsagesInternal(symbolTable) { patcher.patchDeclarations(listOf(root)) }
}
override fun collectAllStubbedSymbols(): Set<IrSymbol> {
return stubGenerator.allStubbedSymbols
}
private fun generateStubsAndPatchUsagesInternal(symbolTable: SymbolTable, patchIrTree: () -> Unit) {
// Generate stubs.
for (symbol in symbolTable.allUnbound) {