FIR2IR: eager conversion of annotations in Library class and members
This commit is contained in:
committed by
Mikhail Glukhikh
parent
fd32e918d5
commit
ab2a2b3a87
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.backend
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.BuiltinSymbolsBase
|
import org.jetbrains.kotlin.backend.common.ir.BuiltinSymbolsBase
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.backend.generators.AnnotationGenerator
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
|
import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
|
||||||
import org.jetbrains.kotlin.fir.psi
|
import org.jetbrains.kotlin.fir.psi
|
||||||
@@ -182,7 +183,8 @@ class Fir2IrConverter(
|
|||||||
val components = Fir2IrComponentsStorage(session, scopeSession, symbolTable, builtIns, mangler)
|
val components = Fir2IrComponentsStorage(session, scopeSession, symbolTable, builtIns, mangler)
|
||||||
val conversionScope = Fir2IrConversionScope()
|
val conversionScope = Fir2IrConversionScope()
|
||||||
val classifierStorage = Fir2IrClassifierStorage(components)
|
val classifierStorage = Fir2IrClassifierStorage(components)
|
||||||
val declarationStorage = Fir2IrDeclarationStorage(components, moduleDescriptor, classifierStorage, conversionScope, fakeOverrideMode)
|
val declarationStorage =
|
||||||
|
Fir2IrDeclarationStorage(components, moduleDescriptor, classifierStorage, conversionScope, fakeOverrideMode)
|
||||||
val typeConverter = Fir2IrTypeConverter(components)
|
val typeConverter = Fir2IrTypeConverter(components)
|
||||||
components.declarationStorage = declarationStorage
|
components.declarationStorage = declarationStorage
|
||||||
components.classifierStorage = classifierStorage
|
components.classifierStorage = classifierStorage
|
||||||
@@ -212,6 +214,7 @@ class Fir2IrConverter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val fir2irVisitor = Fir2IrVisitor(converter, components, conversionScope, fakeOverrideMode)
|
val fir2irVisitor = Fir2IrVisitor(converter, components, conversionScope, fakeOverrideMode)
|
||||||
|
declarationStorage.annotationGenerator = AnnotationGenerator(fir2irVisitor)
|
||||||
for (firFile in firFiles) {
|
for (firFile in firFiles) {
|
||||||
val irFile = firFile.accept(fir2irVisitor, null) as IrFile
|
val irFile = firFile.accept(fir2irVisitor, null) as IrFile
|
||||||
val fileEntry = sourceManager.getOrCreateFileEntry(firFile.psi as KtFile)
|
val fileEntry = sourceManager.getOrCreateFileEntry(firFile.psi as KtFile)
|
||||||
|
|||||||
+19
-5
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.KtNodeTypes
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.*
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.*
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||||
|
import org.jetbrains.kotlin.fir.backend.generators.AnnotationGenerator
|
||||||
import org.jetbrains.kotlin.fir.backend.generators.FakeOverrideGenerator
|
import org.jetbrains.kotlin.fir.backend.generators.FakeOverrideGenerator
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||||
@@ -22,10 +24,7 @@ import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub
|
|||||||
import org.jetbrains.kotlin.fir.render
|
import org.jetbrains.kotlin.fir.render
|
||||||
import org.jetbrains.kotlin.fir.resolve.*
|
import org.jetbrains.kotlin.fir.resolve.*
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrConstructorSymbol
|
import org.jetbrains.kotlin.fir.symbols.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrPropertySymbol
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrSimpleFunctionSymbol
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
@@ -53,6 +52,9 @@ class Fir2IrDeclarationStorage(
|
|||||||
conversionScope: Fir2IrConversionScope,
|
conversionScope: Fir2IrConversionScope,
|
||||||
fakeOverrideMode: FakeOverrideMode
|
fakeOverrideMode: FakeOverrideMode
|
||||||
) : Fir2IrComponents by components {
|
) : Fir2IrComponents by components {
|
||||||
|
|
||||||
|
internal var annotationGenerator: AnnotationGenerator? = null
|
||||||
|
|
||||||
private val fakeOverrideGenerator = FakeOverrideGenerator(
|
private val fakeOverrideGenerator = FakeOverrideGenerator(
|
||||||
session, components.scopeSession, classifierStorage, this, conversionScope, fakeOverrideMode
|
session, components.scopeSession, classifierStorage, this, conversionScope, fakeOverrideMode
|
||||||
)
|
)
|
||||||
@@ -262,6 +264,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
irDeclaration.parent = irClass
|
irDeclaration.parent = irClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
irClass.convertAnnotationsFromLibrary(regularClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun findIrParent(packageFqName: FqName, parentClassId: ClassId?, firBasedSymbol: FirBasedSymbol<*>): IrDeclarationParent? {
|
internal fun findIrParent(packageFqName: FqName, parentClassId: ClassId?, firBasedSymbol: FirBasedSymbol<*>): IrDeclarationParent? {
|
||||||
@@ -477,6 +480,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
isOperator = simpleFunction?.isOperator == true
|
isOperator = simpleFunction?.isOperator == true
|
||||||
).apply {
|
).apply {
|
||||||
metadata = FirMetadataSource.Function(function)
|
metadata = FirMetadataSource.Function(function)
|
||||||
|
convertAnnotationsFromLibrary(function)
|
||||||
enterScope(this)
|
enterScope(this)
|
||||||
bindAndDeclareParameters(
|
bindAndDeclareParameters(
|
||||||
function, irParent,
|
function, irParent,
|
||||||
@@ -600,8 +604,11 @@ class Fir2IrDeclarationStorage(
|
|||||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||||
isOperator = false
|
isOperator = false
|
||||||
).apply {
|
).apply {
|
||||||
|
correspondingPropertySymbol = correspondingProperty.symbol
|
||||||
if (propertyAccessor != null) {
|
if (propertyAccessor != null) {
|
||||||
metadata = FirMetadataSource.Function(propertyAccessor)
|
metadata = FirMetadataSource.Function(propertyAccessor)
|
||||||
|
// Note that deserialized annotations are stored in the accessor, not the property.
|
||||||
|
convertAnnotationsFromLibrary(propertyAccessor)
|
||||||
}
|
}
|
||||||
with(classifierStorage) {
|
with(classifierStorage) {
|
||||||
setTypeParameters(
|
setTypeParameters(
|
||||||
@@ -625,7 +632,6 @@ class Fir2IrDeclarationStorage(
|
|||||||
if (irParent != null) {
|
if (irParent != null) {
|
||||||
parent = irParent
|
parent = irParent
|
||||||
}
|
}
|
||||||
correspondingPropertySymbol = correspondingProperty.symbol
|
|
||||||
if (!isFakeOverride && thisReceiverOwner != null) {
|
if (!isFakeOverride && thisReceiverOwner != null) {
|
||||||
populateOverriddenSymbols(thisReceiverOwner)
|
populateOverriddenSymbols(thisReceiverOwner)
|
||||||
}
|
}
|
||||||
@@ -661,6 +667,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
}.apply {
|
}.apply {
|
||||||
metadata = FirMetadataSource.Property(property)
|
metadata = FirMetadataSource.Property(property)
|
||||||
|
convertAnnotationsFromLibrary(property)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -709,6 +716,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE
|
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE
|
||||||
).apply {
|
).apply {
|
||||||
metadata = FirMetadataSource.Variable(property)
|
metadata = FirMetadataSource.Variable(property)
|
||||||
|
convertAnnotationsFromLibrary(property)
|
||||||
enterScope(this)
|
enterScope(this)
|
||||||
if (irParent != null) {
|
if (irParent != null) {
|
||||||
parent = irParent
|
parent = irParent
|
||||||
@@ -1023,6 +1031,12 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun IrMutableAnnotationContainer.convertAnnotationsFromLibrary(firAnnotationContainer: FirAnnotationContainer) {
|
||||||
|
if ((firAnnotationContainer as? FirDeclaration)?.isFromLibrary == true) {
|
||||||
|
annotationGenerator?.generate(this, firAnnotationContainer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
internal val ENUM_SYNTHETIC_NAMES = mapOf(
|
internal val ENUM_SYNTHETIC_NAMES = mapOf(
|
||||||
Name.identifier("values") to IrSyntheticBodyKind.ENUM_VALUES,
|
Name.identifier("values") to IrSyntheticBodyKind.ENUM_VALUES,
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ fun FirTypeParameterBuilder.addDefaultBoundIfNecessary(isFlexible: Boolean = fal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline val FirDeclaration.isFromLibrary: Boolean
|
||||||
|
get() = origin == FirDeclarationOrigin.Library
|
||||||
inline val FirRegularClass.isInner get() = status.isInner
|
inline val FirRegularClass.isInner get() = status.isInner
|
||||||
inline val FirRegularClass.isCompanion get() = status.isCompanion
|
inline val FirRegularClass.isCompanion get() = status.isCompanion
|
||||||
inline val FirRegularClass.isData get() = status.isData
|
inline val FirRegularClass.isData get() = status.isData
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// !LANGUAGE: +InlineClasses
|
// !LANGUAGE: +InlineClasses
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// java.lang.NoSuchMethodError: java.util.TreeMap.remove
|
// java.lang.NoSuchMethodError: java.util.TreeMap.remove
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// !LANGUAGE: +MultiPlatformProjects
|
// !LANGUAGE: +MultiPlatformProjects
|
||||||
// !USE_EXPERIMENTAL: kotlin.ExperimentalMultiplatform
|
// !USE_EXPERIMENTAL: kotlin.ExperimentalMultiplatform
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
|
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
Reference in New Issue
Block a user