[FIR2IR] Use signature composer only for non-local declarations
This commit is contained in:
@@ -156,7 +156,11 @@ class Fir2IrClassifierStorage(
|
|||||||
return irClass
|
return irClass
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun declareIrClass(signature: IdSignature, factory: (IrClassSymbol) -> IrClass): IrClass {
|
private fun declareIrClass(signature: IdSignature?, factory: (IrClassSymbol) -> IrClass): IrClass {
|
||||||
|
if (signature == null) {
|
||||||
|
val descriptor = WrappedClassDescriptor()
|
||||||
|
return symbolTable.declareClass(descriptor, factory).apply { descriptor.bind(this) }
|
||||||
|
}
|
||||||
return symbolTable.declareClass(signature, { Fir2IrClassSymbol(signature) }, factory)
|
return symbolTable.declareClass(signature, { Fir2IrClassSymbol(signature) }, factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +364,7 @@ class Fir2IrClassifierStorage(
|
|||||||
if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.visibility == Visibilities.LOCAL) {
|
if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.visibility == Visibilities.LOCAL) {
|
||||||
return createIrClass(firClass).symbol
|
return createIrClass(firClass).symbol
|
||||||
}
|
}
|
||||||
val signature = signatureComposer.composeSignature(firClass)
|
val signature = signatureComposer.composeSignature(firClass)!!
|
||||||
symbolTable.referenceClassIfAny(signature)?.let { irClassSymbol ->
|
symbolTable.referenceClassIfAny(signature)?.let { irClassSymbol ->
|
||||||
val irClass = irClassSymbol.owner
|
val irClass = irClassSymbol.owner
|
||||||
classCache[firClass as FirRegularClass] = irClass
|
classCache[firClass as FirRegularClass] = irClass
|
||||||
|
|||||||
+47
-12
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.backend
|
|||||||
import org.jetbrains.kotlin.KtNodeTypes
|
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.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||||
@@ -433,7 +434,11 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun declareIrSimpleFunction(signature: IdSignature, factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction): IrSimpleFunction {
|
private fun declareIrSimpleFunction(signature: IdSignature?, factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction): IrSimpleFunction {
|
||||||
|
if (signature == null) {
|
||||||
|
val descriptor = WrappedSimpleFunctionDescriptor()
|
||||||
|
return symbolTable.declareSimpleFunction(descriptor, factory).apply { descriptor.bind(this) }
|
||||||
|
}
|
||||||
return symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature) }, factory)
|
return symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature) }, factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,7 +524,11 @@ class Fir2IrDeclarationStorage(
|
|||||||
|
|
||||||
fun getCachedIrConstructor(constructor: FirConstructor): IrConstructor? = constructorCache[constructor]
|
fun getCachedIrConstructor(constructor: FirConstructor): IrConstructor? = constructorCache[constructor]
|
||||||
|
|
||||||
private fun declareIrConstructor(signature: IdSignature, factory: (IrConstructorSymbol) -> IrConstructor): IrConstructor {
|
private fun declareIrConstructor(signature: IdSignature?, factory: (IrConstructorSymbol) -> IrConstructor): IrConstructor {
|
||||||
|
if (signature == null) {
|
||||||
|
val descriptor = WrappedClassConstructorDescriptor()
|
||||||
|
return symbolTable.declareConstructor(descriptor, factory).apply { descriptor.bind(this) }
|
||||||
|
}
|
||||||
return symbolTable.declareConstructor(signature, { Fir2IrConstructorSymbol(signature) }, factory)
|
return symbolTable.declareConstructor(signature, { Fir2IrConstructorSymbol(signature) }, factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -550,6 +559,20 @@ class Fir2IrDeclarationStorage(
|
|||||||
return created
|
return created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun declareIrAccessor(
|
||||||
|
signature: IdSignature?,
|
||||||
|
isGetter: Boolean,
|
||||||
|
factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
|
||||||
|
): IrSimpleFunction {
|
||||||
|
if (signature == null) {
|
||||||
|
val descriptor =
|
||||||
|
if (isGetter) WrappedPropertyGetterDescriptor(Annotations.EMPTY, SourceElement.NO_SOURCE)
|
||||||
|
else WrappedPropertySetterDescriptor(Annotations.EMPTY, SourceElement.NO_SOURCE)
|
||||||
|
return symbolTable.declareSimpleFunction(descriptor, factory).apply { descriptor.bind(this) }
|
||||||
|
}
|
||||||
|
return symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature) }, factory)
|
||||||
|
}
|
||||||
|
|
||||||
private fun createIrPropertyAccessor(
|
private fun createIrPropertyAccessor(
|
||||||
propertyAccessor: FirPropertyAccessor?,
|
propertyAccessor: FirPropertyAccessor?,
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
@@ -564,7 +587,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
): IrSimpleFunction {
|
): IrSimpleFunction {
|
||||||
val prefix = if (isSetter) "set" else "get"
|
val prefix = if (isSetter) "set" else "get"
|
||||||
val signature = signatureComposer.composeAccessorSignature(property, isSetter)
|
val signature = signatureComposer.composeAccessorSignature(property, isSetter)
|
||||||
return declareIrSimpleFunction(signature) { symbol ->
|
return declareIrAccessor(signature, isGetter = !isSetter) { symbol ->
|
||||||
val accessorReturnType = if (isSetter) irBuiltIns.unitType else propertyType
|
val accessorReturnType = if (isSetter) irBuiltIns.unitType else propertyType
|
||||||
IrFunctionImpl(
|
IrFunctionImpl(
|
||||||
startOffset, endOffset, origin, symbol,
|
startOffset, endOffset, origin, symbol,
|
||||||
@@ -647,7 +670,13 @@ class Fir2IrDeclarationStorage(
|
|||||||
else -> Visibilities.PRIVATE
|
else -> Visibilities.PRIVATE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun declareIrProperty(signature: IdSignature, factory: (IrPropertySymbol) -> IrProperty): IrProperty {
|
private fun declareIrProperty(signature: IdSignature?, factory: (IrPropertySymbol) -> IrProperty): IrProperty {
|
||||||
|
if (signature == null) {
|
||||||
|
val descriptor = WrappedPropertyDescriptor()
|
||||||
|
return symbolTable.declareProperty(0, 0, IrDeclarationOrigin.DEFINED, descriptor, isDelegated = false, factory).apply {
|
||||||
|
descriptor.bind(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
return symbolTable.declareProperty(signature, { Fir2IrPropertySymbol(signature) }, factory)
|
return symbolTable.declareProperty(signature, { Fir2IrPropertySymbol(signature) }, factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -877,11 +906,14 @@ class Fir2IrDeclarationStorage(
|
|||||||
return when (val firDeclaration = firFunctionSymbol.fir) {
|
return when (val firDeclaration = firFunctionSymbol.fir) {
|
||||||
is FirSimpleFunction, is FirAnonymousFunction -> {
|
is FirSimpleFunction, is FirAnonymousFunction -> {
|
||||||
getCachedIrFunction(firDeclaration)?.let { return it.symbol }
|
getCachedIrFunction(firDeclaration)?.let { return it.symbol }
|
||||||
|
val signature = signatureComposer.composeSignature(firDeclaration)
|
||||||
val irParent = findIrParent(firDeclaration)
|
val irParent = findIrParent(firDeclaration)
|
||||||
symbolTable.referenceSimpleFunctionIfAny(signatureComposer.composeSignature(firDeclaration))?.let { irFunctionSymbol ->
|
if (signature != null) {
|
||||||
val irFunction = irFunctionSymbol.owner
|
symbolTable.referenceSimpleFunctionIfAny(signature)?.let { irFunctionSymbol ->
|
||||||
functionCache[firDeclaration] = irFunction
|
val irFunction = irFunctionSymbol.owner
|
||||||
return irFunctionSymbol
|
functionCache[firDeclaration] = irFunction
|
||||||
|
return irFunctionSymbol
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||||
createIrFunction(firDeclaration, irParent, origin = parentOrigin).apply {
|
createIrFunction(firDeclaration, irParent, origin = parentOrigin).apply {
|
||||||
@@ -899,11 +931,14 @@ class Fir2IrDeclarationStorage(
|
|||||||
return when (val fir = firVariableSymbol.fir) {
|
return when (val fir = firVariableSymbol.fir) {
|
||||||
is FirProperty -> {
|
is FirProperty -> {
|
||||||
propertyCache[fir]?.let { return it.symbol }
|
propertyCache[fir]?.let { return it.symbol }
|
||||||
|
val signature = signatureComposer.composeSignature(fir)
|
||||||
val irParent = findIrParent(fir)
|
val irParent = findIrParent(fir)
|
||||||
symbolTable.referencePropertyIfAny(signatureComposer.composeSignature(fir))?.let { irPropertySymbol ->
|
if (signature != null) {
|
||||||
val irProperty = irPropertySymbol.owner
|
symbolTable.referencePropertyIfAny(signature)?.let { irPropertySymbol ->
|
||||||
propertyCache[fir] = irProperty
|
val irProperty = irPropertySymbol.owner
|
||||||
return irPropertySymbol
|
propertyCache[fir] = irProperty
|
||||||
|
return irPropertySymbol
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||||
createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ import org.jetbrains.kotlin.fir.declarations.FirProperty
|
|||||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||||
|
|
||||||
interface Fir2IrSignatureComposer {
|
interface Fir2IrSignatureComposer {
|
||||||
fun composeSignature(declaration: FirDeclaration): IdSignature
|
fun composeSignature(declaration: FirDeclaration): IdSignature?
|
||||||
fun composeAccessorSignature(property: FirProperty, isSetter: Boolean): IdSignature
|
fun composeAccessorSignature(property: FirProperty, isSetter: Boolean): IdSignature?
|
||||||
}
|
}
|
||||||
+6
-3
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.signaturer
|
package org.jetbrains.kotlin.fir.signaturer
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
|
import org.jetbrains.kotlin.fir.FirEffectiveVisibilityImpl
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.backend.Fir2IrSignatureComposer
|
import org.jetbrains.kotlin.fir.backend.Fir2IrSignatureComposer
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
@@ -53,7 +54,9 @@ class FirBasedSignatureComposer(private val mangler: FirMangler) : Fir2IrSignatu
|
|||||||
private val CallableId.relativeCallableName: FqName
|
private val CallableId.relativeCallableName: FqName
|
||||||
get() = className?.child(callableName) ?: FqName.topLevel(callableName)
|
get() = className?.child(callableName) ?: FqName.topLevel(callableName)
|
||||||
|
|
||||||
override fun composeSignature(declaration: FirDeclaration): IdSignature {
|
override fun composeSignature(declaration: FirDeclaration): IdSignature? {
|
||||||
|
if (declaration is FirAnonymousObject || declaration is FirAnonymousFunction) return null
|
||||||
|
if (declaration is FirMemberDeclaration && declaration.effectiveVisibility == FirEffectiveVisibilityImpl.Local) return null
|
||||||
val builder = SignatureBuilder()
|
val builder = SignatureBuilder()
|
||||||
declaration.accept(builder)
|
declaration.accept(builder)
|
||||||
return when {
|
return when {
|
||||||
@@ -69,8 +72,8 @@ class FirBasedSignatureComposer(private val mangler: FirMangler) : Fir2IrSignatu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun composeAccessorSignature(property: FirProperty, isSetter: Boolean): IdSignature {
|
override fun composeAccessorSignature(property: FirProperty, isSetter: Boolean): IdSignature? {
|
||||||
val propertySignature = composeSignature(property) as IdSignature.PublicSignature
|
val propertySignature = composeSignature(property) as? IdSignature.PublicSignature ?: return null
|
||||||
val accessorFqName = if (isSetter) {
|
val accessorFqName = if (isSetter) {
|
||||||
propertySignature.declarationFqn.child(Name.special("<set-${property.name}>"))
|
propertySignature.declarationFqn.child(Name.special("<set-${property.name}>"))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user