提交 952576e9 编写于 作者: I Ilmir Usmanov

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.
上级 d48f9277
......@@ -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 {
......@@ -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 {
......
// 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()
\ No newline at end of file
// !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()
\ No newline at end of file
// !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()
\ No newline at end of file
......@@ -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 {
......@@ -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 {
......@@ -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");
......@@ -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");
......@@ -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");
......@@ -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");
......@@ -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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册