Coroutines lowering
This commit is contained in:
@@ -3,6 +3,14 @@ package konan.internal
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
@Intrinsic
|
||||
@PublishedApi
|
||||
internal fun <T> getContinuation(): Continuation<T> = throw AssertionError("Call to getContinuation should've been lowered")
|
||||
|
||||
@Intrinsic
|
||||
@PublishedApi
|
||||
internal fun <T> returnIfSuspended(value: Any?): T = throw AssertionError("Call to returnIfSuspended should've been lowered")
|
||||
|
||||
// Single-threaded continuation.
|
||||
class SafeContinuation<in T>
|
||||
constructor(
|
||||
@@ -67,6 +75,7 @@ internal fun <T> interceptContinuationIfNeeded(
|
||||
* @suppress
|
||||
*/
|
||||
@ExportForCompiler
|
||||
@PublishedApi
|
||||
internal fun <T> normalizeContinuation(continuation: Continuation<T>): Continuation<T> =
|
||||
(continuation as? CoroutineImpl)?.facade ?: continuation
|
||||
|
||||
@@ -80,7 +89,8 @@ abstract internal class CoroutineImpl(
|
||||
|
||||
// label == -1 when coroutine cannot be started (it is just a factory object) or has already finished execution
|
||||
// label == 0 in initial part of the coroutine
|
||||
protected var label: Int = if (completion != null) 0L else -1L
|
||||
// TODO: use IntPtr.
|
||||
protected var label: Long = if (completion != null) 0L else -1L
|
||||
|
||||
private val _context: CoroutineContext? = completion?.context
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ package kotlin.coroutines.experimental.intrinsics
|
||||
import kotlin.coroutines.experimental.Continuation
|
||||
import kotlin.coroutines.experimental.CoroutineContext
|
||||
import kotlin.coroutines.experimental.processBareContinuationResume
|
||||
import konan.internal.interceptContinuationIfNeeded
|
||||
import konan.internal.CoroutineImpl
|
||||
import konan.internal.*
|
||||
|
||||
/**
|
||||
* Obtains the current continuation instance inside suspend functions and either suspend
|
||||
@@ -40,7 +39,8 @@ import konan.internal.CoroutineImpl
|
||||
* continuation instance.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline suspend fun <T> suspendCoroutineOrReturn(crossinline block: (Continuation<T>) -> Any?): T = throw Error("Should've been intrinsified")
|
||||
public inline suspend fun <T> suspendCoroutineOrReturn(crossinline block: (Continuation<T>) -> Any?): T =
|
||||
returnIfSuspended<T>(block(normalizeContinuation<T>(getContinuation<T>())))
|
||||
|
||||
/**
|
||||
* This value is used as a return value of [suspendCoroutineOrReturn] `block` argument to state that
|
||||
|
||||
Reference in New Issue
Block a user