From 307e01e6b6d0073ea252cf74dab76bf504f8d09c Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Fri, 14 Aug 2020 01:04:36 +0200 Subject: [PATCH] Document coroutines codegen: suspend markers: JS & Native --- .../kotlin/codegen/coroutines/coroutines-codegen.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutines-codegen.md b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutines-codegen.md index 77ed14ad01d..1c3448cbe9e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutines-codegen.md +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutines-codegen.md @@ -274,4 +274,15 @@ to `kotlin.jvm.internal.InlineMarker.mark`'s call cannot be changed. The codegen generates the markers by calling `addSuspendMarker`. After generating `MethodNode` of the function, it passes the node to `CoroutineTransformerMethodVisitor`. `CoroutineTransformerMethodVisitor` collects the suspension points by checking these markers, and then it generates the state-machine. -FIXME: I should rename `CoroutineTransformerMethodVisitor` to `StateMachineBuilder` already. \ No newline at end of file +FIXME: I should rename `CoroutineTransformerMethodVisitor` to `StateMachineBuilder` already. + +#### JS & Native: Suspend Markers +The difference between JVM_IR and JS_IR/Native in regards to coroutine codegen non-JVM back-ends do not generate suspending markers in the +resulting code. They still collect suspension points, however. +That is because they assume the closed-world model; in other words, they do not generate libraries in their target languages, which could +contain suspending inline functions. Thus, the back-ends run the inliner before all lowerings, and they generate state machine during a +suspend lowering, whereas JVM_IR still relies on the old back-end's `CoroutineTransfromerMethodVisitor` to do this since we cannot just +generate state machine during a lowering, there are suspend inline functions in libraries bytecode, because of the open-world model. +Well, we can, if the function does not inline other functions. Nevertheless, there is much work to do in the new back-end, and generating a +state-machine during the lowering is a part of it. +