diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index b07df0ac87b..9b4233f3338 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -45617,6 +45617,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt"); } + @Test + @TestMetadata("callableReferenceInlinedFunFromOtherModule.kt") + public void testCallableReferenceInlinedFunFromOtherModule() throws Exception { + runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt"); + } + @Test @TestMetadata("checkcast.kt") public void testCheckcast() throws Exception { diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt index 20fa283ce79..1b53c41292c 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt @@ -119,3 +119,5 @@ fun CommonBackendContext.createArrayOfExpression( putValueArgument(0, arg0) } } + +fun IrFunction.isInlineFunWithReifiedParameter() = isInline && typeParameters.any { it.isReified } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/WrapInlineDeclarationsWithReifiedTypeParametersLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/WrapInlineDeclarationsWithReifiedTypeParametersLowering.kt similarity index 62% rename from compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/WrapInlineDeclarationsWithReifiedTypeParametersLowering.kt rename to compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/WrapInlineDeclarationsWithReifiedTypeParametersLowering.kt index d67a4e890fb..04814b4745d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/WrapInlineDeclarationsWithReifiedTypeParametersLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/WrapInlineDeclarationsWithReifiedTypeParametersLowering.kt @@ -1,31 +1,29 @@ /* - * Copyright 2010-2021 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. */ -/* - * Copyright 2010-2021 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. - */ - -package org.jetbrains.kotlin.ir.backend.js.lower.inline +package org.jetbrains.kotlin.backend.common.lower import org.jetbrains.kotlin.backend.common.BackendContext import org.jetbrains.kotlin.backend.common.BodyLoweringPass +import org.jetbrains.kotlin.backend.common.ir.isInlineFunWithReifiedParameter import org.jetbrains.kotlin.descriptors.DescriptorVisibilities -import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder -import org.jetbrains.kotlin.ir.backend.js.utils.isInlineFunWithReifiedParameter import org.jetbrains.kotlin.ir.builders.declarations.addFunction import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter -import org.jetbrains.kotlin.ir.declarations.IrDeclaration -import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer -import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.builders.declarations.buildFun +import org.jetbrains.kotlin.ir.builders.irCall +import org.jetbrains.kotlin.ir.builders.irGet +import org.jetbrains.kotlin.ir.builders.irReturn +import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrFunctionReference +import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl import org.jetbrains.kotlin.ir.types.IrTypeArgument import org.jetbrains.kotlin.ir.types.IrTypeSubstitutor +import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET import org.jetbrains.kotlin.ir.util.typeSubstitutionMap import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid @@ -59,48 +57,56 @@ class WrapInlineDeclarationsWithReifiedTypeParametersLowering(val context: Backe context.irBuiltIns ) - val function = irFactory.addFunction(container.parent as IrDeclarationContainer) { + val function = irFactory.buildFun { name = Name.identifier("${owner.name}${"$"}wrap") - returnType = owner.returnType - visibility = DescriptorVisibilities.PRIVATE - origin = JsIrBuilder.SYNTHESIZED_DECLARATION - }.also { function -> + returnType = typeSubstitutor.substitute(owner.returnType) + visibility = DescriptorVisibilities.LOCAL + origin = IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE + startOffset = SYNTHETIC_OFFSET + endOffset = SYNTHETIC_OFFSET + }.apply { + parent = container as IrDeclarationParent + val irBuilder = context.createIrBuilder(symbol, SYNTHETIC_OFFSET, SYNTHETIC_OFFSET) owner.valueParameters.forEach { valueParameter -> - function.addValueParameter( + addValueParameter( valueParameter.name, typeSubstitutor.substitute(valueParameter.type) ) } - function.body = irFactory.createBlockBody( + body = irFactory.createBlockBody( expression.startOffset, expression.endOffset ) { statements.add( - JsIrBuilder.buildReturn( - function.symbol, - JsIrBuilder.buildCall(owner.symbol).also { call -> + irBuilder.irReturn( + irBuilder.irCall(owner.symbol).also { call -> call.dispatchReceiver = expression.dispatchReceiver call.extensionReceiver = expression.extensionReceiver - function.valueParameters.forEachIndexed { index, valueParameter -> - call.putValueArgument(index, JsIrBuilder.buildGetValue(valueParameter.symbol)) + valueParameters.forEachIndexed { index, valueParameter -> + call.putValueArgument(index, irBuilder.irGet(valueParameter)) } for (i in 0 until expression.typeArgumentsCount) { call.putTypeArgument(i, expression.getTypeArgument(i)) } }, - owner.returnType ) ) } } - return IrFunctionReferenceImpl.fromSymbolOwner( - expression.startOffset, - expression.endOffset, - expression.type, - function.symbol, - function.typeParameters.size, - expression.reflectionTarget - ) + return context.createIrBuilder(container.symbol).irBlock( + expression, + origin = IrStatementOrigin.ADAPTED_FUNCTION_REFERENCE + ) { + +function + +IrFunctionReferenceImpl.fromSymbolOwner( + expression.startOffset, + expression.endOffset, + expression.type, + function.symbol, + function.typeParameters.size, + expression.reflectionTarget + ) + } } }) } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt index 1717b51a501..49d3d886106 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt @@ -13,9 +13,7 @@ import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineFunc import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineLambdasLowering import org.jetbrains.kotlin.backend.common.lower.loops.ForLoopsLowering import org.jetbrains.kotlin.backend.common.lower.optimizations.FoldConstantLowering -import org.jetbrains.kotlin.backend.common.lower.optimizations.PropertyAccessorInlineLowering import org.jetbrains.kotlin.backend.common.phaser.* -import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.backend.js.codegen.JsGenerationGranularity import org.jetbrains.kotlin.ir.backend.js.lower.* import org.jetbrains.kotlin.ir.backend.js.lower.calls.CallsLowering diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/RemoveInlineDeclarationsWithReifiedTypeParametersLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/RemoveInlineDeclarationsWithReifiedTypeParametersLowering.kt index a97d436580e..11b6d08442d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/RemoveInlineDeclarationsWithReifiedTypeParametersLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/RemoveInlineDeclarationsWithReifiedTypeParametersLowering.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.ir.backend.js.lower.inline import org.jetbrains.kotlin.backend.common.DeclarationTransformer import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext -import org.jetbrains.kotlin.ir.backend.js.utils.isInlineFunWithReifiedParameter +import org.jetbrains.kotlin.backend.common.ir.isInlineFunWithReifiedParameter import org.jetbrains.kotlin.ir.declarations.IrDeclaration import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.IrProperty diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/misc.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/misc.kt index 3480780cfc8..56f586607f3 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/misc.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/misc.kt @@ -118,5 +118,3 @@ fun invokeFunForLambda(call: IrCall) = .type .getClass()!! .invokeFun!! - -fun IrFunction.isInlineFunWithReifiedParameter() = isInline && typeParameters.any { it.isReified } diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt index 2ee10afb325..6ae20707c7c 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt @@ -14,13 +14,11 @@ import org.jetbrains.kotlin.backend.common.lower.optimizations.PropertyAccessorI import org.jetbrains.kotlin.backend.common.phaser.* import org.jetbrains.kotlin.backend.common.toMultiModuleAction import org.jetbrains.kotlin.backend.wasm.lower.* -import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.backend.js.lower.* import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.AddContinuationToFunctionCallsLowering import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.AddContinuationToNonLocalSuspendFunctionsLowering import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.JsSuspendFunctionsLowering import org.jetbrains.kotlin.ir.backend.js.lower.inline.RemoveInlineDeclarationsWithReifiedTypeParametersLowering -import org.jetbrains.kotlin.ir.backend.js.lower.inline.WrapInlineDeclarationsWithReifiedTypeParametersLowering import org.jetbrains.kotlin.ir.backend.wasm.lower.generateMainFunctionCalls import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.util.patchDeclarationParents diff --git a/compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt b/compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt index 5a7287b9dc4..d521c8b72be 100644 --- a/compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt +++ b/compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt @@ -1,5 +1,4 @@ // WITH_STDLIB -// IGNORE_BACKEND: NATIVE inline fun baz(value: T): String = "OK" + value @@ -67,6 +66,21 @@ class F { inline fun foo(x: T1, y: T2): Any? = "OK" + x + y } +inline fun bam(value1: K?, value2: T?): String = "OK" + value1.toString() + value2.toString() + +fun test10(): String { + val f: (T?, String?) -> String = ::bam + return f(null, "abc") +} + +inline fun test11Impl() : String { + val f: (T?, String?) -> String = ::bam + return f(null, "def") +} + +fun test11() = test11Impl() + + fun box(): String { val test1 = test() if (test1 != "OK1") return "fail1: $test1" @@ -86,6 +100,10 @@ fun box(): String { if (test8 != "OK56") return "fail8: $test8" val test9 = F().foo(65, "hello") if (test9 != "OK65hello") return "fail9: $test9" + val test10 = test10() + if (test10 != "OKnullabc") return "fail10: $test10" + val test11 = test11() + if (test11 != "OKnulldef") return "fail11: $test11" return "OK" } diff --git a/compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt b/compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt new file mode 100644 index 00000000000..4f4947d61ae --- /dev/null +++ b/compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt @@ -0,0 +1,119 @@ +// WITH_STDLIB + +// MODULE: lib +// FILE: lib.kt + +inline fun baz(value: T): String = "OK" + value + +object Foo { + val log = "123" +} + +public inline fun Foo.foo(value: T): String = + log + value + + +object Bar { + val log = "321" + + public inline fun bar(value: T): String = + log + value +} + + +class C { + inline fun qux(value: T): String = "OK" + value +} + +inline fun ((Any) -> String).cux(value: T): String = this(value) + +inline fun bak(value1: T, value2: K, value3: S): String = "OK" + value1 + value2 + value3 + +inline fun bal(value1: Array, value2: Array): String = "OK" + value1.joinToString() + value2.joinToString() + +class E +public inline fun E.foo(value: T): String = "OK" + value + +class F { + inline fun foo(x: T1, y: T2): Any? = "OK" + x + y +} + +inline fun bam(value1: K?, value2: T?): String = "OK" + value1.toString() + value2.toString() + +inline fun test11Impl() : String { + val f: (T?, String?) -> String = ::bam + return f(null, "def") +} + + +// MODULE: main(lib) +// FILE: main.kt + +fun test(): String { + val f: (Any) -> String = ::baz + return f(1) +} + +val test2 = { "OK".let(Foo::foo) } + +val test3 = { "OK".let(Bar::bar) } + +fun test4(): String { + val c = C() + val cr: (String) -> String = c::qux + return cr("456") +} + +fun test5(): String { + val foo: (Any) -> String = ({ b: Any -> + val a: (Any) -> String = ::baz + a(b) + })::cux + return foo(3) +} + +fun test6(): String { + val f: (Any, Int, String) -> String = ::bak + return f(1, 37, "joo") +} + +fun test7(): String { + val f: (Array, Array) -> String = ::bal + return f(arrayOf("mer", "nas"), arrayOf(73, 37)) +} + + +fun test10(): String { + val f: (T?, String?) -> String = ::bam + return f(null, "abc") +} + +fun test11() = test11Impl() + + +fun box(): String { + val test1 = test() + if (test1 != "OK1") return "fail1: $test1" + val test2 = test2() + if (test2 != "123OK") return "fail2: $test2" + val test3 = test3() + if (test3 != "321OK") return "fail3: $test3" + val test4 = test4() + if (test4 != "OK456") return "fail4: $test4" + val test5 = test5() + if (test5 != "OK3") return "fail5: $test5" + val test6 = test6() + if (test6 != "OK137joo") return "fail6: $test6" + val test7 = test7() + if (test7 != "OKmer, nas73, 37") return "fail7: $test7" + val test8 = E().foo(56) + if (test8 != "OK56") return "fail8: $test8" + val test9 = F().foo(65, "hello") + if (test9 != "OK65hello") return "fail9: $test9" + val test10 = test10() + if (test10 != "OKnullabc") return "fail10: $test10" + val test11 = test11() + if (test11 != "OKnulldef") return "fail11: $test11" + + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 33e569fd1c9..d461d895881 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -44195,6 +44195,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt"); } + @Test + @TestMetadata("callableReferenceInlinedFunFromOtherModule.kt") + public void testCallableReferenceInlinedFunFromOtherModule() throws Exception { + runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt"); + } + @Test @TestMetadata("checkcast.kt") public void testCheckcast() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index dc108b03292..1b6f0fd3c14 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -45617,6 +45617,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt"); } + @Test + @TestMetadata("callableReferenceInlinedFunFromOtherModule.kt") + public void testCallableReferenceInlinedFunFromOtherModule() throws Exception { + runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt"); + } + @Test @TestMetadata("checkcast.kt") public void testCheckcast() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index c3524f6cdc3..bd7d755609d 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -35616,6 +35616,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt"); } + @TestMetadata("callableReferenceInlinedFunFromOtherModule.kt") + public void testCallableReferenceInlinedFunFromOtherModule() throws Exception { + runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt"); + } + @TestMetadata("checkcast.kt") public void testCheckcast() throws Exception { runTest("compiler/testData/codegen/box/reified/checkcast.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 21138a8db92..eee3baf1eef 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -33199,6 +33199,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt"); } + @Test + @TestMetadata("callableReferenceInlinedFunFromOtherModule.kt") + public void testCallableReferenceInlinedFunFromOtherModule() throws Exception { + runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt"); + } + @Test @TestMetadata("checkcast.kt") public void testCheckcast() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index b9760194901..d3e418535a1 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -33367,6 +33367,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt"); } + @Test + @TestMetadata("callableReferenceInlinedFunFromOtherModule.kt") + public void testCallableReferenceInlinedFunFromOtherModule() throws Exception { + runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt"); + } + @Test @TestMetadata("checkcast.kt") public void testCheckcast() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index a9ab18f24d5..8f4120fa49f 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -29876,6 +29876,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt"); } + @TestMetadata("callableReferenceInlinedFunFromOtherModule.kt") + public void testCallableReferenceInlinedFunFromOtherModule() throws Exception { + runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt"); + } + @TestMetadata("checkcast.kt") public void testCheckcast() throws Exception { runTest("compiler/testData/codegen/box/reified/checkcast.kt"); diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt index fdd8cdcf00b..81421e0231b 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt @@ -2,7 +2,6 @@ package org.jetbrains.kotlin.backend.konan import org.jetbrains.kotlin.backend.common.* import org.jetbrains.kotlin.backend.common.lower.* -import org.jetbrains.kotlin.backend.common.lower.StringConcatenationLowering import org.jetbrains.kotlin.backend.common.lower.inline.FunctionInlining import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesExtractionFromInlineFunctionsLowering import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineFunctionsLowering @@ -160,6 +159,12 @@ internal val extractLocalClassesFromInlineBodies = makeKonanFileOpPhase( prerequisite = setOf(sharedVariablesPhase), // TODO: add "soft" dependency on inventNamesForLocalClasses ) +internal val wrapInlineDeclarationsWithReifiedTypeParametersLowering = makeKonanFileLoweringPhase( + ::WrapInlineDeclarationsWithReifiedTypeParametersLowering, + name = "WrapInlineDeclarationsWithReifiedTypeParameters", + description = "Wrap inline declarations with reified type parameters" +) + internal val inlinePhase = makeKonanFileOpPhase( { context, irFile -> irFile.acceptChildrenVoid(object : IrElementVisitorVoid { diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt index c64c8306119..830b0d9f003 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt @@ -252,6 +252,7 @@ internal val allLoweringsPhase = NamedCompilerPhase( sharedVariablesPhase, inventNamesForLocalClasses, extractLocalClassesFromInlineBodies, + wrapInlineDeclarationsWithReifiedTypeParametersLowering, inlinePhase, provisionalFunctionExpressionPhase, postInlinePhase, diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/NativeInlineFunctionResolver.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/NativeInlineFunctionResolver.kt index 10759300a31..70e9c780b7b 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/NativeInlineFunctionResolver.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/NativeInlineFunctionResolver.kt @@ -74,6 +74,8 @@ internal class NativeInlineFunctionResolver(override val context: Context) : Def LocalClassesExtractionFromInlineFunctionsLowering(context).lower(body, notLoweredFunction) } + WrapInlineDeclarationsWithReifiedTypeParametersLowering(context).lower(body, notLoweredFunction) + return notLoweredFunction } diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 8843d07882e..f0b8927d611 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -36410,6 +36410,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFun.kt"); } + @Test + @TestMetadata("callableReferenceInlinedFunFromOtherModule.kt") + public void testCallableReferenceInlinedFunFromOtherModule() throws Exception { + runTest("compiler/testData/codegen/box/reified/callableReferenceInlinedFunFromOtherModule.kt"); + } + @Test @TestMetadata("checkcast.kt") public void testCheckcast() throws Exception {