Fix inlining of tail call suspend function

When inlining tail-call suspend function to regular
suspend function in JS BE, don't forget to insert suspension point.
See KT-16951
This commit is contained in:
Alexey Andreev
2017-03-20 18:34:08 +03:00
parent 466540399c
commit 6ba3812582
9 changed files with 134 additions and 14 deletions
@@ -43,9 +43,13 @@ class ReturnReplacingVisitor(
ctx.removeMe()
val returnExpression = x.expression
val returnReplacement = getReturnReplacement(x.expression)
if (returnReplacement != null) {
ctx.addNext(JsExpressionStatement(returnReplacement).apply { synthetic = true })
if (returnExpression != null && returnExpression.isTailCallSuspend) {
returnReplacement.isSuspend = true
}
ctx.addNext(JsExpressionStatement(returnReplacement))
}
if (breakLabel != null) {
@@ -68,6 +72,7 @@ class ReturnReplacingVisitor(
fun processCoroutineResult(expression: JsExpression?): JsExpression? {
if (!isSuspend) return expression
if (expression != null && expression.isTailCallSuspend) return expression
val lhs = JsNameRef("\$\$coroutineResult\$\$", JsAstUtils.stateMachineReceiver()).apply { coroutineResult = true }
return JsAstUtils.assignment(lhs, expression ?: Namer.getUndefinedExpression())
}