From 1aa7f36bd9edc30f6d36672c60c06e19681e6238 Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Mon, 30 Sep 2024 15:24:28 +0200 Subject: [PATCH] [Ir.Actualizer] Fix property to field actualization In before, the link to temporary field inside f/o property was left in tree. In fact, this doesn't break anything in normal compilation, because of the backend ability to work with slightly incorrect IR. But it can become a problem after some stdlib code changes, or when -Xserialize-ir is enabled. ^KT-71826 Fixed --- .../actualizer/SpecialFakeOverrideSymbolsResolver.kt | 3 ++- .../k2/AbstractMutableList_modCount.fir.ir.txt | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/ir/ir.actualization/src/main/kotlin/org/jetbrains/kotlin/backend/common/actualizer/SpecialFakeOverrideSymbolsResolver.kt b/compiler/ir/ir.actualization/src/main/kotlin/org/jetbrains/kotlin/backend/common/actualizer/SpecialFakeOverrideSymbolsResolver.kt index 76b6b83438fc5..bf2ac2038bb7b 100644 --- a/compiler/ir/ir.actualization/src/main/kotlin/org/jetbrains/kotlin/backend/common/actualizer/SpecialFakeOverrideSymbolsResolver.kt +++ b/compiler/ir/ir.actualization/src/main/kotlin/org/jetbrains/kotlin/backend/common/actualizer/SpecialFakeOverrideSymbolsResolver.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.ir.util.SymbolRemapper import org.jetbrains.kotlin.ir.util.isGetter import org.jetbrains.kotlin.ir.util.isSetter import org.jetbrains.kotlin.ir.util.render +import org.jetbrains.kotlin.ir.util.resolveFakeOverride import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid @@ -242,7 +243,7 @@ class SpecialFakeOverrideSymbolsActualizedByFieldsTransformer( val originalAccessorSymbol = fakeOverrideAccessorSymbol.originalSymbol val actualizedClassSymbol = fakeOverrideAccessorSymbol.containingClassSymbol - val actualFieldSymbol = expectActualMap.propertyAccessorsActualizedByFields[originalAccessorSymbol]?.owner?.backingField?.symbol + val actualFieldSymbol = expectActualMap.propertyAccessorsActualizedByFields[originalAccessorSymbol]?.owner?.resolveFakeOverride()?.backingField?.symbol ?: error("No override for $originalAccessorSymbol in $actualizedClassSymbol") return when { diff --git a/compiler/testData/codegen/box/multiplatform/k2/AbstractMutableList_modCount.fir.ir.txt b/compiler/testData/codegen/box/multiplatform/k2/AbstractMutableList_modCount.fir.ir.txt index f527f1d32c2c4..1cf878af56231 100644 --- a/compiler/testData/codegen/box/multiplatform/k2/AbstractMutableList_modCount.fir.ir.txt +++ b/compiler/testData/codegen/box/multiplatform/k2/AbstractMutableList_modCount.fir.ir.txt @@ -160,7 +160,7 @@ FILE fqName:kotlin.collections fileName:/common.kt $this: VALUE_PARAMETER name: type:kotlin.collections.AbstractMyMutableList BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun getModCountAtAbstractMyMutableList (): kotlin.Int declared in kotlin.collections.AbstractMyMutableList' - GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in kotlin.collections.AbstractMutableList' type=kotlin.Int origin=GET_PROPERTY + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in bar.JavaAbstractMutableList' type=kotlin.Int origin=GET_PROPERTY receiver: GET_VAR ': kotlin.collections.AbstractMyMutableList declared in kotlin.collections.AbstractMyMutableList.getModCountAtAbstractMyMutableList' type=kotlin.collections.AbstractMyMutableList origin=null FUN name:getModCountViaReferenceAtAbstractMyMutableList visibility:public modality:FINAL <> ($this:kotlin.collections.AbstractMyMutableList) returnType:kotlin.Int $this: VALUE_PARAMETER name: type:kotlin.collections.AbstractMyMutableList @@ -176,9 +176,9 @@ FILE fqName:kotlin.collections fileName:/common.kt TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit BLOCK type=kotlin.Int origin=POSTFIX_INCR VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int [val] - GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in kotlin.collections.AbstractMutableList' type=kotlin.Int origin=POSTFIX_INCR + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in bar.JavaAbstractMutableList' type=kotlin.Int origin=POSTFIX_INCR receiver: GET_VAR ': kotlin.collections.AbstractMyMutableList declared in kotlin.collections.AbstractMyMutableList.incrementModCountAtAbstractMyMutableList' type=kotlin.collections.AbstractMyMutableList origin=null - SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in kotlin.collections.AbstractMutableList' type=kotlin.Unit origin=POSTFIX_INCR + SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in bar.JavaAbstractMutableList' type=kotlin.Unit origin=POSTFIX_INCR receiver: GET_VAR ': kotlin.collections.AbstractMyMutableList declared in kotlin.collections.AbstractMyMutableList.incrementModCountAtAbstractMyMutableList' type=kotlin.collections.AbstractMyMutableList origin=null value: CALL 'public final fun inc (): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=POSTFIX_INCR $this: GET_VAR 'val tmp_0: kotlin.Int declared in kotlin.collections.AbstractMyMutableList.incrementModCountAtAbstractMyMutableList' type=kotlin.Int origin=null @@ -243,7 +243,7 @@ FILE fqName:kotlin.collections fileName:/common.kt $this: VALUE_PARAMETER name: type:kotlin.collections.MyMutableList BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun getModCountAtMyMutableList (): kotlin.Int declared in kotlin.collections.MyMutableList' - GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in kotlin.collections.AbstractMutableList' type=kotlin.Int origin=GET_PROPERTY + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in bar.JavaAbstractMutableList' type=kotlin.Int origin=GET_PROPERTY receiver: GET_VAR ': kotlin.collections.MyMutableList declared in kotlin.collections.MyMutableList.getModCountAtMyMutableList' type=kotlin.collections.MyMutableList origin=null FUN name:getModCountViaReferenceAtMyMutableList visibility:public modality:FINAL <> ($this:kotlin.collections.MyMutableList) returnType:kotlin.Int $this: VALUE_PARAMETER name: type:kotlin.collections.MyMutableList @@ -259,9 +259,9 @@ FILE fqName:kotlin.collections fileName:/common.kt TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit BLOCK type=kotlin.Int origin=POSTFIX_INCR VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int [val] - GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in kotlin.collections.AbstractMutableList' type=kotlin.Int origin=POSTFIX_INCR + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in bar.JavaAbstractMutableList' type=kotlin.Int origin=POSTFIX_INCR receiver: GET_VAR ': kotlin.collections.MyMutableList declared in kotlin.collections.MyMutableList.incrementModCountAtMyMutableList' type=kotlin.collections.MyMutableList origin=null - SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in kotlin.collections.AbstractMutableList' type=kotlin.Unit origin=POSTFIX_INCR + SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:modCount type:kotlin.Int visibility:protected/*protected and package*/ declared in bar.JavaAbstractMutableList' type=kotlin.Unit origin=POSTFIX_INCR receiver: GET_VAR ': kotlin.collections.MyMutableList declared in kotlin.collections.MyMutableList.incrementModCountAtMyMutableList' type=kotlin.collections.MyMutableList origin=null value: CALL 'public final fun inc (): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=POSTFIX_INCR $this: GET_VAR 'val tmp_1: kotlin.Int declared in kotlin.collections.MyMutableList.incrementModCountAtMyMutableList' type=kotlin.Int origin=null