[IR] Refactor ir infrastructure

- Remove range-based uniq id indexes using to link built ins
 - Limit KotlinType usages, replace them with corresponding IrType
This commit is contained in:
Roman Artemev
2019-10-28 10:50:15 +03:00
committed by romanart
parent 90d07eee53
commit a343a57207
22 changed files with 409 additions and 232 deletions
@@ -35,14 +35,12 @@ abstract class GlobalDeclarationTable(private val mangler: KotlinMangler, privat
constructor(mangler: KotlinMangler) : this(mangler, UniqIdClashTracker.DEFAULT_TRACKER)
protected open fun loadKnownBuiltins(builtIns: IrBuiltIns, startIndex: Long): Long {
var index = startIndex
protected fun loadKnownBuiltins(builtIns: IrBuiltIns) {
val mask = 1L shl 63
builtIns.knownBuiltins.forEach {
table[it.owner] = UniqId(index or mask).also { id -> clashTracker.commit(it.owner, id) }
index++
val index = with(mangler) { it.mangle.hashMangle }
table[it] = UniqId(index or mask).also { id -> clashTracker.commit(it, id) }
}
return index
}
open fun computeUniqIdByDeclaration(declaration: IrDeclaration): UniqId {
@@ -51,7 +51,7 @@ abstract class KotlinIrLinker(
val symbolTable: SymbolTable,
private val exportedDependencies: List<ModuleDescriptor>,
private val forwardModuleDescriptor: ModuleDescriptor?,
private val firstKnownBuiltinsIndex: Long
mangler: KotlinMangler
) : DescriptorUniqIdAware, IrDeserializer {
@@ -472,18 +472,18 @@ abstract class KotlinIrLinker(
protected abstract val descriptorReferenceDeserializer: DescriptorReferenceDeserializer
protected val indexAfterKnownBuiltins = loadKnownBuiltinSymbols()
private fun loadKnownBuiltinSymbols(): Long {
var currentIndex = firstKnownBuiltinsIndex
private fun loadKnownBuiltinSymbols(mangler: KotlinMangler) {
val mask = 1L shl 63
val globalDeserializedSymbols = globalDeserializationState.deserializedSymbols
builtIns.knownBuiltins.forEach {
globalDeserializedSymbols[UniqId(currentIndex or mask)] = it
assert(symbolTable.referenceSimpleFunction(it.descriptor) == it)
currentIndex++
val currentIndex = with(mangler) { it.mangle.hashMangle }
globalDeserializedSymbols[UniqId(currentIndex or mask)] = it.symbol
assert(symbolTable.referenceSimpleFunction(it.symbol.descriptor as SimpleFunctionDescriptor).owner === it)
}
return currentIndex
}
init {
loadKnownBuiltinSymbols(mangler)
}
private val ByteArray.codedInputStream: org.jetbrains.kotlin.protobuf.CodedInputStream