From a0b814a1b63c5ea681865a66c88b49b0791cc146 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Wed, 5 Oct 2022 14:06:23 +0200 Subject: [PATCH] [FIR] make FirPropertyAccessor#propertySymbol non-nullable we need it to restore property accessor by property ^KT-54311 --- .../api/fir/symbols/KtFirPropertyGetterSymbol.kt | 2 +- .../api/fir/symbols/KtFirPropertySetterSymbol.kt | 2 +- .../RedundantVisibilityModifierSyntaxChecker.kt | 4 ++-- .../kotlin/fir/backend/jvm/FirJvmMangleComputer.kt | 2 +- .../fir/backend/jvm/FirMetadataSerializer.kt | 14 ++++++++++---- .../kotlin/fir/backend/ConversionUtils.kt | 2 +- .../kotlin/fir/signaturer/FirManglerUtil.kt | 2 +- .../JavaAnnotationSyntheticPropertiesScope.kt | 4 ++-- .../kotlin/fir/declarations/FirPropertyAccessor.kt | 2 +- .../builder/FirPropertyAccessorBuilder.kt | 2 +- .../declarations/impl/FirPropertyAccessorImpl.kt | 2 +- .../impl/FirDefaultPropertyAccessor.kt | 4 ++-- .../synthetic/FirSyntheticPropertyAccessor.kt | 8 +++----- .../synthetic/FirSyntheticPropertyBuilder.kt | 6 +++--- .../kotlin/fir/tree/generator/NodeConfigurator.kt | 4 ++-- 15 files changed, 32 insertions(+), 28 deletions(-) diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertyGetterSymbol.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertyGetterSymbol.kt index cc7aa33ef23..e78d5457e48 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertyGetterSymbol.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertyGetterSymbol.kt @@ -47,7 +47,7 @@ internal class KtFirPropertyGetterSymbol( override val isOverride: Boolean get() = withValidityAssertion { 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 } diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertySetterSymbol.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertySetterSymbol.kt index af8f5fe13af..bcb02ef3715 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertySetterSymbol.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertySetterSymbol.kt @@ -51,7 +51,7 @@ internal class KtFirPropertySetterSymbol( override val isOverride: Boolean get() = withValidityAssertion { if (firSymbol.isOverride) return true - val propertySymbol = firSymbol.fir.propertySymbol ?: return@withValidityAssertion false + val propertySymbol = firSymbol.fir.propertySymbol if (!propertySymbol.isOverride) return false val session = firResolveSession.useSiteFirSession val containingClassScope = firSymbol.dispatchReceiverType?.scope( diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierSyntaxChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierSyntaxChecker.kt index 3551e92ac6b..8c3e2cafba6 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierSyntaxChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierSyntaxChecker.kt @@ -184,7 +184,7 @@ object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker= 2 && context.containingDeclarations.asReversed()[1] is FirClass - && propertySymbol?.isOverride == true -> findPropertyAccessorVisibility(this, context) + && propertySymbol.isOverride -> findPropertyAccessorVisibility(this, context) this is FirPropertyAccessor -> { context.findClosest()?.visibility ?: Visibilities.DEFAULT_VISIBILITY @@ -234,7 +234,7 @@ object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker = if (this is FirPropertyAccessor) - this.propertySymbol?.fir?.contextReceivers.orEmpty() + this.propertySymbol.fir.contextReceivers else this.contextReceivers diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirManglerUtil.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirManglerUtil.kt index 76e9585c7aa..cf7794faa11 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirManglerUtil.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirManglerUtil.kt @@ -20,7 +20,7 @@ val FirCallableDeclaration.irName: Name isSetter -> " error("unknown property accessor kind $this") } - Name.special(prefix + propertySymbol!!.fir.name + ">") + Name.special(prefix + propertySymbol.fir.name + ">") } else -> SpecialNames.ANONYMOUS } diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaAnnotationSyntheticPropertiesScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaAnnotationSyntheticPropertiesScope.kt index 8aac4f6b65d..f5ad53116c3 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaAnnotationSyntheticPropertiesScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaAnnotationSyntheticPropertiesScope.kt @@ -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. */ @@ -46,7 +46,7 @@ class JavaAnnotationSyntheticPropertiesScope( val symbol = syntheticPropertiesCache.getOrPut(functionSymbol) { val callableId = CallableId(classId, name) FirJavaOverriddenSyntheticPropertySymbol(callableId, callableId).also { - val accessor = FirSyntheticPropertyAccessor(function, isGetter = true) + val accessor = FirSyntheticPropertyAccessor(function, isGetter = true, it) FirSyntheticProperty( session.nullableModuleData ?: function.moduleData, name, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirPropertyAccessor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirPropertyAccessor.kt index 63b8056d652..93064fbadda 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirPropertyAccessor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirPropertyAccessor.kt @@ -42,7 +42,7 @@ abstract class FirPropertyAccessor : FirFunction(), FirContractDescriptionOwner, abstract override val body: FirBlock? abstract override val contractDescription: FirContractDescription abstract override val symbol: FirPropertyAccessorSymbol - abstract val propertySymbol: FirPropertySymbol? + abstract val propertySymbol: FirPropertySymbol abstract val isGetter: Boolean abstract val isSetter: Boolean abstract override val annotations: List diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyAccessorBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyAccessorBuilder.kt index 15759519c74..6051220a381 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyAccessorBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyAccessorBuilder.kt @@ -60,7 +60,7 @@ class FirPropertyAccessorBuilder : FirFunctionBuilder, FirAnnotationContainerBui override var body: FirBlock? = null var contractDescription: FirContractDescription = FirEmptyContractDescription lateinit var symbol: FirPropertyAccessorSymbol - var propertySymbol: FirPropertySymbol? = null + lateinit var propertySymbol: FirPropertySymbol var isGetter: Boolean by kotlin.properties.Delegates.notNull() override val annotations: MutableList = mutableListOf() val typeParameters: MutableList = mutableListOf() diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt index 83e28c1e524..ac2afd2452a 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt @@ -53,7 +53,7 @@ open class FirPropertyAccessorImpl @FirImplementationDetail constructor( override var body: FirBlock?, override var contractDescription: FirContractDescription, override val symbol: FirPropertyAccessorSymbol, - override val propertySymbol: FirPropertySymbol?, + override val propertySymbol: FirPropertySymbol, override val isGetter: Boolean, override val annotations: MutableList, override val typeParameters: MutableList, diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt index 7585e8434e1..6b2b1f070d3 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt @@ -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. */ @@ -64,7 +64,7 @@ abstract class FirDefaultPropertyAccessor( typeParameters = mutableListOf(), ) { override val dispatchReceiverType: ConeSimpleKotlinType? - get() = propertySymbol?.dispatchReceiverType + get() = propertySymbol.dispatchReceiverType final override var body: FirBlock? get() = null diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyAccessor.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyAccessor.kt index 7dc04f9a260..3f9900daef1 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyAccessor.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyAccessor.kt @@ -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. */ @@ -24,7 +24,8 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ class FirSyntheticPropertyAccessor( val delegate: FirSimpleFunction, - override val isGetter: Boolean + override val isGetter: Boolean, + override val propertySymbol: FirPropertySymbol, ) : FirPropertyAccessor() { override val source: KtSourceElement? get() = delegate.source @@ -78,9 +79,6 @@ class FirSyntheticPropertyAccessor( override val contextReceivers: List get() = emptyList() - // NB: unused - override val propertySymbol: FirPropertySymbol? = null - override val controlFlowGraphReference: FirControlFlowGraphReference? = null override val contractDescription: FirContractDescription = FirEmptyContractDescription diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyBuilder.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyBuilder.kt index 5e92a2e6214..ab4d49b2b56 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyBuilder.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyBuilder.kt @@ -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. */ @@ -27,8 +27,8 @@ class FirSyntheticPropertyBuilder { moduleData, name, isVar = delegateSetter != null, symbol = symbol, status = status ?: delegateGetter.status, resolvePhase = delegateGetter.resolvePhase, - getter = FirSyntheticPropertyAccessor(delegateGetter, isGetter = true), - setter = delegateSetter?.let { FirSyntheticPropertyAccessor(it, isGetter = false) }, + getter = FirSyntheticPropertyAccessor(delegateGetter, isGetter = true, symbol), + setter = delegateSetter?.let { FirSyntheticPropertyAccessor(it, isGetter = false, symbol) }, deprecationsProvider = deprecationsProvider ) } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index 4dd7be4f8fb..72847f01742 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -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. */ @@ -337,7 +337,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild propertyAccessor.configure { +symbol("FirPropertyAccessorSymbol") - +field("propertySymbol", firPropertySymbolType, nullable = true).apply { + +field("propertySymbol", firPropertySymbolType).apply { withBindThis = false } +booleanField("isGetter")