Skip to content

Commit

Permalink
IC & Coroutines: Unbox inline class parameter of suspend lambda
Browse files Browse the repository at this point in the history
inside 'create' if 'create' overrides 'create' from
BaseContinuationImpl. In other words, unbox the parameter if 'create'
accepts only one parameter.

 #KT-43249 Fixed
 #KT-43533 Fixed
  • Loading branch information
ilmirus committed Nov 26, 2020
1 parent eba260f commit 4e33421
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.isInlineClassType
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
Expand Down Expand Up @@ -446,12 +447,24 @@ class CoroutineCodegenForLambda private constructor(
)
} else {
if (generateErasedCreate) {
load(index, AsmTypes.OBJECT_TYPE)
StackValue.coerce(
AsmTypes.OBJECT_TYPE, builtIns.nullableAnyType,
fieldInfoForCoroutineLambdaParameter.fieldType, fieldInfoForCoroutineLambdaParameter.fieldKotlinType,
this
)
if (parameter.type.isInlineClassType()) {
load(cloneIndex, fieldInfoForCoroutineLambdaParameter.ownerType)
load(index, AsmTypes.OBJECT_TYPE)
StackValue.unboxInlineClass(AsmTypes.OBJECT_TYPE, parameter.type, this)
putfield(
fieldInfoForCoroutineLambdaParameter.ownerInternalName,
fieldInfoForCoroutineLambdaParameter.fieldName,
fieldInfoForCoroutineLambdaParameter.fieldType.descriptor
)
continue
} else {
load(index, AsmTypes.OBJECT_TYPE)
StackValue.coerce(
AsmTypes.OBJECT_TYPE, builtIns.nullableAnyType,
fieldInfoForCoroutineLambdaParameter.fieldType, fieldInfoForCoroutineLambdaParameter.fieldKotlinType,
this
)
}
} else {
load(index, fieldInfoForCoroutineLambdaParameter.fieldType)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME

import kotlin.coroutines.*

fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}

inline class IC(val s: String)

suspend fun <T> List<T>.onEach(c: suspend (T) -> Unit) {
for (e in this) {
c(e)
}
}

fun box(): String {
var res = ""
builder {
listOf(IC("O"), IC("K")).onEach { res += it.s }
}
return res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME

import kotlin.coroutines.*

fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}

inline class IC(val s: String)

suspend fun <T> List<T>.onEach(c: suspend (T) -> Unit) {
for (e in this) {
c(e)
}
}

var c: Continuation<Any>? = null

fun box(): String {
var res = ""
builder {
listOf(IC("O"), IC("K")).onEach { res += suspendCoroutine<String> { cont ->
@Suppress("UNCHECKED_CAST")
c = cont as Continuation<Any>
}}
}
c?.resume("O")
c?.resume("K")
return res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// WITH_RUNTIME
// WITH_COROUTINES
// KJS_WITH_FULL_RUNTIME

import kotlin.coroutines.*
import helpers.*

var result = "FAIL"

fun builder(c: suspend () -> Unit) {
c.startCoroutine(handleExceptionContinuation {
result = it.message!!
})
}

inline class IC(val s: String)

suspend fun <T> List<T>.onEach(c: suspend (T) -> Unit) {
for (e in this) {
c(e)
}
}

var c: Continuation<Any>? = null

fun box(): String {
builder {
listOf(IC("O"), IC("K")).onEach { suspendCoroutine<String> { cont ->
@Suppress("UNCHECKED_CAST")
c = cont as Continuation<Any>
}}
}
c?.resumeWithException(IllegalStateException("OK"))
return result
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e33421

Please sign in to comment.