From ca401cb01dfa88ba0dce6a0394a0670122128680 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 20 Jun 2019 12:46:38 +0300 Subject: [PATCH] FIR2IR: support backing field symbols from FIR, fix test data --- .../kotlin/fir/backend/ConversionUtils.kt | 3 +- .../fir/backend/Fir2IrDeclarationStorage.kt | 4 +- .../ir/irText/classes/initVar.fir.txt | 9 ++-- .../declarations/classLevelProperties.fir.txt | 3 +- .../packageLevelProperties.fir.txt | 3 +- .../ir/irText/expressions/field.fir.txt | 7 ++-- .../expressions/propertyReferences.fir.txt | 41 ++++++++++--------- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt index 39eb4078e57..6dd3956f24c 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt @@ -106,6 +106,7 @@ fun FirNamedReference.toSymbol(declarationStorage: Fir2IrDeclarationStorage): Ir when (val callableSymbol = this.coneSymbol) { is FirFunctionSymbol -> return callableSymbol.toFunctionSymbol(declarationStorage) is FirPropertySymbol -> return callableSymbol.toPropertyOrFieldSymbol(declarationStorage) + is FirBackingFieldSymbol -> return callableSymbol.toPropertyOrFieldSymbol(declarationStorage) is FirVariableSymbol -> return callableSymbol.toValueSymbol(declarationStorage) } } @@ -124,7 +125,7 @@ fun FirFunctionSymbol.toFunctionSymbol(declarationStorage: Fir2IrDeclarationStor return declarationStorage.getIrFunctionSymbol(this) } -fun FirPropertySymbol.toPropertyOrFieldSymbol(declarationStorage: Fir2IrDeclarationStorage): IrSymbol { +fun FirVariableSymbol.toPropertyOrFieldSymbol(declarationStorage: Fir2IrDeclarationStorage): IrSymbol { return declarationStorage.getIrPropertyOrFieldSymbol(this) } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 109813e3be8..a7ac6f69b82 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -499,8 +499,8 @@ class Fir2IrDeclarationStorage( } } - fun getIrPropertyOrFieldSymbol(firPropertySymbol: FirPropertySymbol): IrSymbol { - return when (val fir = firPropertySymbol.fir) { + fun getIrPropertyOrFieldSymbol(firVariableSymbol: FirVariableSymbol): IrSymbol { + return when (val fir = firVariableSymbol.fir) { is FirProperty -> { val irProperty = getIrProperty(fir).apply { setAndModifyParent(findIrParent(fir)) diff --git a/compiler/testData/ir/irText/classes/initVar.fir.txt b/compiler/testData/ir/irText/classes/initVar.fir.txt index 921c3fa1a77..27f08e3fb2d 100644 --- a/compiler/testData/ir/irText/classes/initVar.fir.txt +++ b/compiler/testData/ir/irText/classes/initVar.fir.txt @@ -138,7 +138,8 @@ FILE fqName: fileName:/initVar.kt $this: VALUE_PARAMETER name: type:.TestInitVarWithCustomSetter VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public ' type=kotlin.Int origin=null + value: GET_VAR 'value: kotlin.Int declared in .TestInitVarWithCustomSetter.' type=kotlin.Int origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any @@ -168,7 +169,8 @@ FILE fqName: fileName:/initVar.kt $this: VALUE_PARAMETER name: type:.TestInitVarWithCustomSetterWithExplicitCtor VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public ' type=kotlin.Int origin=null + value: GET_VAR 'value: kotlin.Int declared in .TestInitVarWithCustomSetterWithExplicitCtor.' type=kotlin.Int origin=null ANONYMOUS_INITIALIZER isStatic=false BLOCK_BODY SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public ' type=kotlin.Int origin=null @@ -206,7 +208,8 @@ FILE fqName: fileName:/initVar.kt $this: VALUE_PARAMETER name: type:.TestInitVarWithCustomSetterInCtor VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public ' type=kotlin.Int origin=null + value: GET_VAR 'value: kotlin.Int declared in .TestInitVarWithCustomSetterInCtor.' type=kotlin.Int origin=null CONSTRUCTOR visibility:public <> () returnType:.TestInitVarWithCustomSetterInCtor BLOCK_BODY SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public ' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/declarations/classLevelProperties.fir.txt b/compiler/testData/ir/irText/declarations/classLevelProperties.fir.txt index 679f48d50b9..a6438a2bc31 100644 --- a/compiler/testData/ir/irText/declarations/classLevelProperties.fir.txt +++ b/compiler/testData/ir/irText/declarations/classLevelProperties.fir.txt @@ -58,7 +58,8 @@ FILE fqName: fileName:/classLevelProperties.kt $this: VALUE_PARAMETER name: type:.C VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test4 type:kotlin.Int visibility:public ' type=kotlin.Int origin=null + value: GET_VAR 'value: kotlin.Int declared in .C.' type=kotlin.Int origin=null PROPERTY name:test5 visibility:public modality:FINAL [var] FIELD PROPERTY_BACKING_FIELD name:test5 type:kotlin.Int visibility:public EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/declarations/packageLevelProperties.fir.txt b/compiler/testData/ir/irText/declarations/packageLevelProperties.fir.txt index 5cee1f39323..6ade103189b 100644 --- a/compiler/testData/ir/irText/declarations/packageLevelProperties.fir.txt +++ b/compiler/testData/ir/irText/declarations/packageLevelProperties.fir.txt @@ -42,7 +42,8 @@ FILE fqName: fileName:/packageLevelProperties.kt correspondingProperty: PROPERTY name:test4 visibility:public modality:FINAL [var] VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test4 type:kotlin.Int visibility:public [static] ' type=kotlin.Int origin=null + value: GET_VAR 'value: kotlin.Int declared in .' type=kotlin.Int origin=null PROPERTY name:test5 visibility:public modality:FINAL [var] FIELD PROPERTY_BACKING_FIELD name:test5 type:kotlin.Int visibility:public [static] EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/expressions/field.fir.txt b/compiler/testData/ir/irText/expressions/field.fir.txt index e805887df39..58e5aa5e91e 100644 --- a/compiler/testData/ir/irText/expressions/field.fir.txt +++ b/compiler/testData/ir/irText/expressions/field.fir.txt @@ -12,7 +12,8 @@ FILE fqName: fileName:/field.kt correspondingProperty: PROPERTY name:testSimple visibility:public modality:FINAL [var] VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:testSimple type:kotlin.Int visibility:public [static] ' type=kotlin.Int origin=null + value: GET_VAR 'value: kotlin.Int declared in .' type=kotlin.Int origin=null PROPERTY name:testAugmented visibility:public modality:FINAL [var] FIELD PROPERTY_BACKING_FIELD name:testAugmented type:kotlin.Int visibility:public [static] EXPRESSION_BODY @@ -26,5 +27,5 @@ FILE fqName: fileName:/field.kt correspondingProperty: PROPERTY name:testAugmented visibility:public modality:FINAL [var] VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:testAugmented type:kotlin.Int visibility:public [static] ' type=kotlin.Int origin=null + value: GET_VAR 'value: kotlin.Int declared in .' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/expressions/propertyReferences.fir.txt b/compiler/testData/ir/irText/expressions/propertyReferences.fir.txt index 46e7da87791..91b6440439d 100644 --- a/compiler/testData/ir/irText/expressions/propertyReferences.fir.txt +++ b/compiler/testData/ir/irText/expressions/propertyReferences.fir.txt @@ -130,12 +130,13 @@ FILE fqName: fileName:/propertyReferences.kt correspondingProperty: PROPERTY name:varWithBackingFieldAndAccessors visibility:public modality:FINAL [var] BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + ERROR_CALL 'No getter found for F|/varWithBackingFieldAndAccessors|' type=kotlin.Int FUN name: visibility:public modality:FINAL <> (value:kotlin.Int) returnType:kotlin.Unit correspondingProperty: PROPERTY name:varWithBackingFieldAndAccessors visibility:public modality:FINAL [var] VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:varWithBackingFieldAndAccessors type:kotlin.Int visibility:public [static] ' type=kotlin.Int origin=null + value: GET_VAR 'value: kotlin.Int declared in .' type=kotlin.Int origin=null PROPERTY name:test_varWithBackingFieldAndAccessors visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:test_varWithBackingFieldAndAccessors type:kotlin.Int visibility:public [final,static] EXPRESSION_BODY @@ -146,39 +147,39 @@ FILE fqName: fileName:/propertyReferences.kt RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in ' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_varWithBackingFieldAndAccessors type:kotlin.Int visibility:public [final,static] ' type=kotlin.Int origin=null PROPERTY name:valWithAccessors visibility:public modality:FINAL [val] - FUN name: visibility:public modality:FINAL <> () returnType:IrErrorType + FUN name: visibility:public modality:FINAL <> () returnType:kotlin.Int correspondingProperty: PROPERTY name:valWithAccessors visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - CONST Int type=IrErrorType value=1 + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 PROPERTY name:test_valWithAccessors visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:test_valWithAccessors type:IrErrorType visibility:public [final,static] + FIELD PROPERTY_BACKING_FIELD name:test_valWithAccessors type:kotlin.Int visibility:public [final,static] EXPRESSION_BODY - CALL 'public final fun (): IrErrorType declared in ' type=IrErrorType origin=null - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType + CALL 'public final fun (): kotlin.Int declared in ' type=kotlin.Int origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Int correspondingProperty: PROPERTY name:test_valWithAccessors visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_valWithAccessors type:IrErrorType visibility:public [final,static] ' type=IrErrorType origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_valWithAccessors type:kotlin.Int visibility:public [final,static] ' type=kotlin.Int origin=null PROPERTY name:varWithAccessors visibility:public modality:FINAL [var] - FUN name: visibility:public modality:FINAL <> () returnType:IrErrorType + FUN name: visibility:public modality:FINAL <> () returnType:kotlin.Int correspondingProperty: PROPERTY name:varWithAccessors visibility:public modality:FINAL [var] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - CONST Int type=IrErrorType value=1 - FUN name: visibility:public modality:FINAL <> (value:IrErrorType) returnType:kotlin.Unit + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name: visibility:public modality:FINAL <> (value:kotlin.Int) returnType:kotlin.Unit correspondingProperty: PROPERTY name:varWithAccessors visibility:public modality:FINAL [var] - VALUE_PARAMETER name:value index:0 type:IrErrorType + VALUE_PARAMETER name:value index:0 type:kotlin.Int BLOCK_BODY PROPERTY name:test_varWithAccessors visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:test_varWithAccessors type:IrErrorType visibility:public [final,static] + FIELD PROPERTY_BACKING_FIELD name:test_varWithAccessors type:kotlin.Int visibility:public [final,static] EXPRESSION_BODY - CALL 'public final fun (): IrErrorType declared in ' type=IrErrorType origin=null - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType + CALL 'public final fun (): kotlin.Int declared in ' type=kotlin.Int origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Int correspondingProperty: PROPERTY name:test_varWithAccessors visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_varWithAccessors type:IrErrorType visibility:public [final,static] ' type=IrErrorType origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_varWithAccessors type:kotlin.Int visibility:public [final,static] ' type=kotlin.Int origin=null PROPERTY name:delegatedVal visibility:public modality:FINAL [delegated,val] FIELD PROPERTY_BACKING_FIELD name:delegatedVal type:IrErrorType visibility:public [final,static] FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType