JVM_IR: Do not unbox Result parameter if it not only one inline class
parameter, since in this case, the compiler generates a bridge, where the result is unboxed.
This commit is contained in:
+18
@@ -17684,6 +17684,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
@@ -17736,6 +17742,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
@@ -17788,6 +17800,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
|
||||
+5
@@ -626,6 +626,7 @@ class ExpressionCodegen(
|
||||
// bridge to unbox it. Instead, we unbox it in the non-mangled function manually.
|
||||
private fun unboxResultIfNeeded(arg: IrGetValue) {
|
||||
if (arg.type.erasedUpperBound.fqNameWhenAvailable != StandardNames.RESULT_FQ_NAME) return
|
||||
if (!onlyResultInlineClassParameters()) return
|
||||
if (irFunction !is IrSimpleFunction) return
|
||||
// Skip Result's methods
|
||||
if (irFunction.parentAsClass.fqNameWhenAvailable == StandardNames.RESULT_FQ_NAME) return
|
||||
@@ -642,6 +643,10 @@ class ExpressionCodegen(
|
||||
StackValue.unboxInlineClass(OBJECT_TYPE, arg.type.erasedUpperBound.defaultType.toIrBasedKotlinType(), mv)
|
||||
}
|
||||
|
||||
private fun onlyResultInlineClassParameters(): Boolean = irFunction.valueParameters.all {
|
||||
!it.type.erasedUpperBound.isInline || it.type.erasedUpperBound.fqNameWhenAvailable == StandardNames.RESULT_FQ_NAME
|
||||
}
|
||||
|
||||
private fun hasBridge(): Boolean = irFunction.parentAsClass.declarations.any { function ->
|
||||
function is IrFunction && function != irFunction &&
|
||||
context.methodSignatureMapper.mapSignatureSkipGeneric(function).let {
|
||||
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
// WASM_MUTE_REASON: SAM_CONVERSIONS
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// WITH_RUNTIME
|
||||
|
||||
inline class IC(val value: Any)
|
||||
|
||||
fun <T> foo(a: Result<T>, ic: IC): Pair<T, Any> = bar(a, ic) { a, ic ->
|
||||
a.getOrThrow() to ic.value
|
||||
}
|
||||
|
||||
fun interface FunIFace<T1, T2, R> {
|
||||
fun call(t1: T1, t2: T2): R
|
||||
}
|
||||
|
||||
fun <T1, T2, R> bar(t1: T1, t2: T2, f: FunIFace<T1, T2, R>): R {
|
||||
return f.call(t1, t2)
|
||||
}
|
||||
|
||||
fun Pair<Any, Any>.join(): String = "$first$second"
|
||||
|
||||
fun box(): String = foo<Any>(Result.success("O"), IC("K")).join()
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// WITH_RUNTIME
|
||||
|
||||
inline class IC(val value: Any)
|
||||
|
||||
fun <T> foo(a: Result<T>, ic: IC): Pair<T, Any> = bar(a, ic) { a, ic ->
|
||||
a.getOrThrow() to ic.value
|
||||
}
|
||||
|
||||
fun <T1, T2, R> bar(t1: T1, t2: T2, f: (T1, T2) -> R): R {
|
||||
return f(t1, t2)
|
||||
}
|
||||
|
||||
fun Pair<Any, Any>.join(): String = "$first$second"
|
||||
|
||||
fun box(): String = foo<Any>(Result.success("O"), IC("K")).join()
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// WITH_RUNTIME
|
||||
|
||||
inline class IC(val value: Any)
|
||||
|
||||
fun <T> foo(a: Result<T>, ic: IC): Pair<T, Any> = bar(a, ic, object : IFace<Result<T>, IC, Pair<T, Any>> {
|
||||
override fun call(a: Result<T>, ic: IC): Pair<T, Any> = a.getOrThrow() to ic.value
|
||||
})
|
||||
|
||||
interface IFace<T1, T2, R> {
|
||||
fun call(t1: T1, t2: T2): R
|
||||
}
|
||||
|
||||
fun <T1, T2, R> bar(t1: T1, t2: T2, f: IFace<T1, T2, R>): R {
|
||||
return f.call(t1, t2)
|
||||
}
|
||||
|
||||
fun Pair<Any, Any>.join(): String = "$first$second"
|
||||
|
||||
fun box(): String = foo<Any>(Result.success("O"), IC("K")).join()
|
||||
+18
@@ -17684,6 +17684,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
@@ -17736,6 +17742,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
@@ -17788,6 +17800,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
|
||||
+18
@@ -17684,6 +17684,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
@@ -17736,6 +17742,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
@@ -17788,6 +17800,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
|
||||
+15
@@ -15492,6 +15492,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/string.kt");
|
||||
@@ -15540,6 +15545,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt");
|
||||
@@ -15588,6 +15598,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+15
@@ -13342,6 +13342,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/string.kt");
|
||||
@@ -13390,6 +13395,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt");
|
||||
@@ -13438,6 +13448,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt");
|
||||
|
||||
Generated
+15
@@ -13342,6 +13342,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/string.kt");
|
||||
@@ -13390,6 +13395,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt");
|
||||
@@ -13438,6 +13448,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt");
|
||||
|
||||
Generated
+15
@@ -13407,6 +13407,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/string.kt");
|
||||
@@ -13455,6 +13460,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt");
|
||||
@@ -13503,6 +13513,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+10
@@ -7591,6 +7591,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt");
|
||||
@@ -7639,6 +7644,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resultAny.kt")
|
||||
public void testResultAny() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("string.kt")
|
||||
public void testString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt");
|
||||
|
||||
Reference in New Issue
Block a user