FIR2IR: split getIrPropertyOrFieldSymbol, handle locals there
This commit is contained in:
@@ -130,7 +130,7 @@ fun FirReference.toSymbol(
|
||||
is FirClassSymbol<*> -> classifierStorage.getIrClassSymbol(boundSymbol).owner.thisReceiver?.symbol
|
||||
is FirFunctionSymbol -> declarationStorage.getIrFunctionSymbol(boundSymbol).owner.extensionReceiverParameter?.symbol
|
||||
is FirPropertySymbol -> {
|
||||
val property = declarationStorage.getIrPropertyOrFieldSymbol(boundSymbol).owner as? IrProperty
|
||||
val property = declarationStorage.getIrPropertySymbol(boundSymbol).owner as? IrProperty
|
||||
property?.let { conversionScope.parentAccessorOfPropertyFromStack(it) }?.symbol
|
||||
}
|
||||
else -> null
|
||||
@@ -149,22 +149,16 @@ private fun FirCallableSymbol<*>.toSymbol(declarationStorage: Fir2IrDeclarationS
|
||||
} else {
|
||||
syntheticProperty.setter!!.delegate.symbol.toSymbol(declarationStorage, preferGetter)
|
||||
}
|
||||
} ?: fir.toSymbol(declarationStorage)
|
||||
} ?: declarationStorage.getIrPropertySymbol(this)
|
||||
}
|
||||
is FirPropertySymbol -> fir.toSymbol(declarationStorage)
|
||||
is FirFieldSymbol -> declarationStorage.getIrPropertyOrFieldSymbol(this)
|
||||
is FirPropertySymbol -> declarationStorage.getIrPropertySymbol(this)
|
||||
is FirFieldSymbol -> declarationStorage.getIrFieldSymbol(this)
|
||||
is FirBackingFieldSymbol -> declarationStorage.getIrBackingFieldSymbol(this)
|
||||
is FirDelegateFieldSymbol<*> -> declarationStorage.getIrBackingFieldSymbol(this)
|
||||
is FirVariableSymbol<*> -> declarationStorage.getIrValueSymbol(this)
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun FirProperty.toSymbol(declarationStorage: Fir2IrDeclarationStorage): IrSymbol? = when {
|
||||
!isLocal -> declarationStorage.getIrPropertyOrFieldSymbol(symbol)
|
||||
delegate != null -> declarationStorage.getIrLocalDelegatedPropertySymbol(symbol)
|
||||
else -> declarationStorage.getIrValueSymbol(symbol)
|
||||
}
|
||||
|
||||
fun FirConstExpression<*>.getIrConstKind(): IrConstKind<*> = when (kind) {
|
||||
FirConstKind.IntegerLiteral -> {
|
||||
val type = typeRef.coneTypeUnsafe<ConeIntegerLiteralType>()
|
||||
@@ -327,7 +321,7 @@ internal fun FirProperty.generateOverriddenAccessorSymbols(
|
||||
if (it.fir.visibility == Visibilities.Private) {
|
||||
return@processDirectlyOverriddenProperties ProcessorAction.NEXT
|
||||
}
|
||||
val overriddenProperty = declarationStorage.getIrPropertyOrFieldSymbol(it.unwrapSubstitutionOverrides()) as IrPropertySymbol
|
||||
val overriddenProperty = declarationStorage.getIrPropertySymbol(it.unwrapSubstitutionOverrides()) as IrPropertySymbol
|
||||
val overriddenAccessor = if (isGetter) overriddenProperty.owner.getter?.symbol else overriddenProperty.owner.setter?.symbol
|
||||
if (overriddenAccessor != null) {
|
||||
overriddenSet += overriddenAccessor
|
||||
|
||||
+43
-49
@@ -9,8 +9,6 @@ import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.BUILT_INS_PACKAGE_FQ_NAMES
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
@@ -1012,53 +1010,54 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
}
|
||||
|
||||
fun getIrPropertyOrFieldSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
return when (val fir = firVariableSymbol.fir) {
|
||||
is FirProperty -> {
|
||||
propertyCache[fir]?.let { return it.symbol }
|
||||
val signature = signatureComposer.composeSignature(fir)
|
||||
val irParent = findIrParent(fir)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
if (signature != null) {
|
||||
symbolTable.referencePropertyIfAny(signature)?.let { irPropertySymbol ->
|
||||
val irProperty = irPropertySymbol.owner
|
||||
propertyCache[fir] = irProperty
|
||||
return irPropertySymbol
|
||||
}
|
||||
// TODO: package fragment members (?)
|
||||
if (irParent is Fir2IrLazyClass) {
|
||||
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
|
||||
"Should not have reference to public API uncached property from source code"
|
||||
fun getIrPropertySymbol(firPropertySymbol: FirPropertySymbol): IrSymbol {
|
||||
val fir = firPropertySymbol.fir
|
||||
if (fir.isLocal) {
|
||||
return localStorage.getDelegatedProperty(fir)?.symbol ?: getIrVariableSymbol(fir)
|
||||
}
|
||||
propertyCache[fir]?.let { return it.symbol }
|
||||
val signature = signatureComposer.composeSignature(fir)
|
||||
val irParent = findIrParent(fir)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
if (signature != null) {
|
||||
symbolTable.referencePropertyIfAny(signature)?.let { irPropertySymbol ->
|
||||
val irProperty = irPropertySymbol.owner
|
||||
propertyCache[fir] = irProperty
|
||||
return irPropertySymbol
|
||||
}
|
||||
// TODO: package fragment members (?)
|
||||
if (irParent is Fir2IrLazyClass) {
|
||||
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
|
||||
"Should not have reference to public API uncached property from source code"
|
||||
}
|
||||
val symbol = Fir2IrPropertySymbol(signature, fir.containerSource)
|
||||
val irProperty = fir.convertWithOffsets { startOffset, endOffset ->
|
||||
symbolTable.declareProperty(signature, { symbol }) {
|
||||
val isFakeOverride =
|
||||
firPropertySymbol.isFakeOverride &&
|
||||
firPropertySymbol.callableId != firPropertySymbol.overriddenSymbol?.callableId
|
||||
Fir2IrLazyProperty(
|
||||
components, startOffset, endOffset, parentOrigin, fir, irParent.fir, symbol, isFakeOverride
|
||||
).apply {
|
||||
parent = irParent
|
||||
}
|
||||
val symbol = Fir2IrPropertySymbol(signature, fir.containerSource)
|
||||
val irProperty = fir.convertWithOffsets { startOffset, endOffset ->
|
||||
symbolTable.declareProperty(signature, { symbol }) {
|
||||
val isFakeOverride =
|
||||
firVariableSymbol is FirPropertySymbol && firVariableSymbol.isFakeOverride &&
|
||||
firVariableSymbol.callableId != firVariableSymbol.overriddenSymbol?.callableId
|
||||
Fir2IrLazyProperty(
|
||||
components, startOffset, endOffset, parentOrigin, fir, irParent.fir, symbol, isFakeOverride
|
||||
).apply {
|
||||
parent = irParent
|
||||
}
|
||||
}
|
||||
}
|
||||
propertyCache[fir] = irProperty
|
||||
return symbol
|
||||
}
|
||||
}
|
||||
createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}.symbol
|
||||
propertyCache[fir] = irProperty
|
||||
return symbol
|
||||
}
|
||||
is FirField -> {
|
||||
fieldCache[fir]?.let { return it.symbol }
|
||||
createIrField(fir).apply {
|
||||
setAndModifyParent(findIrParent(fir))
|
||||
}.symbol
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unexpected fir in property symbol: ${fir.render()}")
|
||||
}
|
||||
return createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}.symbol
|
||||
}
|
||||
|
||||
fun getIrFieldSymbol(firFieldSymbol: FirFieldSymbol): IrSymbol {
|
||||
val fir = firFieldSymbol.fir
|
||||
val irProperty = fieldCache[fir] ?: createIrField(fir).apply {
|
||||
setAndModifyParent(findIrParent(fir))
|
||||
}
|
||||
return irProperty.symbol
|
||||
}
|
||||
|
||||
fun getIrBackingFieldSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
@@ -1085,11 +1084,6 @@ class Fir2IrDeclarationStorage(
|
||||
?: throw IllegalArgumentException("Cannot find variable ${firVariable.render()} in local storage")
|
||||
}
|
||||
|
||||
fun getIrLocalDelegatedPropertySymbol(firPropertySymbol: FirPropertySymbol): IrSymbol {
|
||||
return localStorage.getDelegatedProperty(firPropertySymbol.fir)?.symbol
|
||||
?: throw IllegalArgumentException("Cannot find delegated property ${firPropertySymbol.fir.render()} in local storage")
|
||||
}
|
||||
|
||||
fun getIrValueSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
return when (val firDeclaration = firVariableSymbol.fir) {
|
||||
is FirEnumEntry -> {
|
||||
|
||||
+1
-1
@@ -219,7 +219,7 @@ class FakeOverrideGenerator(
|
||||
isVar: Boolean,
|
||||
firOverriddenSymbol: FirPropertySymbol
|
||||
): IrProperty {
|
||||
val irSymbol = declarationStorage.getIrPropertyOrFieldSymbol(firOverriddenSymbol) as? IrPropertySymbol ?: return this
|
||||
val irSymbol = declarationStorage.getIrPropertySymbol(firOverriddenSymbol) as? IrPropertySymbol ?: return this
|
||||
val overriddenProperty = irSymbol.owner
|
||||
getter?.apply {
|
||||
overriddenProperty.getter?.symbol?.let { overriddenSymbols = listOf(it) }
|
||||
|
||||
@@ -155,7 +155,7 @@ class Fir2IrLazyClass(
|
||||
processedNames += declaration.name
|
||||
scope.processPropertiesByName(declaration.name) {
|
||||
if (it is FirPropertySymbol) {
|
||||
result += declarationStorage.getIrPropertyOrFieldSymbol(it).owner as IrProperty
|
||||
result += declarationStorage.getIrPropertySymbol(it).owner as IrProperty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user