JVM_IR: register builtin annotation constructors in SymbolTable
When deserializing IR, these annotations need to be visible.
This commit is contained in:
committed by
TeamCityServer
parent
8d15a1d13d
commit
ec1c97c684
+14
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createParameterDeclarations
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.SingletonObjectJvmStaticTransformer
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.deserializeClassFromByteArray
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.deserializeIrFileFromByteArray
|
||||
@@ -15,6 +16,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrMangler
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addConstructor
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildClass
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -184,6 +186,8 @@ open class JvmGeneratorExtensionsImpl(private val generateFacades: Boolean = tru
|
||||
private val kotlinJvmInternalPackage =
|
||||
IrExternalPackageFragmentImpl(DescriptorlessExternalPackageFragmentSymbol(), JvmAnnotationNames.KOTLIN_JVM_INTERNAL)
|
||||
|
||||
private val specialAnnotationConstructors = mutableListOf<IrConstructor>()
|
||||
|
||||
private fun createSpecialAnnotationClass(fqn: FqName, parent: IrPackageFragment) =
|
||||
IrFactoryImpl.buildClass {
|
||||
kind = ClassKind.ANNOTATION_CLASS
|
||||
@@ -193,6 +197,8 @@ open class JvmGeneratorExtensionsImpl(private val generateFacades: Boolean = tru
|
||||
this.parent = parent
|
||||
addConstructor {
|
||||
isPrimary = true
|
||||
}.also { constructor ->
|
||||
specialAnnotationConstructors.add(constructor)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +224,14 @@ open class JvmGeneratorExtensionsImpl(private val generateFacades: Boolean = tru
|
||||
)
|
||||
}
|
||||
|
||||
override fun registerDeclarations(symbolTable: SymbolTable) {
|
||||
val signatureComputer = IdSignatureSerializer(JvmIrMangler)
|
||||
specialAnnotationConstructors.forEach { constructor ->
|
||||
symbolTable.declareConstructorWithSignature(signatureComputer.composePublicIdSignature(constructor), constructor.symbol)
|
||||
}
|
||||
super.registerDeclarations(symbolTable)
|
||||
}
|
||||
|
||||
override val shouldPreventDeprecatedIntegerValueTypeLiteralConversion: Boolean
|
||||
get() = true
|
||||
|
||||
|
||||
@@ -47,6 +47,10 @@ abstract class DeclarationStubGenerator(
|
||||
) : IrProvider {
|
||||
protected val lazyTable = symbolTable.lazyWrapper
|
||||
|
||||
init {
|
||||
extensions.registerDeclarations(symbolTable)
|
||||
}
|
||||
|
||||
val lock: IrLock
|
||||
get() = symbolTable.lock
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@ open class StubGeneratorExtensions {
|
||||
open val rawTypeAnnotationConstructor: IrConstructor?
|
||||
get() = null
|
||||
|
||||
open fun registerDeclarations(symbolTable: SymbolTable) {}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val EMPTY = StubGeneratorExtensions()
|
||||
|
||||
@@ -77,6 +77,7 @@ class SymbolTable(
|
||||
abstract fun get(d: D): S?
|
||||
abstract fun set(s: S)
|
||||
abstract fun get(sig: IdSignature): S?
|
||||
abstract fun set(sig: IdSignature, s: S)
|
||||
|
||||
inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
|
||||
synchronized(lock) {
|
||||
@@ -217,6 +218,10 @@ class SymbolTable(
|
||||
}
|
||||
|
||||
override fun get(sig: IdSignature): S? = idSigToSymbol[sig]
|
||||
|
||||
override fun set(sig: IdSignature, s: S) {
|
||||
idSigToSymbol[sig] = s
|
||||
}
|
||||
}
|
||||
|
||||
private inner class EnumEntrySymbolTable : FlatSymbolTable<ClassDescriptor, IrEnumEntry, IrEnumEntrySymbol>() {
|
||||
@@ -265,6 +270,10 @@ class SymbolTable(
|
||||
|
||||
operator fun get(sig: IdSignature): S? = idSigToSymbol[sig] ?: parent?.get(sig)
|
||||
|
||||
operator fun set(sig: IdSignature, s: S) {
|
||||
idSigToSymbol[sig] = s
|
||||
}
|
||||
|
||||
fun dumpTo(stringBuilder: StringBuilder): StringBuilder =
|
||||
stringBuilder.also {
|
||||
it.append("owner=")
|
||||
@@ -296,6 +305,11 @@ class SymbolTable(
|
||||
return scope[sig]
|
||||
}
|
||||
|
||||
override fun set(sig: IdSignature, s: S) {
|
||||
val scope = currentScope ?: throw AssertionError("No active scope")
|
||||
scope[sig] = s
|
||||
}
|
||||
|
||||
inline fun declareLocal(d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
|
||||
val scope = currentScope ?: throw AssertionError("No active scope")
|
||||
val symbol = scope.getLocal(d) ?: createSymbol().also { scope[d] = it }
|
||||
@@ -514,6 +528,10 @@ class SymbolTable(
|
||||
constructorFactory
|
||||
)
|
||||
|
||||
fun declareConstructorWithSignature(sig: IdSignature, symbol: IrConstructorSymbol) {
|
||||
constructorSymbolTable.set(sig, symbol)
|
||||
}
|
||||
|
||||
override fun referenceConstructor(descriptor: ClassConstructorDescriptor) =
|
||||
constructorSymbolTable.referenced(descriptor) { createConstructorSymbol(descriptor) }
|
||||
|
||||
|
||||
+1
@@ -303,6 +303,7 @@ class IrDeclarationDeserializer(
|
||||
val flags = ClassFlags.decode(fcode)
|
||||
|
||||
symbolTable.declareClass(signature, { symbol as IrClassSymbol }) {
|
||||
assert(it === symbol)
|
||||
irFactory.createClass(
|
||||
startOffset, endOffset, origin,
|
||||
it,
|
||||
|
||||
Reference in New Issue
Block a user