[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.backend.common.serialization.encodings.BinarySymbolData
|
||||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory
|
import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
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.library.IrLibrary
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -205,9 +202,7 @@ class IrModuleDeserializerWithBuiltIns(
|
|||||||
|
|
||||||
open class CurrentModuleDeserializer(
|
open class CurrentModuleDeserializer(
|
||||||
override val moduleFragment: IrModuleFragment,
|
override val moduleFragment: IrModuleFragment,
|
||||||
override val moduleDependencies: Collection<IrModuleDeserializer>,
|
override val moduleDependencies: Collection<IrModuleDeserializer>
|
||||||
private val symbolTable: SymbolTable,
|
|
||||||
private val extensions: Collection<IrExtensionGenerator>
|
|
||||||
) : IrModuleDeserializer(moduleFragment.descriptor) {
|
) : IrModuleDeserializer(moduleFragment.descriptor) {
|
||||||
override fun contains(idSig: IdSignature): Boolean = false // TODO:
|
override fun contains(idSig: IdSignature): Boolean = false // TODO:
|
||||||
|
|
||||||
@@ -215,68 +210,5 @@ open class CurrentModuleDeserializer(
|
|||||||
error("Unreachable execution: there could not be back-links")
|
error("Unreachable execution: there could not be back-links")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun declareIrSymbol(symbol: IrSymbol) {
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+4
-3
@@ -491,6 +491,7 @@ abstract class KotlinIrLinker(
|
|||||||
moduleDeserializer.declareIrSymbol(symbol)
|
moduleDeserializer.declareIrSymbol(symbol)
|
||||||
|
|
||||||
deserializeAllReachableTopLevels()
|
deserializeAllReachableTopLevels()
|
||||||
|
if (!symbol.isBound) return null
|
||||||
return descriptor
|
return descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,15 +522,15 @@ abstract class KotlinIrLinker(
|
|||||||
return symbol.owner as IrDeclaration
|
return symbol.owner as IrDeclaration
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>, extensions: Collection<IrExtensionGenerator>): IrModuleDeserializer =
|
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
||||||
CurrentModuleDeserializer(moduleFragment, dependencies, symbolTable, extensions)
|
CurrentModuleDeserializer(moduleFragment, dependencies)
|
||||||
|
|
||||||
override fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrExtensionGenerator>) {
|
override fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrExtensionGenerator>) {
|
||||||
if (moduleFragment != null) {
|
if (moduleFragment != null) {
|
||||||
val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map {
|
val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map {
|
||||||
deserializersForModules[it] ?: error("No deserializer found for $it")
|
deserializersForModules[it] ?: error("No deserializer found for $it")
|
||||||
}
|
}
|
||||||
val currentModuleDeserializer = createCurrentModuleDeserializer(moduleFragment, currentModuleDependencies, extensions)
|
val currentModuleDeserializer = createCurrentModuleDeserializer(moduleFragment, currentModuleDependencies)
|
||||||
deserializersForModules[moduleFragment.descriptor] =
|
deserializersForModules[moduleFragment.descriptor] =
|
||||||
maybeWrapWithBuiltInAndInit(moduleFragment.descriptor, currentModuleDeserializer)
|
maybeWrapWithBuiltInAndInit(moduleFragment.descriptor, currentModuleDeserializer)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-6
@@ -36,12 +36,8 @@ class JsIrLinker(
|
|||||||
private inner class JsModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary, strategy: DeserializationStrategy) :
|
private inner class JsModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary, strategy: DeserializationStrategy) :
|
||||||
KotlinIrLinker.BasicIrModuleDeserializer(moduleDescriptor, klib, strategy)
|
KotlinIrLinker.BasicIrModuleDeserializer(moduleDescriptor, klib, strategy)
|
||||||
|
|
||||||
override fun createCurrentModuleDeserializer(
|
override fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer {
|
||||||
moduleFragment: IrModuleFragment,
|
val currentModuleDeserializer = super.createCurrentModuleDeserializer(moduleFragment, dependencies)
|
||||||
dependencies: Collection<IrModuleDeserializer>,
|
|
||||||
extensions: Collection<IrExtensionGenerator>
|
|
||||||
): IrModuleDeserializer {
|
|
||||||
val currentModuleDeserializer = super.createCurrentModuleDeserializer(moduleFragment, dependencies, extensions)
|
|
||||||
icData?.let {
|
icData?.let {
|
||||||
return CurrentModuleWithICDeserializer(currentModuleDeserializer, symbolTable, builtIns, it) { lib ->
|
return CurrentModuleWithICDeserializer(currentModuleDeserializer, symbolTable, builtIns, it) { lib ->
|
||||||
JsModuleDeserializer(currentModuleDeserializer.moduleDescriptor, lib, currentModuleDeserializer.strategy)
|
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.symbols.IrSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
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.ir.util.SymbolTable
|
||||||
import org.jetbrains.kotlin.library.IrLibrary
|
import org.jetbrains.kotlin.library.IrLibrary
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.*
|
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 =
|
override fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
||||||
JvmCurrentModuleDeserializer(moduleFragment, dependencies, extensions)
|
JvmCurrentModuleDeserializer(moduleFragment, dependencies)
|
||||||
|
|
||||||
private inner class JvmCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>, extensions: Collection<IrExtensionGenerator>) :
|
private inner class JvmCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>) :
|
||||||
CurrentModuleDeserializer(moduleFragment, dependencies, symbolTable, extensions) {
|
CurrentModuleDeserializer(moduleFragment, dependencies) {
|
||||||
override fun declareIrSymbol(symbol: IrSymbol) {
|
override fun declareIrSymbol(symbol: IrSymbol) {
|
||||||
val descriptor = symbol.descriptor
|
val descriptor = symbol.descriptor
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user