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 8e60d909fdf..2f8668eb72b 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 @@ -874,6 +874,11 @@ class Fir2IrDeclarationStorage( is FirSimpleFunction, is FirAnonymousFunction -> { getCachedIrFunction(firDeclaration)?.let { return it.symbol } val irParent = findIrParent(firDeclaration) + symbolTable.referenceSimpleFunctionIfAny(signatureComposer.composeSignature(firDeclaration))?.let { irFunctionSymbol -> + val irFunction = irFunctionSymbol.owner + functionCache[firDeclaration] = irFunction + return irFunctionSymbol + } val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED createIrFunction(firDeclaration, irParent, origin = parentOrigin).apply { setAndModifyParent(irParent) @@ -891,6 +896,11 @@ class Fir2IrDeclarationStorage( is FirProperty -> { propertyCache[fir]?.let { return it.symbol } val irParent = findIrParent(fir) + symbolTable.referencePropertyIfAny(signatureComposer.composeSignature(fir))?.let { irPropertySymbol -> + val irProperty = irPropertySymbol.owner + propertyCache[fir] = irProperty + return irPropertySymbol + } val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED createIrProperty(fir, irParent, origin = parentOrigin).apply { setAndModifyParent(irParent) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt index 41426a0d9c9..841a23c1d96 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt @@ -633,6 +633,9 @@ open class SymbolTable( override fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol = propertySymbolTable.referenced(descriptor) { createPropertySymbol(descriptor) } + fun referencePropertyIfAny(sig: IdSignature): IrPropertySymbol? = + propertySymbolTable.get(sig) + override fun referencePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrPropertySymbol = propertySymbolTable.run { if (sig.isPublic) referenced(sig) { IrPropertyPublicSymbolImpl(descriptor, sig) } @@ -718,6 +721,9 @@ open class SymbolTable( override fun referenceSimpleFunction(descriptor: FunctionDescriptor) = simpleFunctionSymbolTable.referenced(descriptor) { createSimpleFunctionSymbol(descriptor) } + fun referenceSimpleFunctionIfAny(sig: IdSignature): IrSimpleFunctionSymbol? = + simpleFunctionSymbolTable.get(sig) + override fun referenceSimpleFunctionFromLinker(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol { return simpleFunctionSymbolTable.run { if (sig.isPublic) referenced(sig) { IrSimpleFunctionPublicSymbolImpl(descriptor, sig) } else diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt index b179868b8ba..896e4de23f6 100644 --- a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt @@ -6,27 +6,27 @@ FILE fqName: fileName:/enhancedNullabilityInForLoop.kt BLOCK_BODY BLOCK type=kotlin.Unit origin=FOR_LOOP VAR FOR_LOOP_ITERATOR name:tmp_0 type:kotlin.collections.MutableIterator<.P?> [val] - CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<.P?> origin=FOR_LOOP_ITERATOR + CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<.P?> origin=FOR_LOOP_ITERATOR $this: CALL 'public open fun listOfNotNull (): kotlin.collections.List<.P?>? declared in .J' type=kotlin.collections.List<.P?>? origin=null WHILE label=null origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT $this: GET_VAR 'val tmp_0: kotlin.collections.MutableIterator<.P?> [val] declared in .testForInListUnused' type=kotlin.collections.MutableIterator<.P?> origin=null body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE VAR FOR_LOOP_VARIABLE name:x type:.P? [val] - CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableIterator' type=.P? origin=FOR_LOOP_NEXT + CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=.P? origin=FOR_LOOP_NEXT $this: GET_VAR 'val tmp_0: kotlin.collections.MutableIterator<.P?> [val] declared in .testForInListUnused' type=kotlin.collections.MutableIterator<.P?> origin=null FUN name:testForInListDestructured visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY BLOCK type=kotlin.Unit origin=FOR_LOOP VAR FOR_LOOP_ITERATOR name:tmp_1 type:kotlin.collections.MutableIterator<.P?> [val] - CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<.P?> origin=FOR_LOOP_ITERATOR + CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<.P?> origin=FOR_LOOP_ITERATOR $this: CALL 'public open fun listOfNotNull (): kotlin.collections.List<.P?>? declared in .J' type=kotlin.collections.List<.P?>? origin=null WHILE label=null origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT $this: GET_VAR 'val tmp_1: kotlin.collections.MutableIterator<.P?> [val] declared in .testForInListDestructured' type=kotlin.collections.MutableIterator<.P?> origin=null body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE VAR FOR_LOOP_VARIABLE name: type:.P? [val] - CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableIterator' type=.P? origin=FOR_LOOP_NEXT + CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=.P? origin=FOR_LOOP_NEXT $this: GET_VAR 'val tmp_1: kotlin.collections.MutableIterator<.P?> [val] declared in .testForInListDestructured' type=kotlin.collections.MutableIterator<.P?> origin=null VAR name:x type:kotlin.Int [val] CALL 'public final fun component1 (): kotlin.Int declared in .P' type=kotlin.Int origin=null @@ -37,14 +37,14 @@ FILE fqName: fileName:/enhancedNullabilityInForLoop.kt FUN name:testDesugaredForInList visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY VAR name:iterator type:kotlin.collections.MutableIterator<.P?> [val] - CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<.P?> origin=null + CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<.P?> origin=null $this: CALL 'public open fun listOfNotNull (): kotlin.collections.List<.P?>? declared in .J' type=kotlin.collections.List<.P?>? origin=null WHILE label=null origin=WHILE_LOOP condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null $this: GET_VAR 'val iterator: kotlin.collections.MutableIterator<.P?> [val] declared in .testDesugaredForInList' type=kotlin.collections.MutableIterator<.P?> origin=null body: BLOCK type=kotlin.Unit origin=WHILE_LOOP VAR name:x type:.P? [val] - CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableIterator' type=.P? origin=null + CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=.P? origin=null $this: GET_VAR 'val iterator: kotlin.collections.MutableIterator<.P?> [val] declared in .testDesugaredForInList' type=kotlin.collections.MutableIterator<.P?> origin=null FUN name:testForInArrayUnused visibility:public modality:FINAL <> (j:.J) returnType:kotlin.Unit VALUE_PARAMETER name:j index:0 type:.J @@ -65,14 +65,14 @@ FILE fqName: fileName:/enhancedNullabilityInForLoop.kt BLOCK_BODY BLOCK type=kotlin.Unit origin=FOR_LOOP VAR FOR_LOOP_ITERATOR name:tmp_3 type:kotlin.collections.MutableIterator<.P?> [val] - CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<.P?> origin=FOR_LOOP_ITERATOR + CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableList' type=kotlin.collections.MutableIterator<.P?> origin=FOR_LOOP_ITERATOR $this: CALL 'public open fun listOfNotNull (): kotlin.collections.List<.P?>? declared in .J' type=kotlin.collections.List<.P?>? origin=null WHILE label=null origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT $this: GET_VAR 'val tmp_3: kotlin.collections.MutableIterator<.P?> [val] declared in .testForInListUse' type=kotlin.collections.MutableIterator<.P?> origin=null body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE VAR FOR_LOOP_VARIABLE name:x type:.P? [val] - CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [operator] declared in kotlin.collections.MutableIterator' type=.P? origin=FOR_LOOP_NEXT + CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=.P? origin=FOR_LOOP_NEXT $this: GET_VAR 'val tmp_3: kotlin.collections.MutableIterator<.P?> [val] declared in .testForInListUse' type=kotlin.collections.MutableIterator<.P?> origin=null CALL 'public final fun use (s: .P): kotlin.Unit declared in ' type=kotlin.Unit origin=null s: GET_VAR 'val x: .P? [val] declared in .testForInListUse' type=.P? origin=null