[Private fake overrides] Private fake overrides linkage
This commit is contained in:
@@ -89,8 +89,7 @@ class Psi2IrTranslator(
|
|||||||
moduleGenerator.generateUnboundSymbolsAsDependencies(irProviders)
|
moduleGenerator.generateUnboundSymbolsAsDependencies(irProviders)
|
||||||
|
|
||||||
deserializers.forEach { it.postProcess() }
|
deserializers.forEach { it.postProcess() }
|
||||||
val allUnbound = context.symbolTable.allUnbound
|
context.symbolTable.noUnboundLeft("Unbound symbols not allowed\n")
|
||||||
assert(allUnbound.isEmpty()) { "Unbound symbols not allowed\n${allUnbound.joinToString("\n\t", "\t")}" }
|
|
||||||
|
|
||||||
postprocessingSteps.forEach { it.invoke(irModule) }
|
postprocessingSteps.forEach { it.invoke(irModule) }
|
||||||
// assert(context.symbolTable.allUnbound.isEmpty()) // TODO: fix IrPluginContext to make it not produce additional external reference
|
// assert(context.symbolTable.allUnbound.isEmpty()) // TODO: fix IrPluginContext to make it not produce additional external reference
|
||||||
|
|||||||
@@ -51,8 +51,16 @@ abstract class FakeOverrideBuilderStrategy {
|
|||||||
return deepCopyFakeOverride
|
return deepCopyFakeOverride
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this one doesn't belong here. IrOverridingUtil shouldn't know about symbol table.
|
fun linkFakeOverride(fakeOverride: IrOverridableMember) {
|
||||||
abstract fun linkFakeOverride(fakeOverride: IrOverridableMember)
|
when (fakeOverride) {
|
||||||
|
is IrFakeOverrideFunction -> linkFunctionFakeOverride(fakeOverride)
|
||||||
|
is IrFakeOverrideProperty -> linkPropertyFakeOverride(fakeOverride)
|
||||||
|
else -> error("Unexpected fake override: $fakeOverride")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun linkFunctionFakeOverride(declaration: IrFakeOverrideFunction)
|
||||||
|
protected abstract fun linkPropertyFakeOverride(declaration: IrFakeOverrideProperty)
|
||||||
|
|
||||||
// TODO: need to make IrProperty carry overriddenSymbols.
|
// TODO: need to make IrProperty carry overriddenSymbols.
|
||||||
val propertyOverriddenSymbols: MutableMap<IrOverridableMember, List<IrSymbol>> = mutableMapOf()
|
val propertyOverriddenSymbols: MutableMap<IrOverridableMember, List<IrSymbol>> = mutableMapOf()
|
||||||
@@ -390,8 +398,8 @@ class IrOverridingUtil(
|
|||||||
fakeOverride.overriddenSymbols.isNotEmpty()
|
fakeOverride.overriddenSymbols.isNotEmpty()
|
||||||
) { "Overridden symbols should be set for " + CallableMemberDescriptor.Kind.FAKE_OVERRIDE }
|
) { "Overridden symbols should be set for " + CallableMemberDescriptor.Kind.FAKE_OVERRIDE }
|
||||||
|
|
||||||
fakeOverrideBuilder.linkFakeOverride(fakeOverride)
|
|
||||||
addedFakeOverrides.add(fakeOverride)
|
addedFakeOverrides.add(fakeOverride)
|
||||||
|
fakeOverrideBuilder.linkFakeOverride(fakeOverride)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isVisibilityMoreSpecific(
|
private fun isVisibilityMoreSpecific(
|
||||||
|
|||||||
+29
-16
@@ -72,6 +72,7 @@ object FakeOverrideControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FakeOverrideBuilder(
|
class FakeOverrideBuilder(
|
||||||
|
val linker: FileLocalAwareLinker,
|
||||||
val symbolTable: SymbolTable,
|
val symbolTable: SymbolTable,
|
||||||
val signaturer: IdSignatureSerializer,
|
val signaturer: IdSignatureSerializer,
|
||||||
irBuiltIns: IrBuiltIns,
|
irBuiltIns: IrBuiltIns,
|
||||||
@@ -108,23 +109,12 @@ class FakeOverrideBuilder(
|
|||||||
irOverridingUtil.buildFakeOverridesForClass(clazz)
|
irOverridingUtil.buildFakeOverridesForClass(clazz)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun linkFakeOverride(fakeOverride: IrOverridableMember) {
|
override fun linkFunctionFakeOverride(declaration: IrFakeOverrideFunction) {
|
||||||
when (fakeOverride) {
|
val signature = composeSignature(declaration)
|
||||||
is IrFakeOverrideFunction -> linkFunctionFakeOverride(fakeOverride)
|
declareFunctionFakeOverride(declaration, signature)
|
||||||
is IrFakeOverrideProperty -> linkPropertyFakeOverride(fakeOverride)
|
|
||||||
else -> error("Unexpected fake override: $fakeOverride")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun linkFunctionFakeOverride(declaration: IrFakeOverrideFunction) {
|
override fun linkPropertyFakeOverride(declaration: IrFakeOverrideProperty) {
|
||||||
val signature = signaturer.composePublicIdSignature(declaration)
|
|
||||||
|
|
||||||
symbolTable.declareSimpleFunctionFromLinker(WrappedSimpleFunctionDescriptor(), signature) {
|
|
||||||
declaration.acquireSymbol(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun linkPropertyFakeOverride(declaration: IrFakeOverrideProperty) {
|
|
||||||
// To compute a signature for a property with type parameters,
|
// To compute a signature for a property with type parameters,
|
||||||
// we must have its accessor's correspondingProperty pointing to the property's symbol.
|
// we must have its accessor's correspondingProperty pointing to the property's symbol.
|
||||||
// See IrMangleComputer.mangleTypeParameterReference() for details.
|
// See IrMangleComputer.mangleTypeParameterReference() for details.
|
||||||
@@ -154,7 +144,30 @@ class FakeOverrideBuilder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun provideFakeOverrides(klass: IrClass) {
|
private fun composeSignature(declaration: IrDeclaration) =
|
||||||
|
signaturer.composeSignatureForDeclaration(declaration)
|
||||||
|
|
||||||
|
private fun declareFunctionFakeOverride(declaration: IrFakeOverrideFunction, signature: IdSignature) {
|
||||||
|
val parent = declaration.parentAsClass
|
||||||
|
val symbol = linker.tryReferencingSimpleFunctionByLocalSignature(parent, signature)
|
||||||
|
val descriptor = symbol?.descriptor ?: WrappedSimpleFunctionDescriptor()
|
||||||
|
symbolTable.declareSimpleFunctionFromLinker(descriptor, signature) {
|
||||||
|
assert(it === symbol || symbol == null)
|
||||||
|
declaration.acquireSymbol(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun declarePropertyFakeOverride(declaration: IrFakeOverrideProperty, signature: IdSignature) {
|
||||||
|
val parent = declaration.parentAsClass
|
||||||
|
val symbol = linker.tryReferencingPropertyByLocalSignature(parent, signature)
|
||||||
|
val descriptor = symbol?.descriptor ?: WrappedPropertyDescriptor()
|
||||||
|
symbolTable.declarePropertyFromLinker(descriptor, signature) {
|
||||||
|
assert(it === symbol || symbol == null)
|
||||||
|
declaration.acquireSymbol(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun provideFakeOverrides(klass: IrClass) {
|
||||||
buildFakeOverrideChainsForClass(klass)
|
buildFakeOverrideChainsForClass(klass)
|
||||||
propertyOverriddenSymbols.clear()
|
propertyOverriddenSymbols.clear()
|
||||||
irOverridingUtil.clear()
|
irOverridingUtil.clear()
|
||||||
|
|||||||
+15
-4
@@ -9,10 +9,7 @@ import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolD
|
|||||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
|
import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
|
|
||||||
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
|
||||||
@@ -36,6 +33,12 @@ abstract class IrModuleDeserializer(val moduleDescriptor: ModuleDescriptor) {
|
|||||||
abstract operator fun contains(idSig: IdSignature): Boolean
|
abstract operator fun contains(idSig: IdSignature): Boolean
|
||||||
abstract fun deserializeIrSymbol(idSig: IdSignature, symbolKind: BinarySymbolData.SymbolKind): IrSymbol
|
abstract fun deserializeIrSymbol(idSig: IdSignature, symbolKind: BinarySymbolData.SymbolKind): IrSymbol
|
||||||
|
|
||||||
|
open fun referenceSimpleFunctionByLocalSignature(file: IrFile, idSignature: IdSignature) : IrSimpleFunctionSymbol =
|
||||||
|
error("Unsupported operation")
|
||||||
|
|
||||||
|
open fun referencePropertyByLocalSignature(file: IrFile, idSignature: IdSignature): IrPropertySymbol =
|
||||||
|
error("Unsupported operation")
|
||||||
|
|
||||||
open fun declareIrSymbol(symbol: IrSymbol) {
|
open fun declareIrSymbol(symbol: IrSymbol) {
|
||||||
val signature = symbol.signature
|
val signature = symbol.signature
|
||||||
require(signature != null) { "Symbol is not public API: ${symbol.descriptor}" }
|
require(signature != null) { "Symbol is not public API: ${symbol.descriptor}" }
|
||||||
@@ -47,6 +50,8 @@ abstract class IrModuleDeserializer(val moduleDescriptor: ModuleDescriptor) {
|
|||||||
|
|
||||||
open fun init() = init(this)
|
open fun init() = init(this)
|
||||||
|
|
||||||
|
open fun postProcess() {}
|
||||||
|
|
||||||
open fun init(delegate: IrModuleDeserializer) {}
|
open fun init(delegate: IrModuleDeserializer) {}
|
||||||
|
|
||||||
open fun addModuleReachableTopLevel(idSig: IdSignature) { error("Unsupported Operation (sig: $idSig") }
|
open fun addModuleReachableTopLevel(idSig: IdSignature) { error("Unsupported Operation (sig: $idSig") }
|
||||||
@@ -93,6 +98,12 @@ class IrModuleDeserializerWithBuiltIns(
|
|||||||
return checkIsFunctionInterface(idSig) || idSig in delegate
|
return checkIsFunctionInterface(idSig) || idSig in delegate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun referenceSimpleFunctionByLocalSignature(file: IrFile, idSignature: IdSignature) : IrSimpleFunctionSymbol =
|
||||||
|
delegate.referenceSimpleFunctionByLocalSignature(file, idSignature)
|
||||||
|
|
||||||
|
override fun referencePropertyByLocalSignature(file: IrFile, idSignature: IdSignature): IrPropertySymbol =
|
||||||
|
delegate.referencePropertyByLocalSignature(file, idSignature)
|
||||||
|
|
||||||
override fun deserializeReachableDeclarations() {
|
override fun deserializeReachableDeclarations() {
|
||||||
delegate.deserializeReachableDeclarations()
|
delegate.deserializeReachableDeclarations()
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-5
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.backend.common.serialization
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.LoggingContext
|
import org.jetbrains.kotlin.backend.common.LoggingContext
|
||||||
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
||||||
|
import org.jetbrains.kotlin.backend.common.overrides.FileLocalAwareLinker
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
@@ -14,7 +15,6 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
|
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
@@ -29,9 +29,7 @@ import org.jetbrains.kotlin.ir.symbols.*
|
|||||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl
|
||||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.util.NaiveSourceBasedFileEntryImpl
|
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
|
||||||
import org.jetbrains.kotlin.library.IrLibrary
|
import org.jetbrains.kotlin.library.IrLibrary
|
||||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
@@ -56,7 +54,7 @@ abstract class KotlinIrLinker(
|
|||||||
val symbolTable: SymbolTable,
|
val symbolTable: SymbolTable,
|
||||||
private val exportedDependencies: List<ModuleDescriptor>,
|
private val exportedDependencies: List<ModuleDescriptor>,
|
||||||
private val deserializeFakeOverrides: Boolean
|
private val deserializeFakeOverrides: Boolean
|
||||||
) : IrDeserializer {
|
) : IrDeserializer, FileLocalAwareLinker {
|
||||||
|
|
||||||
// Kotlin-MPP related data. Consider some refactoring
|
// Kotlin-MPP related data. Consider some refactoring
|
||||||
private val expectUniqIdToActualUniqId = mutableMapOf<IdSignature, IdSignature>()
|
private val expectUniqIdToActualUniqId = mutableMapOf<IdSignature, IdSignature>()
|
||||||
@@ -129,6 +127,14 @@ abstract class KotlinIrLinker(
|
|||||||
fileToDeserializerMap.values.forEach { it.deserializeExpectActualMapping() }
|
fileToDeserializerMap.values.forEach { it.deserializeExpectActualMapping() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun referenceSimpleFunctionByLocalSignature(file: IrFile, idSignature: IdSignature) : IrSimpleFunctionSymbol =
|
||||||
|
fileToDeserializerMap[file]?.referenceSimpleFunctionByLocalSignature(idSignature)
|
||||||
|
?: error("No deserializer for file $file in module ${moduleDescriptor.name}")
|
||||||
|
|
||||||
|
override fun referencePropertyByLocalSignature(file: IrFile, idSignature: IdSignature): IrPropertySymbol =
|
||||||
|
fileToDeserializerMap[file]?.referencePropertyByLocalSignature(idSignature)
|
||||||
|
?: error("No deserializer for file $file in module ${moduleDescriptor.name}")
|
||||||
|
|
||||||
// TODO: fix to topLevel checker
|
// TODO: fix to topLevel checker
|
||||||
override fun contains(idSig: IdSignature): Boolean = idSig in moduleReversedFileIndex
|
override fun contains(idSig: IdSignature): Boolean = idSig in moduleReversedFileIndex
|
||||||
|
|
||||||
@@ -374,6 +380,12 @@ abstract class KotlinIrLinker(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun referenceSimpleFunctionByLocalSignature(idSignature: IdSignature) : IrSimpleFunctionSymbol =
|
||||||
|
deserializeIrSymbolData(idSignature, BinarySymbolData.SymbolKind.FUNCTION_SYMBOL) as IrSimpleFunctionSymbol
|
||||||
|
|
||||||
|
fun referencePropertyByLocalSignature(idSignature: IdSignature): IrPropertySymbol =
|
||||||
|
deserializeIrSymbolData(idSignature, BinarySymbolData.SymbolKind.PROPERTY_SYMBOL) as IrPropertySymbol
|
||||||
|
|
||||||
private fun deserializeIrSymbolData(idSignature: IdSignature, symbolKind: BinarySymbolData.SymbolKind): IrSymbol {
|
private fun deserializeIrSymbolData(idSignature: IdSignature, symbolKind: BinarySymbolData.SymbolKind): IrSymbol {
|
||||||
if (idSignature.isLocal) return deserializeIrLocalSymbolData(idSignature, symbolKind)
|
if (idSignature.isLocal) return deserializeIrLocalSymbolData(idSignature, symbolKind)
|
||||||
|
|
||||||
@@ -591,6 +603,18 @@ abstract class KotlinIrLinker(
|
|||||||
return symbol.owner as IrDeclaration
|
return symbol.owner as IrDeclaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun tryReferencingSimpleFunctionByLocalSignature(parent: IrDeclaration, idSignature: IdSignature): IrSimpleFunctionSymbol? {
|
||||||
|
if (idSignature.isPublic) return null
|
||||||
|
return deserializersForModules[parent.file.packageFragmentDescriptor.containingDeclaration]?.referenceSimpleFunctionByLocalSignature(parent.file, idSignature)
|
||||||
|
?: error("No module deserializer for ${parent.render()}")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun tryReferencingPropertyByLocalSignature(parent: IrDeclaration, idSignature: IdSignature): IrPropertySymbol? {
|
||||||
|
if (idSignature.isPublic) return null
|
||||||
|
return deserializersForModules[parent.file.packageFragmentDescriptor.containingDeclaration]?.referencePropertyByLocalSignature(parent.file, idSignature)
|
||||||
|
?: error("No module deserializer for ${parent.render()}")
|
||||||
|
}
|
||||||
|
|
||||||
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
||||||
CurrentModuleDeserializer(moduleFragment, dependencies)
|
CurrentModuleDeserializer(moduleFragment, dependencies)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user