JS_IR: remove stub generator from IrBuiltins

This commit is contained in:
Anton Bannykh
2019-03-19 17:40:54 +03:00
parent ed440fc060
commit b3f1908026
23 changed files with 125 additions and 144 deletions
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrAnonymousInitializerImpl
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.symbols.IrSymbol
class DescriptorTable {
private val descriptors = mutableMapOf<DeclarationDescriptor, Long>()
@@ -21,18 +22,19 @@ class DescriptorTable {
// TODO: We don't manage id clashes anyhow now.
abstract class DeclarationTable(val builtIns: IrBuiltIns, val descriptorTable: DescriptorTable, mangler: KotlinMangler): KotlinMangler by mangler {
private val builtInsTable = mutableMapOf<IrSymbol, UniqId>()
private val table = mutableMapOf<IrDeclaration, UniqId>()
val descriptors = descriptorTable
protected abstract var currentIndex: Long
open fun loadKnownBuiltins(): Long {
builtIns.knownBuiltins.forEach {
table.put(it, UniqId(currentIndex++, false))
builtInsTable[it] = UniqId(currentIndex++, false)
}
return currentIndex
}
fun uniqIdByDeclaration(value: IrDeclaration) = table.getOrPut(value) {
fun uniqIdByDeclaration(value: IrDeclaration) = (value as? IrSymbolOwner)?.let { builtInsTable[it.symbol] } ?: table.getOrPut(value) {
computeUniqIdByDeclaration(value)
}
@@ -55,4 +57,4 @@ abstract class DeclarationTable(val builtIns: IrBuiltIns, val descriptorTable: D
// This is what we pre-populate tables with
val IrBuiltIns.knownBuiltins
get() = irBuiltInsExternalPackageFragment.declarations
get() = irBuiltInsSymbols
@@ -258,9 +258,8 @@ abstract class KotlinIrLinker(
private fun loadKnownBuiltinSymbols(): Long {
var currentIndex = firstKnownBuiltinsIndex
builtIns.knownBuiltins.forEach {
require(it is IrFunction)
deserializedSymbols[UniqIdKey(null, UniqId(currentIndex, isLocal = false))] = it.symbol
assert(symbolTable.referenceSimpleFunction(it.descriptor) == it.symbol)
deserializedSymbols[UniqIdKey(null, UniqId(currentIndex, isLocal = false))] = it
assert(symbolTable.referenceSimpleFunction(it.descriptor) == it)
currentIndex++
}
return currentIndex