From a25602c709d23a550536f79255cad11dd43eadc4 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 30 Jun 2016 16:48:03 +0300 Subject: [PATCH] Fix spilling algorithm for double-sized coroutine parameters --- .../codegen/coroutines/CoroutineCodegen.kt | 11 +++++++---- .../codegen/box/coroutines/lambdaParameters.kt | 16 ++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt index 5cd8564adce..27e033b7018 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt @@ -135,12 +135,15 @@ class CoroutineCodegen( with(codegen.v) { setLabelValue(LABEL_VALUE_BEFORE_FIRST_SUSPENSION) + // Save lambda parameters to fields + // 0 - this + // 1 - controller + var index = 2 for (parameter in funDescriptor.valueParameters) { - // 0 - this - // 1 - controller - val parametersIndexShift = 2 + val fieldInfoForCoroutineLambdaParameter = parameter.getFieldInfoForCoroutineLambdaParameter() AsmUtil.genAssignInstanceFieldFromParam( - parameter.getFieldInfoForCoroutineLambdaParameter(), parametersIndexShift + parameter.index, this) + fieldInfoForCoroutineLambdaParameter, index, this) + index += fieldInfoForCoroutineLambdaParameter.fieldType.size } load(0, AsmTypes.OBJECT_TYPE) diff --git a/compiler/testData/codegen/box/coroutines/lambdaParameters.kt b/compiler/testData/codegen/box/coroutines/lambdaParameters.kt index cc7e76c0115..31b98ee0129 100644 --- a/compiler/testData/codegen/box/coroutines/lambdaParameters.kt +++ b/compiler/testData/codegen/box/coroutines/lambdaParameters.kt @@ -4,8 +4,8 @@ class Controller { } } -fun builder(coroutine c: Controller.(String, Int) -> Continuation) { - c(Controller(), "OK", 56).resume(Unit) +fun builder(coroutine c: Controller.(Long, String) -> Continuation) { + c(Controller(), 56L, "OK").resume(Unit) } fun noinline(l: () -> String) = l() @@ -14,23 +14,23 @@ inline fun inline(l: () -> String) = l() fun box(): String { var result = "" - builder { s, i -> - result = suspendHere(s + "#" + i) + builder { l, s -> + result = suspendHere(s + "#" + l) } if (result != "OK#56") return "fail 1: $result" - builder { s, i -> + builder { l, s -> result = suspendHere(noinline { - s + "#" + i + s + "#" + l }) } if (result != "OK#56") return "fail 2: $result" - builder { s, i -> + builder { l, s -> result = suspendHere(inline { - s + "#" + i + s + "#" + l }) }