Skip to content

Commit

Permalink
[Ir.Actualizer] Fix property to field actualization
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kunyavskiy authored and qodana-bot committed Oct 1, 2024
1 parent 0a1907d commit 1aa7f36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ FILE fqName:kotlin.collections fileName:/common.kt
$this: VALUE_PARAMETER name:<this> 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 '<this>: 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:<this> type:kotlin.collections.AbstractMyMutableList
Expand All @@ -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 '<this>: 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 '<this>: 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
Expand Down Expand Up @@ -243,7 +243,7 @@ FILE fqName:kotlin.collections fileName:/common.kt
$this: VALUE_PARAMETER name:<this> 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 '<this>: 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:<this> type:kotlin.collections.MyMutableList
Expand All @@ -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 '<this>: 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 '<this>: 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
Expand Down

0 comments on commit 1aa7f36

Please sign in to comment.