Switch sourcesets of experimental and release coroutines
- Move experimental coroutines out of the main source root. - Include experimental coroutines into the coroutines source set. - Include release coroutines into the main source set.
This commit is contained in:
@@ -16,6 +16,7 @@ def builtinsSrcDir2 = "${buildDir}/builtin-sources-for-builtins"
|
||||
def commonSrcDir = "${projectDir}/../src/kotlin"
|
||||
def commonSrcDir2 = "${projectDir}/../common/src"
|
||||
def coroutinesJsSrcDir = "${projectDir}/../coroutines/js/src"
|
||||
def coroutinesExpJsSrcDir = "${projectDir}/../coroutines-experimental/js/src"
|
||||
|
||||
def builtinsDir = "${rootDir}/core/builtins"
|
||||
def experimentalSrcDir = "${rootDir}/libraries/stdlib/experimental"
|
||||
@@ -46,6 +47,7 @@ sourceSets {
|
||||
kotlin {
|
||||
srcDir builtinsSrcDir
|
||||
srcDir jsSrcDir
|
||||
srcDir coroutinesJsSrcDir
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +66,7 @@ sourceSets {
|
||||
|
||||
coroutines {
|
||||
kotlin {
|
||||
srcDir coroutinesJsSrcDir
|
||||
srcDir coroutinesExpJsSrcDir
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,7 +154,7 @@ compileKotlin2Js {
|
||||
"-Xuse-experimental=kotlin.ExperimentalMultiplatform",
|
||||
"-Xuse-experimental=kotlin.contracts.ExperimentalContracts",
|
||||
"-XXLanguage:+InlineClasses",
|
||||
"-XXLanguage:-ReleaseCoroutines"
|
||||
"-XXLanguage:+ReleaseCoroutines"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -177,7 +179,8 @@ compileCoroutinesKotlin2Js {
|
||||
sourceMap = true
|
||||
sourceMapPrefix = "./"
|
||||
freeCompilerArgs += [
|
||||
"-Xuse-experimental=kotlin.contracts.ExperimentalContracts"
|
||||
"-Xuse-experimental=kotlin.contracts.ExperimentalContracts",
|
||||
"-XXLanguage:-ReleaseCoroutines"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.coroutines.experimental
|
||||
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
@JsName("CoroutineImpl")
|
||||
internal abstract class CoroutineImpl(private val resultContinuation: Continuation<Any?>) : Continuation<Any?> {
|
||||
protected var state = 0
|
||||
protected var exceptionState = 0
|
||||
protected var result: Any? = null
|
||||
protected var exception: Throwable? = null
|
||||
protected var finallyPath: Array<Int>? = null
|
||||
|
||||
public override val context: CoroutineContext = resultContinuation.context
|
||||
|
||||
val facade: Continuation<Any?> = context[ContinuationInterceptor]?.interceptContinuation(this) ?: this
|
||||
|
||||
override fun resume(value: Any?) {
|
||||
result = value
|
||||
doResumeWrapper()
|
||||
}
|
||||
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
state = exceptionState
|
||||
this.exception = exception
|
||||
doResumeWrapper()
|
||||
}
|
||||
|
||||
protected fun doResumeWrapper() {
|
||||
processBareContinuationResume(resultContinuation) { doResume() }
|
||||
}
|
||||
|
||||
protected abstract fun doResume(): Any?
|
||||
}
|
||||
|
||||
private val UNDECIDED: Any? = Any()
|
||||
private val RESUMED: Any? = Any()
|
||||
|
||||
private class Fail(val exception: Throwable)
|
||||
|
||||
@PublishedApi
|
||||
internal actual class SafeContinuation<in T>
|
||||
internal actual constructor(
|
||||
private val delegate: Continuation<T>,
|
||||
initialResult: Any?
|
||||
) : Continuation<T> {
|
||||
|
||||
@PublishedApi
|
||||
internal actual constructor(delegate: Continuation<T>) : this(delegate, UNDECIDED)
|
||||
|
||||
public actual override val context: CoroutineContext
|
||||
get() = delegate.context
|
||||
|
||||
private var result: Any? = initialResult
|
||||
|
||||
actual override fun resume(value: T) {
|
||||
when {
|
||||
result === UNDECIDED -> {
|
||||
result = value
|
||||
}
|
||||
result === COROUTINE_SUSPENDED -> {
|
||||
result = RESUMED
|
||||
delegate.resume(value)
|
||||
}
|
||||
else -> {
|
||||
throw IllegalStateException("Already resumed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actual override fun resumeWithException(exception: Throwable) {
|
||||
when {
|
||||
result === UNDECIDED -> {
|
||||
result = Fail(exception)
|
||||
}
|
||||
result === COROUTINE_SUSPENDED -> {
|
||||
result = RESUMED
|
||||
delegate.resumeWithException(exception)
|
||||
}
|
||||
else -> {
|
||||
throw IllegalStateException("Already resumed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
internal actual fun getResult(): Any? {
|
||||
if (result === UNDECIDED) {
|
||||
result = COROUTINE_SUSPENDED
|
||||
}
|
||||
val result = this.result
|
||||
return when {
|
||||
result === RESUMED -> {
|
||||
COROUTINE_SUSPENDED // already called continuation, indicate SUSPENDED upstream
|
||||
}
|
||||
result is Fail -> {
|
||||
throw result.exception
|
||||
}
|
||||
else -> {
|
||||
result // either SUSPENDED or data
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.coroutines.experimental.intrinsics
|
||||
|
||||
import kotlin.coroutines.experimental.Continuation
|
||||
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun <T> (suspend () -> T).startCoroutineUninterceptedOrReturn(
|
||||
completion: Continuation<T>
|
||||
): Any? = this.asDynamic()(completion, false)
|
||||
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun <R, T> (suspend R.() -> T).startCoroutineUninterceptedOrReturn(
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
): Any? = this.asDynamic()(receiver, completion, false)
|
||||
|
||||
@SinceKotlin("1.1")
|
||||
public actual fun <R, T> (suspend R.() -> T).createCoroutineUnchecked(
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
): Continuation<Unit> = this.asDynamic()(receiver, completion, true).facade
|
||||
|
||||
@SinceKotlin("1.1")
|
||||
public actual fun <T> (suspend () -> T).createCoroutineUnchecked(
|
||||
completion: Continuation<T>
|
||||
): Continuation<Unit> = this.asDynamic()(completion, true).facade
|
||||
|
||||
|
||||
/**
|
||||
* This value is used as a return value of [suspendCoroutineOrReturn] `block` argument to state that
|
||||
* the execution was suspended and will not return any result immediately.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public actual val COROUTINE_SUSPENDED: Any = CoroutineSuspendedMarker
|
||||
|
||||
private object CoroutineSuspendedMarker
|
||||
Reference in New Issue
Block a user