Get rid of unnecessary additional declarations in tests
This commit is contained in:
@@ -34,7 +34,7 @@ class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuati
|
|||||||
var computesNext = false
|
var computesNext = false
|
||||||
var computeContinuation: Continuation<*>? = null
|
var computeContinuation: Continuation<*>? = null
|
||||||
|
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
suspend fun computeHasNext(): Boolean = suspendCoroutineOrReturn { c ->
|
suspend fun computeHasNext(): Boolean = suspendCoroutineOrReturn { c ->
|
||||||
computesNext = false
|
computesNext = false
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ fun builder(c: suspend () -> Unit) {
|
|||||||
var exception: Throwable? = null
|
var exception: Throwable? = null
|
||||||
|
|
||||||
c.createCoroutine(object : Continuation<Unit> {
|
c.createCoroutine(object : Continuation<Unit> {
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Unit) {
|
override fun resume(data: Unit) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ 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 : Continuation<Unit> {
|
c.startCoroutine(controller, object : Continuation<Unit> {
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Unit) {
|
override fun resume(data: Unit) {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ 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 : Continuation<Unit> {
|
c.startCoroutine(controller, object : Continuation<Unit> {
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Unit) {}
|
override fun resume(data: Unit) {}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,34 @@ class Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class ContinuationDispatcher : ContinuationInterceptor {
|
||||||
|
override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor
|
||||||
|
abstract fun <T> dispatchResume(value: 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 operator fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? = if (this.contextKey == key) this as E else null
|
||||||
|
override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = operation(initial, this)
|
||||||
|
override operator fun plus(context: CoroutineContext): CoroutineContext = this
|
||||||
|
override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = if (this.contextKey == key) EmptyCoroutineContext else this
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DispatchedContinuation<T>(
|
||||||
|
val dispatcher: ContinuationDispatcher,
|
||||||
|
val continuation: Continuation<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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun test(c: suspend Controller.() -> Unit): String {
|
fun test(c: suspend Controller.() -> Unit): String {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c.startCoroutine(controller, EmptyContinuation(object: ContinuationDispatcher() {
|
c.startCoroutine(controller, EmptyContinuation(object: ContinuationDispatcher() {
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ 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 : Continuation<Unit> {
|
private var nextStep: Continuation<Unit> = block.createCoroutine(this, object : Continuation<Unit> {
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Unit) {
|
override fun resume(data: Unit) {
|
||||||
done()
|
done()
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ var result = ""
|
|||||||
|
|
||||||
fun builder(c: suspend () -> Unit) {
|
fun builder(c: suspend () -> Unit) {
|
||||||
c.startCoroutine(object : Continuation<Unit> {
|
c.startCoroutine(object : Continuation<Unit> {
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
override fun resume(value: Unit) {
|
override fun resume(value: Unit) {
|
||||||
}
|
}
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWithException(exception: Throwable) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ fun builder(c: suspend () -> Int): Int {
|
|||||||
var res = 0
|
var res = 0
|
||||||
|
|
||||||
c.createCoroutine(object : Continuation<Int> {
|
c.createCoroutine(object : Continuation<Int> {
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(data: Int) {
|
override fun resume(data: Int) {
|
||||||
res = data
|
res = data
|
||||||
|
|||||||
+28
@@ -21,6 +21,34 @@ class Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class ContinuationDispatcher : ContinuationInterceptor {
|
||||||
|
override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor
|
||||||
|
abstract fun <T> dispatchResume(value: 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 operator fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? = if (this.contextKey == key) this as E else null
|
||||||
|
override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = operation(initial, this)
|
||||||
|
override operator fun plus(context: CoroutineContext): CoroutineContext = this
|
||||||
|
override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = if (this.contextKey == key) EmptyCoroutineContext else this
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DispatchedContinuation<T>(
|
||||||
|
val dispatcher: ContinuationDispatcher,
|
||||||
|
val continuation: Continuation<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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun test(c: suspend Controller.() -> Unit): String {
|
fun test(c: suspend Controller.() -> Unit): String {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c.startCoroutine(controller, EmptyContinuation(object: ContinuationDispatcher() {
|
c.startCoroutine(controller, EmptyContinuation(object: ContinuationDispatcher() {
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
|
|||||||
fun builder(c: suspend () -> Unit) {
|
fun builder(c: suspend () -> Unit) {
|
||||||
var wasResumeCalled = false
|
var wasResumeCalled = false
|
||||||
c.startCoroutine(object : Continuation<Unit> {
|
c.startCoroutine(object : Continuation<Unit> {
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(value: Unit) {
|
override fun resume(value: Unit) {
|
||||||
wasResumeCalled = true
|
wasResumeCalled = true
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
|
|||||||
fun builder(c: suspend () -> Unit) {
|
fun builder(c: suspend () -> Unit) {
|
||||||
var wasResumeCalled = false
|
var wasResumeCalled = false
|
||||||
c.startCoroutine(object : Continuation<Unit> {
|
c.startCoroutine(object : Continuation<Unit> {
|
||||||
override val context = EmptyContext
|
override val context = EmptyCoroutineContext
|
||||||
|
|
||||||
override fun resume(value: Unit) {
|
override fun resume(value: Unit) {
|
||||||
wasResumeCalled = true
|
wasResumeCalled = true
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// FILE: A.kt
|
// FILE: A.kt
|
||||||
|
// WITH_RUNTIME
|
||||||
package a
|
package a
|
||||||
|
|
||||||
import kotlin.coroutines.*
|
import kotlin.coroutines.*
|
||||||
@@ -13,6 +14,7 @@ class Controller {
|
|||||||
|
|
||||||
fun builder(c: suspend Controller.() -> Unit) {
|
fun builder(c: suspend Controller.() -> Unit) {
|
||||||
c.startCoroutine(Controller(), object : Continuation<Unit> {
|
c.startCoroutine(Controller(), object : Continuation<Unit> {
|
||||||
|
override val context: CoroutineContext = EmptyCoroutineContext
|
||||||
override fun resume(value: Unit) {}
|
override fun resume(value: Unit) {}
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {}
|
override fun resumeWithException(exception: Throwable) {}
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ public class KotlinTestUtils {
|
|||||||
"CoroutineUtil.kt",
|
"CoroutineUtil.kt",
|
||||||
"import kotlin.coroutines.*\n" +
|
"import kotlin.coroutines.*\n" +
|
||||||
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
|
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
|
||||||
" override val context = EmptyContext\n" +
|
" override val context = EmptyCoroutineContext\n" +
|
||||||
" override fun resumeWithException(exception: Throwable) {\n" +
|
" override fun resumeWithException(exception: Throwable) {\n" +
|
||||||
" throw exception\n" +
|
" throw exception\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
@@ -658,7 +658,7 @@ public class KotlinTestUtils {
|
|||||||
"}\n" +
|
"}\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {\n" +
|
"fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {\n" +
|
||||||
" override val context = EmptyContext\n" +
|
" override val context = EmptyCoroutineContext\n" +
|
||||||
" override fun resumeWithException(exception: Throwable) {\n" +
|
" override fun resumeWithException(exception: Throwable) {\n" +
|
||||||
" x(exception)\n" +
|
" x(exception)\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
@@ -666,45 +666,10 @@ public class KotlinTestUtils {
|
|||||||
" override fun resume(data: Any?) { }\n" +
|
" override fun resume(data: Any?) { }\n" +
|
||||||
"}\n" +
|
"}\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"object EmptyContext : CoroutineContext {\n" +
|
"open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {\n" +
|
||||||
" override fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? = null\n" +
|
|
||||||
" override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = initial\n" +
|
|
||||||
" override fun plus(context: CoroutineContext): CoroutineContext = context\n" +
|
|
||||||
" override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = this\n" +
|
|
||||||
"}\n" +
|
|
||||||
"\n" +
|
|
||||||
"open class EmptyContinuation(override val context: CoroutineContext = EmptyContext) : Continuation<Any?> {\n" +
|
|
||||||
" companion object : EmptyContinuation()\n" +
|
" companion object : EmptyContinuation()\n" +
|
||||||
" override fun resume(data: Any?) {}\n" +
|
" override fun resume(data: Any?) {}\n" +
|
||||||
" override fun resumeWithException(exception: Throwable) { throw exception }\n" +
|
" override fun resumeWithException(exception: Throwable) { throw exception }\n" +
|
||||||
"}\n" +
|
|
||||||
"\n" +
|
|
||||||
"abstract class ContinuationDispatcher : ContinuationInterceptor {\n" +
|
|
||||||
" override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor\n" +
|
|
||||||
" abstract fun <T> dispatchResume(value: T, continuation: Continuation<T>): Boolean\n" +
|
|
||||||
" abstract fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean\n" +
|
|
||||||
" override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = DispatchedContinuation(this, continuation)\n" +
|
|
||||||
" override operator fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? = if (this.contextKey == key) this as E else null\n" +
|
|
||||||
" override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = operation(initial, this)\n" +
|
|
||||||
" override operator fun plus(context: CoroutineContext): CoroutineContext = this\n" +
|
|
||||||
" override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = if (this.contextKey == key) EmptyContext else this\n" +
|
|
||||||
"}\n" +
|
|
||||||
"\n" +
|
|
||||||
"private class DispatchedContinuation<T>(\n" +
|
|
||||||
" val dispatcher: ContinuationDispatcher,\n" +
|
|
||||||
" val continuation: Continuation<T>\n" +
|
|
||||||
"): Continuation<T> {\n" +
|
|
||||||
" override val context: CoroutineContext = continuation.context\n" +
|
|
||||||
"\n" +
|
|
||||||
" override fun resume(value: T) {\n" +
|
|
||||||
" if (!dispatcher.dispatchResume(value, continuation))\n" +
|
|
||||||
" continuation.resume(value)\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n" +
|
|
||||||
" override fun resumeWithException(exception: Throwable) {\n" +
|
|
||||||
" if (!dispatcher.dispatchResumeWithException(exception, continuation))\n" +
|
|
||||||
" continuation.resumeWithException(exception)\n" +
|
|
||||||
" }\n" +
|
|
||||||
"}",
|
"}",
|
||||||
directives
|
directives
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user