Native: allow virtual calls in CoroutineLaunchpad intrinsic

This intrinsic was always calling the supplied suspend function
non-virtually, and this was hardcoded in the intrinsic generator.
Now this can be configured with `superQualifierSymbol` in the respective
IrCall, just the way this works with any other calls.

As a side effect, global optimizations now process this intrinsic more
correctly (before that, they didn't take the intrinsic generator into
account, and treated the call as virtual).
This commit is contained in:
Svyatoslav Scherbina
2022-08-25 11:51:18 +02:00
committed by Space
parent 728fe918fe
commit f8462f1b0c
3 changed files with 5 additions and 4 deletions
@@ -34,7 +34,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
protected abstract fun getCoroutineBaseClass(function: IrFunction): IrClassSymbol
protected abstract fun nameForCoroutineClass(function: IrFunction): Name
protected abstract fun IrBuilderWithScope.launchSuspendFunctionWithGivenContinuation(
symbol: IrSimpleFunctionSymbol, dispatchReceiver: IrExpression,
symbol: IrSimpleFunctionSymbol, superQualifierSymbol: IrClassSymbol?, dispatchReceiver: IrExpression,
arguments: List<IrExpression>, continuation: IrExpression) : IrExpression
protected abstract fun buildStateMachine(
@@ -146,6 +146,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
+irReturn(
launchSuspendFunctionWithGivenContinuation(
invokeFunction.symbol,
superQualifierSymbol = invokeFunction.parentAsClass.symbol, // Call non-virtually.
irGet(thisReceiver),
valueParameters.dropLast(1).map { irGet(it) },
irGet(valueParameters.last())
@@ -192,7 +192,7 @@ internal class IntrinsicGenerator(private val environment: IntrinsicGeneratorEnv
environment.evaluateCall(suspendFunction,
environment.evaluateExplicitArgs(suspendFunctionCall) + listOf(continuation),
environment.calculateLifetime(suspendFunctionCall),
suspendFunction.parent as? IrClass, // Call non-virtually.
suspendFunctionCall.superQualifierSymbol?.owner,
resultSlot,
)
}
@@ -60,10 +60,10 @@ internal class NativeSuspendFunctionsLowering(ctx: Context): AbstractSuspendFunc
override fun IrBuilderWithScope.launchSuspendFunctionWithGivenContinuation(
symbol: IrSimpleFunctionSymbol, dispatchReceiver: IrExpression,
symbol: IrSimpleFunctionSymbol, superQualifierSymbol: IrClassSymbol?, dispatchReceiver: IrExpression,
arguments: List<IrExpression>, continuation: IrExpression
) = irCall(this@NativeSuspendFunctionsLowering.context.ir.symbols.coroutineLaunchpad).apply {
putValueArgument(0, irCall(symbol).apply {
putValueArgument(0, irCall(symbol.owner, superQualifierSymbol = superQualifierSymbol).apply {
this.dispatchReceiver = dispatchReceiver
arguments.forEachIndexed { index, irExpression ->
putValueArgument(index, irExpression)