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