JVM_IR: make continuation detection more consistent
* unify various checks for whether a suspend function needs a
continuation;
* mark the continuation parameter with an origin (this also allows
correctly computing the offset of the local in codegen -- see the
new test);
* when wrapping `suspend fun main`, use a suspend reference instead of
a synthetic non-suspend lambda (required to correctly implement the
previous point, as previously the continuation parameter was passed
to main() itself correctly only because of very lenient checks in
AddContinuationLowering).
This commit is contained in:
@@ -185,7 +185,7 @@ fun IrTypeParameter.copyToWithoutSuperTypes(
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrFunction.copyReceiverParametersFrom(from: IrFunction) {
|
||||
fun IrFunction.copyReceiverParametersFrom(from: IrFunction) {
|
||||
dispatchReceiverParameter = from.dispatchReceiverParameter?.let {
|
||||
IrValueParameterImpl(it.startOffset, it.endOffset, it.origin, it.descriptor, it.type, it.varargElementType).also {
|
||||
it.parent = this
|
||||
@@ -200,22 +200,6 @@ fun IrFunction.copyValueParametersFrom(from: IrFunction) {
|
||||
valueParameters += from.valueParameters.map { it.copyTo(this, index = it.index + shift) }
|
||||
}
|
||||
|
||||
fun IrFunction.copyValueParametersInsertingContinuationFrom(from: IrFunction, insertContinuation: () -> Unit) {
|
||||
copyReceiverParametersFrom(from)
|
||||
val shift = valueParameters.size
|
||||
var additionalShift = 0
|
||||
from.valueParameters.forEach {
|
||||
// The continuation parameter goes before the default argument mask and handler.
|
||||
if (it.origin == IrDeclarationOrigin.MASK_FOR_DEFAULT_FUNCTION && additionalShift == 0) {
|
||||
insertContinuation()
|
||||
additionalShift = 1
|
||||
}
|
||||
valueParameters += it.copyTo(this, index = it.index + shift + additionalShift)
|
||||
}
|
||||
// If there was no default argument mask and handler, the continuation goes last.
|
||||
if (additionalShift == 0) insertContinuation()
|
||||
}
|
||||
|
||||
fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
||||
assert(typeParameters.isEmpty())
|
||||
copyTypeParametersFrom(from)
|
||||
|
||||
Reference in New Issue
Block a user