JVM IR: Remove remains of 1.2 coroutines from tests
Remove CoroutineAdapter and LANGUAGE: +ReleaseContinuation, which are meaninless now. Update the tests accordingly.
This commit is contained in:
committed by
Space Team
parent
ebc4cf7f96
commit
d7fd2471b8
+2
-4
@@ -18,11 +18,9 @@ class Controller {
|
|||||||
|
|
||||||
fun builder(c: suspend Controller.() -> Unit) {
|
fun builder(c: suspend Controller.() -> Unit) {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c.startCoroutine(controller, object : helpers.ContinuationAdapter<Unit>() {
|
c.startCoroutine(controller, object : Continuation<Unit> {
|
||||||
override val context: CoroutineContext = EmptyCoroutineContext
|
override val context: CoroutineContext = EmptyCoroutineContext
|
||||||
override fun resume(value: Unit) {}
|
override fun resumeWith(value: Result<Unit>) {}
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
controller.callback()
|
controller.callback()
|
||||||
|
|||||||
+7
-7
@@ -50,15 +50,15 @@ fun box(): String {
|
|||||||
|
|
||||||
fun <T> async(c: suspend () -> T): CompletableFuture<T> {
|
fun <T> async(c: suspend () -> T): CompletableFuture<T> {
|
||||||
val future = CompletableFuture<T>()
|
val future = CompletableFuture<T>()
|
||||||
c.startCoroutine(object : helpers.ContinuationAdapter<T>() {
|
c.startCoroutine(object : Continuation<T> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: T) {
|
override fun resumeWith(data: Result<T>) {
|
||||||
future.complete(data)
|
if (data.isSuccess) {
|
||||||
}
|
future.complete(data.getOrThrow())
|
||||||
|
} else {
|
||||||
override fun resumeWithException(exception: Throwable) {
|
future.completeExceptionally(data.exceptionOrNull()!!)
|
||||||
future.completeExceptionally(exception)
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return future
|
return future
|
||||||
|
|||||||
@@ -47,15 +47,15 @@ fun box(): String {
|
|||||||
|
|
||||||
fun <T> async(c: suspend () -> T): CompletableFuture<T> {
|
fun <T> async(c: suspend () -> T): CompletableFuture<T> {
|
||||||
val future = CompletableFuture<T>()
|
val future = CompletableFuture<T>()
|
||||||
c.startCoroutine(object : helpers.ContinuationAdapter<T>() {
|
c.startCoroutine(object : Continuation<T> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: T) {
|
override fun resumeWith(data: Result<T>) {
|
||||||
future.complete(data)
|
try {
|
||||||
}
|
future.complete(data.getOrThrow())
|
||||||
|
} catch (t: Throwable) {
|
||||||
override fun resumeWithException(exception: Throwable) {
|
future.completeExceptionally(t)
|
||||||
future.completeExceptionally(exception)
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return future
|
return future
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ fun <T> asyncGenerate(block: suspend AsyncGenerator<T>.() -> Unit): AsyncSequenc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, ContinuationAdapter<Unit>() {
|
class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuation<Unit> {
|
||||||
var computedNext = false
|
var computedNext = false
|
||||||
var nextValue: T? = null
|
var nextValue: T? = null
|
||||||
var nextStep: Continuation<Unit>? = null
|
var nextStep: Continuation<Unit>? = null
|
||||||
@@ -86,14 +86,9 @@ class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuati
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Completion continuation implementation
|
// Completion continuation implementation
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
done()
|
done()
|
||||||
resumeIterator(null)
|
resumeIterator(value.exceptionOrNull())
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
done()
|
|
||||||
resumeIterator(exception)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generator implementation
|
// Generator implementation
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ fun <T> asyncGenerate(block: suspend AsyncGenerator<T>.() -> Unit): AsyncSequenc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, ContinuationAdapter<Unit>() {
|
class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuation<Unit> {
|
||||||
var computedNext = false
|
var computedNext = false
|
||||||
var nextValue: T? = null
|
var nextValue: T? = null
|
||||||
var nextStep: Continuation<Unit>? = null
|
var nextStep: Continuation<Unit>? = null
|
||||||
@@ -86,14 +86,9 @@ class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuati
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Completion continuation implementation
|
// Completion continuation implementation
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
done()
|
done()
|
||||||
resumeIterator(null)
|
resumeIterator(value.exceptionOrNull())
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
done()
|
|
||||||
resumeIterator(exception)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generator implementation
|
// Generator implementation
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ fun <T> asyncGenerate(block: suspend AsyncGenerator<T>.() -> Unit): AsyncSequenc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, ContinuationAdapter<Unit>() {
|
class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuation<Unit> {
|
||||||
var computedNext = false
|
var computedNext = false
|
||||||
var nextValue: T? = null
|
var nextValue: T? = null
|
||||||
var nextStep: Continuation<Unit>? = null
|
var nextStep: Continuation<Unit>? = null
|
||||||
@@ -86,14 +86,9 @@ class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuati
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Completion continuation implementation
|
// Completion continuation implementation
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
done()
|
done()
|
||||||
resumeIterator(null)
|
resumeIterator(value.exceptionOrNull())
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
done()
|
|
||||||
resumeIterator(exception)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generator implementation
|
// Generator implementation
|
||||||
|
|||||||
@@ -9,14 +9,11 @@ suspend fun suspendHere(): Any = suspendCoroutineUninterceptedOrReturn { x -> }
|
|||||||
fun builder(c: suspend () -> Unit) {
|
fun builder(c: suspend () -> Unit) {
|
||||||
var exception: Throwable? = null
|
var exception: Throwable? = null
|
||||||
|
|
||||||
c.createCoroutine(object : ContinuationAdapter<Unit>() {
|
c.createCoroutine(object : Continuation<Unit> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Unit) {
|
override fun resumeWith(data: Result<Unit>) {
|
||||||
}
|
exception = data.exceptionOrNull()
|
||||||
|
|
||||||
override fun resumeWithException(e: Throwable) {
|
|
||||||
exception = e
|
|
||||||
}
|
}
|
||||||
}).resumeWithException(RuntimeException("OK"))
|
}).resumeWithException(RuntimeException("OK"))
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,11 @@ class Controller {
|
|||||||
|
|
||||||
fun builder(c: suspend Controller.() -> Unit): String {
|
fun builder(c: suspend Controller.() -> Unit): String {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c.startCoroutine(controller, object : ContinuationAdapter<Unit>() {
|
c.startCoroutine(controller, object : Continuation<Unit> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Unit) {
|
override fun resumeWith(data: Result<Unit>) {
|
||||||
|
val exception = data.exceptionOrNull() ?: return
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
controller.result += "caught(${exception.message});"
|
controller.result += "caught(${exception.message});"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+3
-4
@@ -17,12 +17,11 @@ class Controller {
|
|||||||
|
|
||||||
fun builder(c: suspend Controller.() -> Unit): String {
|
fun builder(c: suspend Controller.() -> Unit): String {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c.startCoroutine(controller, object : ContinuationAdapter<Unit>() {
|
c.startCoroutine(controller, object : Continuation<Unit> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Unit) {}
|
override fun resumeWith(data: Result<Unit>) {
|
||||||
|
val exception = data.exceptionOrNull() ?: return
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
controller.result += "ignoreCaught(${exception.message});"
|
controller.result += "ignoreCaught(${exception.message});"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+3
-3
@@ -24,10 +24,10 @@ suspend fun foo(a: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun builder(callback: suspend () -> Unit) {
|
fun builder(callback: suspend () -> Unit) {
|
||||||
callback.startCoroutine(object : ContinuationAdapter<Unit>() {
|
callback.startCoroutine(object : Continuation<Unit> {
|
||||||
override val context: CoroutineContext = EmptyCoroutineContext
|
override val context: CoroutineContext = EmptyCoroutineContext
|
||||||
override fun resume(value: Unit) = Unit
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
override fun resumeWithException(exception: Throwable) {
|
val exception = value.exceptionOrNull() ?: return
|
||||||
id("FAIL WITH EXCEPTION: ${exception.message}")
|
id("FAIL WITH EXCEPTION: ${exception.message}")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+6
-16
@@ -7,14 +7,13 @@
|
|||||||
import helpers.*
|
import helpers.*
|
||||||
import kotlin.coroutines.*
|
import kotlin.coroutines.*
|
||||||
import kotlin.coroutines.intrinsics.*
|
import kotlin.coroutines.intrinsics.*
|
||||||
import helpers.ContinuationAdapter
|
|
||||||
|
|
||||||
fun runCustomLambdaAsCoroutine(e: Throwable? = null, x: (Continuation<String>) -> Any?): String {
|
fun runCustomLambdaAsCoroutine(e: Throwable? = null, x: (Continuation<String>) -> Any?): String {
|
||||||
var result = "fail"
|
var result = "fail"
|
||||||
var wasIntercepted = false
|
var wasIntercepted = false
|
||||||
val c = (x as suspend () -> String).createCoroutine(object: ContinuationAdapter<String>() {
|
val c = (x as suspend () -> String).createCoroutine(object: Continuation<String> {
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
throw exception
|
result = value.getOrThrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
@@ -30,18 +29,13 @@ fun runCustomLambdaAsCoroutine(e: Throwable? = null, x: (Continuation<String>) -
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <T> interceptContinuation(continuation: Continuation<T>) = object : ContinuationAdapter<T>() {
|
override fun <T> interceptContinuation(continuation: Continuation<T>) = object : Continuation<T> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = continuation.context
|
get() = continuation.context
|
||||||
|
|
||||||
override fun resume(value: T) {
|
override fun resumeWith(value: Result<T>) {
|
||||||
wasIntercepted = true
|
wasIntercepted = true
|
||||||
continuation.resume(value)
|
continuation.resumeWith(value)
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
wasIntercepted = true
|
|
||||||
continuation.resumeWithException(exception)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,10 +50,6 @@ fun runCustomLambdaAsCoroutine(e: Throwable? = null, x: (Continuation<String>) -
|
|||||||
override val key: CoroutineContext.Key<*>
|
override val key: CoroutineContext.Key<*>
|
||||||
get() = ContinuationInterceptor.Key
|
get() = ContinuationInterceptor.Key
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resume(value: String) {
|
|
||||||
result = value
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (e != null)
|
if (e != null)
|
||||||
|
|||||||
+3
-7
@@ -20,13 +20,9 @@ fun builder(c: suspend () -> Unit) {
|
|||||||
|
|
||||||
fun builderConsumer(c: suspend () -> Consumer): Consumer {
|
fun builderConsumer(c: suspend () -> Consumer): Consumer {
|
||||||
var res: Consumer? = null
|
var res: Consumer? = null
|
||||||
c.startCoroutine(object : ContinuationAdapter<Consumer>() {
|
c.startCoroutine(object : Continuation<Consumer> {
|
||||||
override fun resume(value: Consumer) {
|
override fun resumeWith(value: Result<Consumer>) {
|
||||||
res = value
|
res = value.getOrThrow()
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(e: Throwable) {
|
|
||||||
throw e
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|||||||
+7
-20
@@ -27,25 +27,19 @@ class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class ContinuationDispatcher : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
|
abstract class ContinuationDispatcher : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
|
||||||
abstract fun <T> dispatchResume(value: T, continuation: Continuation<T>): Boolean
|
abstract fun <T> dispatchResumeWith(value: Result<T>, continuation: Continuation<T>): Boolean
|
||||||
abstract fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean
|
|
||||||
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = DispatchedContinuation(this, continuation)
|
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = DispatchedContinuation(this, continuation)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DispatchedContinuation<T>(
|
private class DispatchedContinuation<T>(
|
||||||
val dispatcher: ContinuationDispatcher,
|
val dispatcher: ContinuationDispatcher,
|
||||||
val continuation: Continuation<T>
|
val continuation: Continuation<T>
|
||||||
): ContinuationAdapter<T>() {
|
): Continuation<T> {
|
||||||
override val context: CoroutineContext = continuation.context
|
override val context: CoroutineContext = continuation.context
|
||||||
|
|
||||||
override fun resume(value: T) {
|
override fun resumeWith(value: Result<T>) {
|
||||||
if (!dispatcher.dispatchResume(value, continuation))
|
if (!dispatcher.dispatchResumeWith(value, continuation))
|
||||||
continuation.resume(value)
|
continuation.resumeWith(value)
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
if (!dispatcher.dispatchResumeWithException(exception, continuation))
|
|
||||||
continuation.resumeWithException(exception)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,16 +53,9 @@ fun test(c: suspend Controller.() -> Unit): String {
|
|||||||
controller.log += "after $id;"
|
controller.log += "after $id;"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <P> dispatchResume(data: P, continuation: Continuation<P>): Boolean {
|
override fun <P> dispatchResumeWith(data: Result<P>, continuation: Continuation<P>): Boolean {
|
||||||
dispatchResume {
|
dispatchResume {
|
||||||
continuation.resume(data)
|
continuation.resumeWith(data)
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean {
|
|
||||||
dispatchResume {
|
|
||||||
continuation.resumeWithException(exception)
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -39,16 +39,13 @@ class GeneratedSequence<out T>(private val block: suspend Generator<T>.() -> Uni
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GeneratedIterator<T>(block: suspend Generator<T>.() -> Unit) : AbstractIterator<T>(), Generator<T> {
|
class GeneratedIterator<T>(block: suspend Generator<T>.() -> Unit) : AbstractIterator<T>(), Generator<T> {
|
||||||
private var nextStep: Continuation<Unit> = block.createCoroutine(this, object : ContinuationAdapter<Unit>() {
|
private var nextStep: Continuation<Unit> = block.createCoroutine(this, object : Continuation<Unit> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Unit) {
|
override fun resumeWith(data: Result<Unit>) {
|
||||||
|
data.getOrThrow()
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
throw exception
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
override fun computeNext() {
|
override fun computeNext() {
|
||||||
|
|||||||
+3
-7
@@ -19,16 +19,12 @@ suspend fun multipleArgs(a: Any, b: Any, c: Any) =
|
|||||||
fun builder(c: suspend () -> String): String {
|
fun builder(c: suspend () -> String): String {
|
||||||
var fromSuspension: String? = null
|
var fromSuspension: String? = null
|
||||||
|
|
||||||
val continuation = object : ContinuationAdapter<String>() {
|
val continuation = object : Continuation<String> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = EmptyCoroutineContext
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
fromSuspension = "Exception: ${exception}"
|
fromSuspension = try { value.getOrThrow() } catch (exception: Throwable) { "Exception: ${exception}" }
|
||||||
}
|
|
||||||
|
|
||||||
override fun resume(value: String) {
|
|
||||||
fromSuspension = value
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -20,16 +20,16 @@ class Controller {
|
|||||||
fun builder(c: suspend Controller.() -> String): String {
|
fun builder(c: suspend Controller.() -> String): String {
|
||||||
var fromSuspension: String? = null
|
var fromSuspension: String? = null
|
||||||
|
|
||||||
c.startCoroutine(this, object : ContinuationAdapter<String>() {
|
c.startCoroutine(this, object : Continuation<String> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = EmptyCoroutineContext
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
fromSuspension = "Exception: " + exception.message!!
|
fromSuspension = try {
|
||||||
}
|
value.getOrThrow()
|
||||||
|
} catch (exception: Throwable) {
|
||||||
override fun resume(value: String) {
|
"Exception: " + exception.message!!
|
||||||
fromSuspension = value
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Vendored
+7
-7
@@ -24,16 +24,16 @@ class Controller {
|
|||||||
fun builder(c: suspend Controller.() -> String): String {
|
fun builder(c: suspend Controller.() -> String): String {
|
||||||
var fromSuspension: String? = null
|
var fromSuspension: String? = null
|
||||||
|
|
||||||
c.startCoroutine(this, object : ContinuationAdapter<String>() {
|
c.startCoroutine(this, object : Continuation<String> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = EmptyCoroutineContext
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
fromSuspension = "Exception: " + exception.message!!
|
fromSuspension = try {
|
||||||
}
|
value.getOrThrow()
|
||||||
|
} catch (exception: Throwable) {
|
||||||
override fun resume(value: String) {
|
"Exception: " + exception.message!!
|
||||||
fromSuspension = value
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+10
-15
@@ -30,16 +30,16 @@ fun builder(testNum: Int, expectedCount: Int, c: suspend () -> String): String {
|
|||||||
var fromSuspension: String? = null
|
var fromSuspension: String? = null
|
||||||
var counter = 0
|
var counter = 0
|
||||||
|
|
||||||
c.startCoroutineUninterceptedOrReturn(object : ContinuationAdapter<String>() {
|
c.startCoroutineUninterceptedOrReturn(object : Continuation<String> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = ContinuationDispatcher { counter++ }
|
get() = ContinuationDispatcher { counter++ }
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
fromSuspension = "Exception: " + exception.message!!
|
fromSuspension = try {
|
||||||
}
|
value.getOrThrow()
|
||||||
|
} catch (exception: Throwable) {
|
||||||
override fun resume(value: String) {
|
"Exception: " + exception.message!!
|
||||||
fromSuspension = value
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -54,17 +54,12 @@ class ContinuationDispatcher(val dispatcher: () -> Unit) : AbstractCoroutineCont
|
|||||||
private class DispatchedContinuation<T>(
|
private class DispatchedContinuation<T>(
|
||||||
val dispatcher: () -> Unit,
|
val dispatcher: () -> Unit,
|
||||||
val continuation: Continuation<T>
|
val continuation: Continuation<T>
|
||||||
): ContinuationAdapter<T>() {
|
): Continuation<T> {
|
||||||
override val context: CoroutineContext = continuation.context
|
override val context: CoroutineContext = continuation.context
|
||||||
|
|
||||||
override fun resume(value: T) {
|
override fun resumeWith(value: Result<T>) {
|
||||||
dispatcher()
|
dispatcher()
|
||||||
continuation.resume(value)
|
continuation.resumeWith(value)
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
dispatcher()
|
|
||||||
continuation.resumeWithException(exception)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -18,16 +18,16 @@ suspend fun suspendWithException(): String = suspendCoroutineUninterceptedOrRetu
|
|||||||
fun builder(c: suspend () -> String): String {
|
fun builder(c: suspend () -> String): String {
|
||||||
var fromSuspension: String? = null
|
var fromSuspension: String? = null
|
||||||
|
|
||||||
c.startCoroutine(object: ContinuationAdapter<String>() {
|
c.startCoroutine(object: Continuation<String> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = EmptyCoroutineContext
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
fromSuspension = "Exception: " + exception.message!!
|
fromSuspension = try {
|
||||||
}
|
value.getOrThrow()
|
||||||
|
} catch (exception: Throwable) {
|
||||||
override fun resume(value: String) {
|
"Exception: " + exception.message!!
|
||||||
fromSuspension = value
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Vendored
+7
-7
@@ -19,16 +19,16 @@ fun builder(shouldSuspend: Boolean, c: suspend () -> String): String {
|
|||||||
var fromSuspension: String? = null
|
var fromSuspension: String? = null
|
||||||
|
|
||||||
val result = try {
|
val result = try {
|
||||||
c.startCoroutineUninterceptedOrReturn(object: ContinuationAdapter<String>() {
|
c.startCoroutineUninterceptedOrReturn(object: Continuation<String> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = EmptyCoroutineContext
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
fromSuspension = "Exception: " + exception.message!!
|
fromSuspension = try {
|
||||||
}
|
value.getOrThrow()
|
||||||
|
} catch (exception: Throwable) {
|
||||||
override fun resume(value: String) {
|
"Exception: " + exception.message!!
|
||||||
fromSuspension = value
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
+10
-15
@@ -25,16 +25,16 @@ fun builder(testNum: Int, shouldSuspend: Boolean, expectedCount: Int, c: suspend
|
|||||||
var counter = 0
|
var counter = 0
|
||||||
|
|
||||||
val result = try {
|
val result = try {
|
||||||
c.startCoroutineUninterceptedOrReturn(object: ContinuationAdapter<String>() {
|
c.startCoroutineUninterceptedOrReturn(object: Continuation<String> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = ContinuationDispatcher { counter++ }
|
get() = ContinuationDispatcher { counter++ }
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
fromSuspension = "Exception: " + exception.message!!
|
fromSuspension = try {
|
||||||
}
|
value.getOrThrow()
|
||||||
|
} catch (exception: Throwable) {
|
||||||
override fun resume(value: String) {
|
"Exception: " + exception.message!!
|
||||||
fromSuspension = value
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -62,17 +62,12 @@ class ContinuationDispatcher(val dispatcher: () -> Unit) : AbstractCoroutineCont
|
|||||||
private class DispatchedContinuation<T>(
|
private class DispatchedContinuation<T>(
|
||||||
val dispatcher: () -> Unit,
|
val dispatcher: () -> Unit,
|
||||||
val continuation: Continuation<T>
|
val continuation: Continuation<T>
|
||||||
): ContinuationAdapter<T>() {
|
): Continuation<T> {
|
||||||
override val context: CoroutineContext = continuation.context
|
override val context: CoroutineContext = continuation.context
|
||||||
|
|
||||||
override fun resume(value: T) {
|
override fun resumeWith(value: Result<T>) {
|
||||||
dispatcher()
|
dispatcher()
|
||||||
continuation.resume(value)
|
continuation.resumeWith(value)
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
dispatcher()
|
|
||||||
continuation.resumeWithException(exception)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
compiler/testData/codegen/box/coroutines/intrinsicSemantics/suspendCoroutineUninterceptedOrReturn.kt
Vendored
+10
-15
@@ -20,16 +20,16 @@ fun builder(shouldSuspend: Boolean, c: suspend () -> String): String {
|
|||||||
var counter = 0
|
var counter = 0
|
||||||
|
|
||||||
val result = try {
|
val result = try {
|
||||||
c.startCoroutineUninterceptedOrReturn(object: ContinuationAdapter<String>() {
|
c.startCoroutineUninterceptedOrReturn(object: Continuation<String> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = ContinuationDispatcher { counter++ }
|
get() = ContinuationDispatcher { counter++ }
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWith(value: Result<String>) {
|
||||||
fromSuspension = "Exception: " + exception.message!!
|
fromSuspension = try {
|
||||||
}
|
value.getOrThrow()
|
||||||
|
} catch (exception: Throwable) {
|
||||||
override fun resume(value: String) {
|
"Exception: " + exception.message!!
|
||||||
fromSuspension = value
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -55,17 +55,12 @@ class ContinuationDispatcher(val dispatcher: () -> Unit) : AbstractCoroutineCont
|
|||||||
private class DispatchedContinuation<T>(
|
private class DispatchedContinuation<T>(
|
||||||
val dispatcher: () -> Unit,
|
val dispatcher: () -> Unit,
|
||||||
val continuation: Continuation<T>
|
val continuation: Continuation<T>
|
||||||
): ContinuationAdapter<T>() {
|
): Continuation<T> {
|
||||||
override val context: CoroutineContext = continuation.context
|
override val context: CoroutineContext = continuation.context
|
||||||
|
|
||||||
override fun resume(value: T) {
|
override fun resumeWith(value: Result<T>) {
|
||||||
dispatcher()
|
dispatcher()
|
||||||
continuation.resume(value)
|
continuation.resumeWith(value)
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
dispatcher()
|
|
||||||
continuation.resumeWithException(exception)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-6
@@ -28,20 +28,17 @@ suspend fun callLocal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun builder(c: suspend () -> Unit) {
|
fun builder(c: suspend () -> Unit) {
|
||||||
val continuation = object: ContinuationAdapter<Unit>() {
|
val continuation = object: Continuation<Unit> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = EmptyCoroutineContext
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
|
value.getOrThrow()
|
||||||
proceed = {
|
proceed = {
|
||||||
result = "OK"
|
result = "OK"
|
||||||
finished = true
|
finished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
throw exception
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
c.startCoroutine(continuation)
|
c.startCoroutine(continuation)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,27 +47,25 @@ suspend fun sleep(): Unit = suspendCoroutine { c ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun async(f: suspend () -> Unit) {
|
fun async(f: suspend () -> Unit) {
|
||||||
f.startCoroutine(object : ContinuationAdapter<Unit>() {
|
f.startCoroutine(object : Continuation<Unit> {
|
||||||
override fun resume(x: Unit) {
|
override fun resumeWith(x: Result<Unit>) {
|
||||||
proceed = {
|
proceed = {
|
||||||
result += "done;"
|
result += "done;"
|
||||||
finished = true
|
finished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun resumeWithException(x: Throwable) {}
|
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun asyncSuspend(f: suspend () -> Unit) {
|
fun asyncSuspend(f: suspend () -> Unit) {
|
||||||
val coroutine = f.createCoroutine(object : ContinuationAdapter<Unit>() {
|
val coroutine = f.createCoroutine(object : Continuation<Unit> {
|
||||||
override fun resume(x: Unit) {
|
override fun resumeWith(x: Result<Unit>) {
|
||||||
proceed = {
|
proceed = {
|
||||||
result += "done;"
|
result += "done;"
|
||||||
finished = true
|
finished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun resumeWithException(x: Throwable) {}
|
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
})
|
})
|
||||||
coroutine.resume(Unit)
|
coroutine.resume(Unit)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
import helpers.*
|
import helpers.*
|
||||||
|
|||||||
@@ -12,15 +12,11 @@ suspend fun suspendHere(): String = suspendCoroutineUninterceptedOrReturn { x ->
|
|||||||
fun builder(c: suspend () -> Int): Int {
|
fun builder(c: suspend () -> Int): Int {
|
||||||
var res = 0
|
var res = 0
|
||||||
|
|
||||||
c.createCoroutine(object : ContinuationAdapter<Int>() {
|
c.createCoroutine(object : Continuation<Int> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Int) {
|
override fun resumeWith(data: Result<Int>) {
|
||||||
res = data
|
res = data.getOrThrow()
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
throw exception
|
|
||||||
}
|
}
|
||||||
}).resume(Unit)
|
}).resume(Unit)
|
||||||
|
|
||||||
|
|||||||
+7
-20
@@ -27,25 +27,19 @@ class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class ContinuationDispatcher : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
|
abstract class ContinuationDispatcher : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
|
||||||
abstract fun <T> dispatchResume(value: T, continuation: Continuation<T>): Boolean
|
abstract fun <T> dispatchResumeWith(value: Result<T>, continuation: Continuation<T>): Boolean
|
||||||
abstract fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean
|
|
||||||
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = DispatchedContinuation(this, continuation)
|
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = DispatchedContinuation(this, continuation)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DispatchedContinuation<T>(
|
private class DispatchedContinuation<T>(
|
||||||
val dispatcher: ContinuationDispatcher,
|
val dispatcher: ContinuationDispatcher,
|
||||||
val continuation: Continuation<T>
|
val continuation: Continuation<T>
|
||||||
): ContinuationAdapter<T>() {
|
): Continuation<T> {
|
||||||
override val context: CoroutineContext = continuation.context
|
override val context: CoroutineContext = continuation.context
|
||||||
|
|
||||||
override fun resume(value: T) {
|
override fun resumeWith(value: Result<T>) {
|
||||||
if (!dispatcher.dispatchResume(value, continuation))
|
if (!dispatcher.dispatchResumeWith(value, continuation))
|
||||||
continuation.resume(value)
|
continuation.resumeWith(value)
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
if (!dispatcher.dispatchResumeWithException(exception, continuation))
|
|
||||||
continuation.resumeWithException(exception)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,16 +53,9 @@ fun test(c: suspend Controller.() -> Unit): String {
|
|||||||
controller.log += "after $id;"
|
controller.log += "after $id;"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <P> dispatchResume(data: P, continuation: Continuation<P>): Boolean {
|
override fun <P> dispatchResumeWith(data: Result<P>, continuation: Continuation<P>): Boolean {
|
||||||
dispatchResume {
|
dispatchResume {
|
||||||
continuation.resume(data)
|
continuation.resumeWith(data)
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean {
|
|
||||||
dispatchResume {
|
|
||||||
continuation.resumeWithException(exception)
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,17 +37,14 @@ suspend fun bar(x: Int): Int = suspendCoroutine { c ->
|
|||||||
inline suspend fun foo(x: Int) = bar(x)
|
inline suspend fun foo(x: Int) = bar(x)
|
||||||
|
|
||||||
fun async(a: suspend () -> Unit) {
|
fun async(a: suspend () -> Unit) {
|
||||||
a.startCoroutine(object : ContinuationAdapter<Unit>() {
|
a.startCoroutine(object : Continuation<Unit> {
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
proceed = {
|
proceed = {
|
||||||
log("done")
|
log("done")
|
||||||
finished = true
|
finished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resumeWithException(e: Throwable) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -11,15 +11,13 @@ suspend fun suspendHere(): String = suspendCoroutineUninterceptedOrReturn { x ->
|
|||||||
|
|
||||||
fun builder(c: suspend () -> Unit) {
|
fun builder(c: suspend () -> Unit) {
|
||||||
var wasResumeCalled = false
|
var wasResumeCalled = false
|
||||||
c.startCoroutine(object : ContinuationAdapter<Unit>() {
|
c.startCoroutine(object : Continuation<Unit> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
wasResumeCalled = true
|
if (value.isSuccess) {
|
||||||
}
|
wasResumeCalled = true
|
||||||
|
}
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,13 @@ suspend fun suspendHere(): String = suspendCoroutineUninterceptedOrReturn { x ->
|
|||||||
|
|
||||||
fun builder(c: suspend () -> Unit) {
|
fun builder(c: suspend () -> Unit) {
|
||||||
var wasResumeCalled = false
|
var wasResumeCalled = false
|
||||||
c.startCoroutine(object : ContinuationAdapter<Unit>() {
|
c.startCoroutine(object : Continuation<Unit> {
|
||||||
override val context = EmptyCoroutineContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
wasResumeCalled = true
|
if (value.isSuccess) {
|
||||||
}
|
wasResumeCalled = true
|
||||||
|
}
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// IGNORE_BACKEND: JS_IR
|
// IGNORE_BACKEND: JS_IR
|
||||||
// IGNORE_BACKEND: JS_IR_ES6
|
// IGNORE_BACKEND: JS_IR_ES6
|
||||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// NO_CHECK_LAMBDA_INLINING
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
|
|
||||||
@@ -8,17 +7,14 @@ inline suspend fun foo(x: suspend () -> String) = x()
|
|||||||
|
|
||||||
// FILE: box.kt
|
// FILE: box.kt
|
||||||
|
|
||||||
import helpers.ContinuationAdapter
|
|
||||||
import kotlin.coroutines.*
|
import kotlin.coroutines.*
|
||||||
import kotlin.coroutines.intrinsics.*
|
import kotlin.coroutines.intrinsics.*
|
||||||
|
|
||||||
fun builder(c: suspend () -> Unit) {
|
fun builder(c: suspend () -> Unit) {
|
||||||
c.startCoroutine(object: ContinuationAdapter<Unit>() {
|
c.startCoroutine(object: Continuation<Unit> {
|
||||||
override fun resume(value: Unit) {
|
override val context: CoroutineContext get() = EmptyCoroutineContext
|
||||||
}
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
|
value.getOrThrow()
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
throw exception
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
|
|
||||||
inline fun inlineMe(crossinline c: suspend () -> Int): suspend () -> Int {
|
inline fun inlineMe(crossinline c: suspend () -> Int): suspend () -> Int {
|
||||||
val i: suspend () -> Int = { c() + c() }
|
val i: suspend () -> Int = { c() + c() }
|
||||||
return i
|
return i
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
|
|
||||||
inline suspend fun inlineMe() = 1000
|
inline suspend fun inlineMe() = 1000
|
||||||
|
|
||||||
// inlineMe$$forInline : valueOf
|
// inlineMe$$forInline : valueOf
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
|
|
||||||
suspend fun produce(): Int = 1000
|
suspend fun produce(): Int = 1000
|
||||||
|
|
||||||
// 0 valueOf
|
// 0 valueOf
|
||||||
|
|||||||
@@ -32,17 +32,3 @@ class ResultContinuation : Continuation<Any?> {
|
|||||||
|
|
||||||
var result: Any? = null
|
var result: Any? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ContinuationAdapter<in T> : Continuation<T> {
|
|
||||||
override val context: CoroutineContext = EmptyCoroutineContext
|
|
||||||
override fun resumeWith(result: Result<T>) {
|
|
||||||
if (result.isSuccess) {
|
|
||||||
resume(result.getOrThrow())
|
|
||||||
} else {
|
|
||||||
resumeWithException(result.exceptionOrNull()!!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract fun resumeWithException(exception: Throwable)
|
|
||||||
abstract fun resume(value: T)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,19 +3,17 @@ package helpers
|
|||||||
import kotlin.coroutines.*
|
import kotlin.coroutines.*
|
||||||
import kotlin.coroutines.intrinsics.*
|
import kotlin.coroutines.intrinsics.*
|
||||||
|
|
||||||
|
|
||||||
val StateMachineChecker = StateMachineCheckerClass()
|
val StateMachineChecker = StateMachineCheckerClass()
|
||||||
|
|
||||||
object CheckStateMachineContinuation: ContinuationAdapter<Unit>() {
|
object CheckStateMachineContinuation: Continuation<Unit> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = EmptyCoroutineContext
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
|
value.getOrThrow()
|
||||||
StateMachineChecker.proceed = {
|
StateMachineChecker.proceed = {
|
||||||
StateMachineChecker.finished = true
|
StateMachineChecker.finished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
throw exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-1
@@ -1,6 +1,5 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !CHECK_TYPE
|
// !CHECK_TYPE
|
||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
import kotlin.reflect.KSuspendFunction0
|
import kotlin.reflect.KSuspendFunction0
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||||
|
|
||||||
suspend fun foo() {}
|
suspend fun foo() {}
|
||||||
|
|||||||
Vendored
-1
@@ -1,5 +1,4 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
fun <R> suspend(block: suspend () -> R): suspend () -> R = block
|
fun <R> suspend(block: suspend () -> R): suspend () -> R = block
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
fun <R> suspend(block: R) = block
|
fun <R> suspend(block: R) = block
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
fun bar() {
|
fun bar() {
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
import kotlin.suspend as suspendLambda
|
import kotlin.suspend as suspendLambda
|
||||||
|
|||||||
Vendored
-1
@@ -1,4 +1,3 @@
|
|||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
import kotlin.suspend as suspendLambda
|
import kotlin.suspend as suspendLambda
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !LANGUAGE: +ReleaseCoroutines
|
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
suspend fun test() {
|
suspend fun test() {
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
// !LANGUAGE: +ReleaseCoroutines +ExperimentalBuilderInference
|
// !LANGUAGE: +ExperimentalBuilderInference
|
||||||
// !OPT_IN: kotlin.RequiresOptIn
|
// !OPT_IN: kotlin.RequiresOptIn
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
|
|||||||
@@ -23,20 +23,6 @@ fun createTextForCoroutineHelpers(checkStateMachine: Boolean, checkTailCallOptim
|
|||||||
|}
|
|}
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
|
|
||||||
val continuationAdapterBody =
|
|
||||||
"""
|
|
||||||
|override fun resumeWith(result: Result<T>) {
|
|
||||||
| if (result.isSuccess) {
|
|
||||||
| resume(result.getOrThrow())
|
|
||||||
| } else {
|
|
||||||
| resumeWithException(result.exceptionOrNull()!!)
|
|
||||||
| }
|
|
||||||
|}
|
|
||||||
|
|
|
||||||
|abstract fun resumeWithException(exception: Throwable)
|
|
||||||
|abstract fun resume(value: T)
|
|
||||||
""".trimMargin()
|
|
||||||
|
|
||||||
val checkStateMachineString = """
|
val checkStateMachineString = """
|
||||||
class StateMachineCheckerClass {
|
class StateMachineCheckerClass {
|
||||||
private var counter = 0
|
private var counter = 0
|
||||||
@@ -68,19 +54,16 @@ fun createTextForCoroutineHelpers(checkStateMachine: Boolean, checkTailCallOptim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val StateMachineChecker = StateMachineCheckerClass()
|
val StateMachineChecker = StateMachineCheckerClass()
|
||||||
object CheckStateMachineContinuation: ContinuationAdapter<Unit>() {
|
object CheckStateMachineContinuation: Continuation<Unit> {
|
||||||
override val context: CoroutineContext
|
override val context: CoroutineContext
|
||||||
get() = EmptyCoroutineContext
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(value: Unit) {
|
override fun resumeWith(value: Result<Unit>) {
|
||||||
|
value.getOrThrow()
|
||||||
StateMachineChecker.proceed = {
|
StateMachineChecker.proceed = {
|
||||||
StateMachineChecker.finished = true
|
StateMachineChecker.finished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
|
||||||
throw exception
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
@@ -146,11 +129,6 @@ fun createTextForCoroutineHelpers(checkStateMachine: Boolean, checkTailCallOptim
|
|||||||
| var result: Any? = null
|
| var result: Any? = null
|
||||||
|}
|
|}
|
||||||
|
|
|
|
||||||
|abstract class ContinuationAdapter<in T> : Continuation<T> {
|
|
||||||
| override val context: CoroutineContext = EmptyCoroutineContext
|
|
||||||
| $continuationAdapterBody
|
|
||||||
|}
|
|
||||||
|
|
|
||||||
|${if (checkStateMachine) checkStateMachineString else ""}
|
|${if (checkStateMachine) checkStateMachineString else ""}
|
||||||
|${if (checkTailCallOptimization) checkTailCallOptimizationString else ""}
|
|${if (checkTailCallOptimization) checkTailCallOptimizationString else ""}
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
|
|||||||
Reference in New Issue
Block a user