[JS IR] Fix boxing/unboxing of inline classes in coroutine scope

- don't box/unbox when value is known to be an inline class
 - add unbox state when coroutine resumed
 - correctly handle suspension in case of inline class
 - add tests
This commit is contained in:
Roman Artemev
2019-11-13 17:30:41 +03:00
committed by romanart
parent 52b24ead91
commit f2093a1763
12 changed files with 284 additions and 19 deletions
@@ -57,6 +57,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
protected abstract fun initializeStateMachine(coroutineConstructors: List<IrConstructor>, coroutineClassThis: IrValueDeclaration)
protected open fun IrBuilderWithScope.generateDelegatedCall(expectedType: IrType, delegatingCall: IrExpression): IrExpression = delegatingCall
private val builtCoroutines = mutableMapOf<IrFunction, BuiltCoroutine>()
private val suspendLambdas = mutableMapOf<IrFunction, IrFunctionReference>()
@@ -228,7 +229,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
val statements = (irFunction.body as IrBlockBody).statements
val lastStatement = statements.last()
assert(lastStatement == delegatingCall || lastStatement is IrReturn) { "Unexpected statement $lastStatement" }
statements[statements.lastIndex] = irReturn(returnValue)
statements[statements.lastIndex] = irReturn(generateDelegatedCall(irFunction.returnType, returnValue))
}
}
@@ -551,7 +552,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
Name.identifier("invoke"),
Visibilities.PROTECTED,
Modality.FINAL,
irFunction.returnType,
context.irBuiltIns.anyNType,
isInline = false,
isExternal = false,
isTailrec = false,