[FIR] make FirPropertyAccessor#propertySymbol non-nullable

we need it to restore property accessor by property

^KT-54311
This commit is contained in:
Dmitrii Gridin
2022-10-05 14:06:23 +02:00
committed by Space Team
parent c6bbce986d
commit a0b814a1b6
15 changed files with 32 additions and 28 deletions
@@ -47,7 +47,7 @@ internal class KtFirPropertyGetterSymbol(
override val isOverride: Boolean override val isOverride: Boolean
get() = withValidityAssertion { get() = withValidityAssertion {
if (firSymbol.isOverride) return@withValidityAssertion true if (firSymbol.isOverride) return@withValidityAssertion true
return firSymbol.fir.propertySymbol?.isOverride == true return firSymbol.fir.propertySymbol.isOverride
} }
override val hasBody: Boolean get() = withValidityAssertion { firSymbol.fir.body != null } override val hasBody: Boolean get() = withValidityAssertion { firSymbol.fir.body != null }
@@ -51,7 +51,7 @@ internal class KtFirPropertySetterSymbol(
override val isOverride: Boolean override val isOverride: Boolean
get() = withValidityAssertion { get() = withValidityAssertion {
if (firSymbol.isOverride) return true if (firSymbol.isOverride) return true
val propertySymbol = firSymbol.fir.propertySymbol ?: return@withValidityAssertion false val propertySymbol = firSymbol.fir.propertySymbol
if (!propertySymbol.isOverride) return false if (!propertySymbol.isOverride) return false
val session = firResolveSession.useSiteFirSession val session = firResolveSession.useSiteFirSession
val containingClassScope = firSymbol.dispatchReceiverType?.scope( val containingClassScope = firSymbol.dispatchReceiverType?.scope(
@@ -184,7 +184,7 @@ object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker<Fi
&& isSetter && isSetter
&& context.containingDeclarations.size >= 2 && context.containingDeclarations.size >= 2
&& context.containingDeclarations.asReversed()[1] is FirClass && context.containingDeclarations.asReversed()[1] is FirClass
&& propertySymbol?.isOverride == true -> findPropertyAccessorVisibility(this, context) && propertySymbol.isOverride -> findPropertyAccessorVisibility(this, context)
this is FirPropertyAccessor -> { this is FirPropertyAccessor -> {
context.findClosest<FirProperty>()?.visibility ?: Visibilities.DEFAULT_VISIBILITY context.findClosest<FirProperty>()?.visibility ?: Visibilities.DEFAULT_VISIBILITY
@@ -234,7 +234,7 @@ object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker<Fi
private fun findPropertyAccessorVisibility(accessor: FirPropertyAccessor, context: CheckerContext): Visibility { private fun findPropertyAccessorVisibility(accessor: FirPropertyAccessor, context: CheckerContext): Visibility {
val containingClass = context.findClosestClassOrObject()?.symbol ?: return Visibilities.Public val containingClass = context.findClosestClassOrObject()?.symbol ?: return Visibilities.Public
val propertySymbol = accessor.propertySymbol ?: return Visibilities.Public val propertySymbol = accessor.propertySymbol
val scope = containingClass.unsubstitutedScope( val scope = containingClass.unsubstitutedScope(
context.sessionHolder.session, context.sessionHolder.session,
@@ -355,7 +355,7 @@ open class FirJvmMangleComputer(
// No need to distinguish between the accessor and its delegate. // No need to distinguish between the accessor and its delegate.
visitSimpleFunction(propertyAccessor.delegate, data) visitSimpleFunction(propertyAccessor.delegate, data)
} else { } else {
propertyAccessor.mangleFunction(isCtor = false, propertyAccessor.isStatic, propertyAccessor.propertySymbol!!.fir) propertyAccessor.mangleFunction(isCtor = false, propertyAccessor.isStatic, propertyAccessor.propertySymbol.fir)
} }
} }
@@ -217,7 +217,10 @@ private fun FirFunction.copyToFreeAnonymousFunction(approximator: AbstractTypeAp
} }
} }
private fun FirPropertyAccessor.copyToFreeAccessor(approximator: AbstractTypeApproximator): FirPropertyAccessor { private fun FirPropertyAccessor.copyToFreeAccessor(
approximator: AbstractTypeApproximator,
newPropertySymbol: FirPropertySymbol,
): FirPropertyAccessor {
val accessor = this val accessor = this
return buildPropertyAccessor { return buildPropertyAccessor {
val typeParameterSet = accessor.typeParameters.toMutableSet() val typeParameterSet = accessor.typeParameters.toMutableSet()
@@ -225,6 +228,7 @@ private fun FirPropertyAccessor.copyToFreeAccessor(approximator: AbstractTypeApp
origin = FirDeclarationOrigin.Source origin = FirDeclarationOrigin.Source
returnTypeRef = accessor.returnTypeRef.approximated(approximator, typeParameterSet, toSuper = true) returnTypeRef = accessor.returnTypeRef.approximated(approximator, typeParameterSet, toSuper = true)
symbol = FirPropertyAccessorSymbol() symbol = FirPropertyAccessorSymbol()
propertySymbol = newPropertySymbol
isGetter = accessor.isGetter isGetter = accessor.isGetter
status = accessor.status status = accessor.status
accessor.valueParameters.mapTo(valueParameters) { accessor.valueParameters.mapTo(valueParameters) {
@@ -243,7 +247,9 @@ internal fun FirProperty.copyToFreeProperty(approximator: AbstractTypeApproximat
val typeParameterSet = property.typeParameters.toMutableSet() val typeParameterSet = property.typeParameters.toMutableSet()
moduleData = property.moduleData moduleData = property.moduleData
origin = FirDeclarationOrigin.Source origin = FirDeclarationOrigin.Source
symbol = FirPropertySymbol(property.symbol.callableId)
val newPropertySymbol = FirPropertySymbol(property.symbol.callableId)
symbol = newPropertySymbol
returnTypeRef = property.returnTypeRef.approximated(approximator, typeParameterSet, toSuper = true) returnTypeRef = property.returnTypeRef.approximated(approximator, typeParameterSet, toSuper = true)
receiverTypeRef = property.receiverTypeRef?.approximated(approximator, typeParameterSet, toSuper = false) receiverTypeRef = property.receiverTypeRef?.approximated(approximator, typeParameterSet, toSuper = false)
name = property.name name = property.name
@@ -252,8 +258,8 @@ internal fun FirProperty.copyToFreeProperty(approximator: AbstractTypeApproximat
delegateFieldSymbol = property.delegateFieldSymbol?.let { delegateFieldSymbol = property.delegateFieldSymbol?.let {
FirDelegateFieldSymbol(it.callableId) FirDelegateFieldSymbol(it.callableId)
} }
getter = property.getter?.copyToFreeAccessor(approximator) getter = property.getter?.copyToFreeAccessor(approximator, newPropertySymbol)
setter = property.setter?.copyToFreeAccessor(approximator) setter = property.setter?.copyToFreeAccessor(approximator, newPropertySymbol)
isVar = property.isVar isVar = property.isVar
isLocal = property.isLocal isLocal = property.isLocal
status = property.status status = property.status
@@ -718,6 +718,6 @@ fun FirVariableAssignment.getIrAssignmentOrigin(): IrStatementOrigin {
fun FirCallableDeclaration.contextReceiversForFunctionOrContainingProperty(): List<FirContextReceiver> = fun FirCallableDeclaration.contextReceiversForFunctionOrContainingProperty(): List<FirContextReceiver> =
if (this is FirPropertyAccessor) if (this is FirPropertyAccessor)
this.propertySymbol?.fir?.contextReceivers.orEmpty() this.propertySymbol.fir.contextReceivers
else else
this.contextReceivers this.contextReceivers
@@ -20,7 +20,7 @@ val FirCallableDeclaration.irName: Name
isSetter -> "<set-" isSetter -> "<set-"
else -> error("unknown property accessor kind $this") else -> error("unknown property accessor kind $this")
} }
Name.special(prefix + propertySymbol!!.fir.name + ">") Name.special(prefix + propertySymbol.fir.name + ">")
} }
else -> SpecialNames.ANONYMOUS else -> SpecialNames.ANONYMOUS
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -46,7 +46,7 @@ class JavaAnnotationSyntheticPropertiesScope(
val symbol = syntheticPropertiesCache.getOrPut(functionSymbol) { val symbol = syntheticPropertiesCache.getOrPut(functionSymbol) {
val callableId = CallableId(classId, name) val callableId = CallableId(classId, name)
FirJavaOverriddenSyntheticPropertySymbol(callableId, callableId).also { FirJavaOverriddenSyntheticPropertySymbol(callableId, callableId).also {
val accessor = FirSyntheticPropertyAccessor(function, isGetter = true) val accessor = FirSyntheticPropertyAccessor(function, isGetter = true, it)
FirSyntheticProperty( FirSyntheticProperty(
session.nullableModuleData ?: function.moduleData, session.nullableModuleData ?: function.moduleData,
name, name,
@@ -42,7 +42,7 @@ abstract class FirPropertyAccessor : FirFunction(), FirContractDescriptionOwner,
abstract override val body: FirBlock? abstract override val body: FirBlock?
abstract override val contractDescription: FirContractDescription abstract override val contractDescription: FirContractDescription
abstract override val symbol: FirPropertyAccessorSymbol abstract override val symbol: FirPropertyAccessorSymbol
abstract val propertySymbol: FirPropertySymbol? abstract val propertySymbol: FirPropertySymbol
abstract val isGetter: Boolean abstract val isGetter: Boolean
abstract val isSetter: Boolean abstract val isSetter: Boolean
abstract override val annotations: List<FirAnnotation> abstract override val annotations: List<FirAnnotation>
@@ -60,7 +60,7 @@ class FirPropertyAccessorBuilder : FirFunctionBuilder, FirAnnotationContainerBui
override var body: FirBlock? = null override var body: FirBlock? = null
var contractDescription: FirContractDescription = FirEmptyContractDescription var contractDescription: FirContractDescription = FirEmptyContractDescription
lateinit var symbol: FirPropertyAccessorSymbol lateinit var symbol: FirPropertyAccessorSymbol
var propertySymbol: FirPropertySymbol? = null lateinit var propertySymbol: FirPropertySymbol
var isGetter: Boolean by kotlin.properties.Delegates.notNull<Boolean>() var isGetter: Boolean by kotlin.properties.Delegates.notNull<Boolean>()
override val annotations: MutableList<FirAnnotation> = mutableListOf() override val annotations: MutableList<FirAnnotation> = mutableListOf()
val typeParameters: MutableList<FirTypeParameter> = mutableListOf() val typeParameters: MutableList<FirTypeParameter> = mutableListOf()
@@ -53,7 +53,7 @@ open class FirPropertyAccessorImpl @FirImplementationDetail constructor(
override var body: FirBlock?, override var body: FirBlock?,
override var contractDescription: FirContractDescription, override var contractDescription: FirContractDescription,
override val symbol: FirPropertyAccessorSymbol, override val symbol: FirPropertyAccessorSymbol,
override val propertySymbol: FirPropertySymbol?, override val propertySymbol: FirPropertySymbol,
override val isGetter: Boolean, override val isGetter: Boolean,
override val annotations: MutableList<FirAnnotation>, override val annotations: MutableList<FirAnnotation>,
override val typeParameters: MutableList<FirTypeParameter>, override val typeParameters: MutableList<FirTypeParameter>,
@@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -64,7 +64,7 @@ abstract class FirDefaultPropertyAccessor(
typeParameters = mutableListOf(), typeParameters = mutableListOf(),
) { ) {
override val dispatchReceiverType: ConeSimpleKotlinType? override val dispatchReceiverType: ConeSimpleKotlinType?
get() = propertySymbol?.dispatchReceiverType get() = propertySymbol.dispatchReceiverType
final override var body: FirBlock? final override var body: FirBlock?
get() = null get() = null
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -24,7 +24,8 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
class FirSyntheticPropertyAccessor( class FirSyntheticPropertyAccessor(
val delegate: FirSimpleFunction, val delegate: FirSimpleFunction,
override val isGetter: Boolean override val isGetter: Boolean,
override val propertySymbol: FirPropertySymbol,
) : FirPropertyAccessor() { ) : FirPropertyAccessor() {
override val source: KtSourceElement? override val source: KtSourceElement?
get() = delegate.source get() = delegate.source
@@ -78,9 +79,6 @@ class FirSyntheticPropertyAccessor(
override val contextReceivers: List<FirContextReceiver> override val contextReceivers: List<FirContextReceiver>
get() = emptyList() get() = emptyList()
// NB: unused
override val propertySymbol: FirPropertySymbol? = null
override val controlFlowGraphReference: FirControlFlowGraphReference? = null override val controlFlowGraphReference: FirControlFlowGraphReference? = null
override val contractDescription: FirContractDescription = FirEmptyContractDescription override val contractDescription: FirContractDescription = FirEmptyContractDescription
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -27,8 +27,8 @@ class FirSyntheticPropertyBuilder {
moduleData, name, isVar = delegateSetter != null, symbol = symbol, moduleData, name, isVar = delegateSetter != null, symbol = symbol,
status = status ?: delegateGetter.status, status = status ?: delegateGetter.status,
resolvePhase = delegateGetter.resolvePhase, resolvePhase = delegateGetter.resolvePhase,
getter = FirSyntheticPropertyAccessor(delegateGetter, isGetter = true), getter = FirSyntheticPropertyAccessor(delegateGetter, isGetter = true, symbol),
setter = delegateSetter?.let { FirSyntheticPropertyAccessor(it, isGetter = false) }, setter = delegateSetter?.let { FirSyntheticPropertyAccessor(it, isGetter = false, symbol) },
deprecationsProvider = deprecationsProvider deprecationsProvider = deprecationsProvider
) )
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -337,7 +337,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
propertyAccessor.configure { propertyAccessor.configure {
+symbol("FirPropertyAccessorSymbol") +symbol("FirPropertyAccessorSymbol")
+field("propertySymbol", firPropertySymbolType, nullable = true).apply { +field("propertySymbol", firPropertySymbolType).apply {
withBindThis = false withBindThis = false
} }
+booleanField("isGetter") +booleanField("isGetter")