[IR] Clean up linker code
This commit is contained in:
+2
-70
@@ -8,15 +8,12 @@ package org.jetbrains.kotlin.backend.common.serialization
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.IrExtensionGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.library.IrLibrary
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -205,9 +202,7 @@ class IrModuleDeserializerWithBuiltIns(
|
||||
|
||||
open class CurrentModuleDeserializer(
|
||||
override val moduleFragment: IrModuleFragment,
|
||||
override val moduleDependencies: Collection<IrModuleDeserializer>,
|
||||
private val symbolTable: SymbolTable,
|
||||
private val extensions: Collection<IrExtensionGenerator>
|
||||
override val moduleDependencies: Collection<IrModuleDeserializer>
|
||||
) : IrModuleDeserializer(moduleFragment.descriptor) {
|
||||
override fun contains(idSig: IdSignature): Boolean = false // TODO:
|
||||
|
||||
@@ -215,68 +210,5 @@ open class CurrentModuleDeserializer(
|
||||
error("Unreachable execution: there could not be back-links")
|
||||
}
|
||||
|
||||
override fun declareIrSymbol(symbol: IrSymbol) {
|
||||
declareIrSymbolImpl(symbol)
|
||||
}
|
||||
|
||||
private fun referenceParentDescriptor(descriptor: DeclarationDescriptor): IrSymbol {
|
||||
return when (descriptor) {
|
||||
is ClassDescriptor -> symbolTable.referenceClass(descriptor)
|
||||
is PropertyDescriptor -> symbolTable.referenceProperty(descriptor)
|
||||
is PackageFragmentDescriptor -> moduleFragment.files.single { it.symbol.descriptor === descriptor }.symbol
|
||||
else -> error("Unexpected declaration parent $descriptor")
|
||||
}
|
||||
}
|
||||
|
||||
private fun declareIrDeclaration(symbol: IrSymbol): IrDeclaration {
|
||||
for (extension in extensions) {
|
||||
extension.declare(symbol)?.let { return it }
|
||||
}
|
||||
|
||||
return declareIrDeclarationDefault(symbol)
|
||||
}
|
||||
|
||||
private fun declareIrDeclarationDefault(symbol: IrSymbol): IrDeclaration {
|
||||
return when (symbol) {
|
||||
is IrClassSymbol -> symbolTable.declareClass(offset, offset, IrDeclarationOrigin.DEFINED, symbol.descriptor)
|
||||
is IrConstructorSymbol -> symbolTable.declareConstructor(offset, offset, IrDeclarationOrigin.DEFINED, symbol.descriptor)
|
||||
is IrSimpleFunctionSymbol -> symbolTable.declareSimpleFunction(offset, offset, IrDeclarationOrigin.DEFINED, symbol.descriptor)
|
||||
is IrPropertySymbol -> symbolTable.declareProperty(offset, offset, IrDeclarationOrigin.DEFINED, symbol.descriptor)
|
||||
is IrTypeAliasSymbol -> TODO("Implement type alias $symbol")
|
||||
is IrEnumEntrySymbol -> symbolTable.declareEnumEntry(offset, offset, IrDeclarationOrigin.DEFINED, symbol.descriptor)
|
||||
else -> error("Unexpected symbol $symbol")
|
||||
}
|
||||
}
|
||||
|
||||
private fun declareIrSymbolImpl(symbol: IrSymbol): IrSymbolOwner {
|
||||
if (symbol.isBound) return symbol.owner
|
||||
val descriptor = symbol.descriptor
|
||||
|
||||
assert(descriptor !is WrappedDeclarationDescriptor<*>)
|
||||
|
||||
val accessor = descriptor as? PropertyAccessorDescriptor
|
||||
|
||||
val parent = descriptor.containingDeclaration ?: error("Expect non-root declaration $descriptor")
|
||||
val parentDeclaration = declareIrSymbolImpl(referenceParentDescriptor(parent)) as IrDeclarationContainer
|
||||
|
||||
val declaredDeclaration = declareIrDeclaration(symbol).also {
|
||||
it.parent = parentDeclaration
|
||||
if (accessor != null) {
|
||||
val property = accessor.correspondingProperty
|
||||
val irProperty = declareIrSymbolImpl(referenceParentDescriptor(property)) as IrProperty
|
||||
val irAccessor = it as IrSimpleFunction
|
||||
irAccessor.correspondingPropertySymbol = irProperty.symbol
|
||||
if (accessor === property.getter) irProperty.getter = irAccessor
|
||||
if (accessor === property.setter) irProperty.setter = irAccessor
|
||||
} else {
|
||||
parentDeclaration.declarations.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
return declaredDeclaration as IrSymbolOwner
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val offset = UNDEFINED_OFFSET
|
||||
}
|
||||
override fun declareIrSymbol(symbol: IrSymbol) {}
|
||||
}
|
||||
+4
-3
@@ -491,6 +491,7 @@ abstract class KotlinIrLinker(
|
||||
moduleDeserializer.declareIrSymbol(symbol)
|
||||
|
||||
deserializeAllReachableTopLevels()
|
||||
if (!symbol.isBound) return null
|
||||
return descriptor
|
||||
}
|
||||
|
||||
@@ -521,15 +522,15 @@ abstract class KotlinIrLinker(
|
||||
return symbol.owner as IrDeclaration
|
||||
}
|
||||
|
||||
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>, extensions: Collection<IrExtensionGenerator>): IrModuleDeserializer =
|
||||
CurrentModuleDeserializer(moduleFragment, dependencies, symbolTable, extensions)
|
||||
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
||||
CurrentModuleDeserializer(moduleFragment, dependencies)
|
||||
|
||||
override fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrExtensionGenerator>) {
|
||||
if (moduleFragment != null) {
|
||||
val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map {
|
||||
deserializersForModules[it] ?: error("No deserializer found for $it")
|
||||
}
|
||||
val currentModuleDeserializer = createCurrentModuleDeserializer(moduleFragment, currentModuleDependencies, extensions)
|
||||
val currentModuleDeserializer = createCurrentModuleDeserializer(moduleFragment, currentModuleDependencies)
|
||||
deserializersForModules[moduleFragment.descriptor] =
|
||||
maybeWrapWithBuiltInAndInit(moduleFragment.descriptor, currentModuleDeserializer)
|
||||
}
|
||||
|
||||
+2
-6
@@ -36,12 +36,8 @@ class JsIrLinker(
|
||||
private inner class JsModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary, strategy: DeserializationStrategy) :
|
||||
KotlinIrLinker.BasicIrModuleDeserializer(moduleDescriptor, klib, strategy)
|
||||
|
||||
override fun createCurrentModuleDeserializer(
|
||||
moduleFragment: IrModuleFragment,
|
||||
dependencies: Collection<IrModuleDeserializer>,
|
||||
extensions: Collection<IrExtensionGenerator>
|
||||
): IrModuleDeserializer {
|
||||
val currentModuleDeserializer = super.createCurrentModuleDeserializer(moduleFragment, dependencies, extensions)
|
||||
override fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer {
|
||||
val currentModuleDeserializer = super.createCurrentModuleDeserializer(moduleFragment, dependencies)
|
||||
icData?.let {
|
||||
return CurrentModuleWithICDeserializer(currentModuleDeserializer, symbolTable, builtIns, it) { lib ->
|
||||
JsModuleDeserializer(currentModuleDeserializer.moduleDescriptor, lib, currentModuleDeserializer.strategy)
|
||||
|
||||
+4
-5
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.IrExtensionGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.library.IrLibrary
|
||||
import org.jetbrains.kotlin.load.java.descriptors.*
|
||||
@@ -76,11 +75,11 @@ class JvmIrLinker(currentModule: ModuleDescriptor?, logger: LoggingContext, buil
|
||||
}
|
||||
|
||||
|
||||
override fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>, extensions: Collection<IrExtensionGenerator>): IrModuleDeserializer =
|
||||
JvmCurrentModuleDeserializer(moduleFragment, dependencies, extensions)
|
||||
override fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
||||
JvmCurrentModuleDeserializer(moduleFragment, dependencies)
|
||||
|
||||
private inner class JvmCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>, extensions: Collection<IrExtensionGenerator>) :
|
||||
CurrentModuleDeserializer(moduleFragment, dependencies, symbolTable, extensions) {
|
||||
private inner class JvmCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>) :
|
||||
CurrentModuleDeserializer(moduleFragment, dependencies) {
|
||||
override fun declareIrSymbol(symbol: IrSymbol) {
|
||||
val descriptor = symbol.descriptor
|
||||
|
||||
|
||||
Reference in New Issue
Block a user