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:
Ilmir Usmanov
2021-01-20 17:06:10 +01:00
parent d48f92775b
commit 952576e98f
12 changed files with 187 additions and 0 deletions
@@ -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 {