[Wasm] Support coroutines
- Reuse JS IR Suspend function lowering
- Fix types
- Disable reinterpretCast-based optimization for inline
classes
- Add basic support to Wasm stdlib
- Explicitly transform suspend functions into regular functions
with continuations
- Clean suspend function handling from JS IR codegen
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("RedundantSuspendModifier")
|
||||
|
||||
package kotlin.wasm.internal
|
||||
|
||||
import kotlin.coroutines.*
|
||||
|
||||
@PublishedApi
|
||||
@ExcludedFromCodegen
|
||||
internal fun <T> getContinuation(): Continuation<T> =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@PublishedApi
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
internal suspend fun <T> returnIfSuspended(@Suppress("UNUSED_PARAMETER") argument: Any?): T =
|
||||
argument as T
|
||||
|
||||
@PublishedApi
|
||||
internal fun <T> interceptContinuationIfNeeded(
|
||||
context: CoroutineContext,
|
||||
continuation: Continuation<T>
|
||||
) = context[ContinuationInterceptor]?.interceptContinuation(continuation) ?: continuation
|
||||
|
||||
|
||||
@PublishedApi
|
||||
internal suspend fun getCoroutineContext(): CoroutineContext = getContinuation<Any?>().context
|
||||
|
||||
@PublishedApi
|
||||
internal suspend fun <T> suspendCoroutineUninterceptedOrReturn(block: (Continuation<T>) -> Any?): T =
|
||||
returnIfSuspended<T>(block(getContinuation<T>()))
|
||||
|
||||
@ExcludedFromCodegen
|
||||
@PublishedApi
|
||||
internal fun <T> startCoroutineUninterceptedOrReturnIntrinsic0(
|
||||
f: (suspend () -> T),
|
||||
completion: Continuation<T>
|
||||
): Any? {
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
@ExcludedFromCodegen
|
||||
@PublishedApi
|
||||
internal fun <R, T> startCoroutineUninterceptedOrReturnIntrinsic1(
|
||||
f: (suspend R.() -> T),
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
): Any? {
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
|
||||
@ExcludedFromCodegen
|
||||
@PublishedApi
|
||||
internal fun <R, P, T> startCoroutineUninterceptedOrReturnIntrinsic2(
|
||||
f: (suspend R.(P) -> T),
|
||||
receiver: R,
|
||||
param: P,
|
||||
completion: Continuation<T>
|
||||
): Any? {
|
||||
implementedAsIntrinsic
|
||||
}
|
||||
Reference in New Issue
Block a user