Support new suspend convention in JVM backend partially

Stack-unwinding does not work yet

 #KT-14924 In Progress
This commit is contained in:
Denis Zharkov
2016-11-24 18:43:01 +03:00
parent 2c3b0aeddb
commit 1f98accad2
98 changed files with 366 additions and 190 deletions
@@ -6,7 +6,7 @@ class Controller {
exception = t
}
suspend fun suspendHere(x: Continuation<Any>) {}
suspend fun suspendHere(): Any = suspendWithCurrentContinuation { x ->}
// INTERCEPT_RESUME_PLACEHOLDER
}
@@ -1,6 +1,6 @@
// WITH_RUNTIME
class Controller {
suspend fun suspendHere(x: Continuation<Any>) {}
suspend fun suspendHere(): Any = suspendWithCurrentContinuation { x ->}
// INTERCEPT_RESUME_PLACEHOLDER
}
+1 -1
View File
@@ -4,7 +4,7 @@ class Controller {
result = "OK"
}
suspend fun <T> await(t: T, c: Continuation<T>) {
suspend fun <T> await(t: T): T = suspendWithCurrentContinuation { c ->
c.resume(t)
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
suspend fun <T> suspendWithResult(value: T): T = suspendWithCurrentContinuation { c ->
c.resume(value)
}
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
suspend fun <T> suspendWithResult(value: T): T = suspendWithCurrentContinuation { c ->
c.resume(value)
}
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
suspend fun <T> suspendWithResult(value: T): T = suspendWithCurrentContinuation { c ->
c.resume(value)
}
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
suspend fun <T> suspendWithResult(value: T): T = suspendWithCurrentContinuation { c ->
c.resume(value)
}
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
suspend fun <T> suspendWithResult(value: T): T = suspendWithCurrentContinuation { c ->
c.resume(value)
}
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
suspend fun <T> suspendWithResult(value: T): T = suspendWithCurrentContinuation { c ->
c.resume(value)
}
}
@@ -8,7 +8,7 @@
class Controller {
var result = ""
suspend fun <T> suspendAndLog(value: T, c: Continuation<T>) {
suspend fun <T> suspendAndLog(value: T): T = suspendWithCurrentContinuation { c ->
result += "suspend($value);"
c.resume(value)
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
suspend fun <T> suspendWithResult(value: T): T = suspendWithCurrentContinuation { c ->
result += "["
c.resume(value)
}
@@ -4,12 +4,12 @@
class Controller {
var result = ""
suspend fun <T> suspendAndLog(value: T, c: Continuation<T>) {
suspend fun <T> suspendAndLog(value: T): T = suspendWithCurrentContinuation { c ->
result += "suspend($value);"
c.resume(value)
}
suspend fun suspendLogAndThrow(exception: Throwable, c: Continuation<Nothing>) {
suspend fun suspendLogAndThrow(exception: Throwable): Nothing = suspendWithCurrentContinuation { c ->
result += "throw(${exception.message});"
c.resumeWithException(exception)
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendAndLog(value: T, c: Continuation<T>) {
suspend fun <T> suspendAndLog(value: T): T = suspendWithCurrentContinuation { c ->
result += "suspend($value);"
c.resume(value)
}
@@ -35,4 +35,4 @@ fun box(): String {
}
return "OK"
}
}
@@ -4,7 +4,7 @@
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T, c: Continuation<T>) {
suspend fun <T> suspendWithResult(value: T): T = suspendWithCurrentContinuation { c ->
c.resume(value)
}
}
@@ -1,6 +1,6 @@
class Controller {
var result = false
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(a: String = "abc", i: Int = 2, x: Continuation<String>) {
suspend fun suspendHere(a: String = "abc", i: Int = 2): String = suspendWithCurrentContinuation { x ->
x.resume(a + "#" + (i + 1))
}
+1 -1
View File
@@ -1,7 +1,7 @@
var result = 0
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
result++
x.resume("OK")
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun <T> suspendHere(v: T, x: Continuation<T>) {
suspend fun <T> suspendHere(v: T): T = suspendWithCurrentContinuation { x ->
x.resume(v)
}
+1 -1
View File
@@ -43,7 +43,7 @@ class GeneratorController<T>() : AbstractIterator<T>() {
this.nextStep = step
}
suspend fun yield(value: T, c: Continuation<Unit>) {
suspend fun yield(value: T): Unit = suspendWithCurrentContinuation { c ->
setNext(value)
setNextStep(c)
}
@@ -3,13 +3,13 @@ class Controller {
var exception: Throwable? = null
val postponedActions = ArrayList<() -> Unit>()
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
suspend fun suspendWithValue(v: String): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resume(v)
}
}
suspend fun suspendWithException(e: Exception, x: Continuation<String>) {
suspend fun suspendWithException(e: Exception): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resumeWithException(e)
}
@@ -1,6 +1,6 @@
class Controller {
var isCompleted = false
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -1,7 +1,7 @@
class Controller {
var log = ""
suspend fun <T> suspendAndLog(value: T, x: Continuation<T>) {
suspend fun <T> suspendAndLog(value: T): T = suspendWithCurrentContinuation { x ->
log += "suspend($value);"
x.resume(value)
}
+1 -1
View File
@@ -2,7 +2,7 @@
// TARGET_BACKEND: JVM
// NO_INTERCEPT_RESUME_TESTS
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -8,17 +8,13 @@ class Controller {
x.resume(v)
}
suspend inline fun suspendInline(v: String, x: Continuation<String>) {
suspend inline fun suspendInline(v: String): String = suspendWithCurrentContinuation { x ->
withValue(v, x)
}
suspend inline fun suspendInline(crossinline b: () -> String, x: Continuation<String>) {
suspendInline(b(), x)
}
suspend inline fun suspendInline(crossinline b: () -> String): String = suspendInline(b())
suspend inline fun <reified T : Any> suspendInline(x: Continuation<String>) {
suspendInline({ T::class.simpleName!! }, x)
}
suspend inline fun <reified T : Any> suspendInline(): String = suspendInline({ T::class.simpleName!! })
// INTERCEPT_RESUME_PLACEHOLDER
}
@@ -4,13 +4,13 @@ var wasCalled = false
class Controller {
val postponedActions = mutableListOf<() -> Unit>()
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
suspend fun suspendWithValue(v: String): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resume(v)
}
}
suspend fun suspendWithException(e: Exception, x: Continuation<String>) {
suspend fun suspendWithException(e: Exception): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resumeWithException(e)
}
@@ -1,6 +1,6 @@
class Controller {
var i = 0
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume((i++).toString())
}
@@ -2,12 +2,12 @@
// WITH_REFLECT
class Controller {
suspend fun runInstanceOf(x: Continuation<Boolean>) {
suspend fun runInstanceOf(): Boolean = suspendWithCurrentContinuation { x ->
val y: Any = x
x.resume(x is Continuation<*>)
}
suspend fun runCast(x: Continuation<Boolean>) {
suspend fun runCast(): Boolean = suspendWithCurrentContinuation { x ->
val y: Any = x
x.resume(Continuation::class.isInstance(y as Continuation<*>))
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,7 +1,7 @@
// WITH_RUNTIME
// TARGET_BACKEND: JVM
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,7 +1,7 @@
// WITH_RUNTIME
// TARGET_BACKEND: JVM
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
+1 -1
View File
@@ -1,6 +1,6 @@
class Controller {
var result = "fail"
suspend fun <V> suspendHere(v: V, x: Continuation<V>) {
suspend fun <V> suspendHere(v: V): V = suspendWithCurrentContinuation { x ->
x.resume(v)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(v: String, x: Continuation<String>) {
suspend fun suspendHere(v: String): String = suspendWithCurrentContinuation { x ->
x.resume(v)
}
@@ -1,7 +1,7 @@
class Controller {
var result = ""
var ok = false
suspend fun suspendHere(v: String, x: Continuation<Unit>) {
suspend fun suspendHere(v: String): Unit = suspendWithCurrentContinuation { x ->
result += v
x.resume(Unit)
}
@@ -1,6 +1,6 @@
class Controller {
var wasHandleResultCalled = false
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -1,6 +1,6 @@
class Controller {
var wasHandleResultCalled = false
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -1,7 +1,7 @@
class Controller {
var ok = false
var v = "fail"
suspend fun suspendHere(v: String, x: Continuation<Unit>) {
suspend fun suspendHere(v: String): Unit = suspendWithCurrentContinuation { x ->
this.v = v
x.resume(Unit)
}
@@ -1,5 +1,6 @@
// WITH_RUNTIME
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -13,11 +14,11 @@ fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
fun box(): String {
var result = "fail"
val lambda: Controller.() -> Continuation<Unit> = {
val lambda: Controller.() -> Continuation<Unit> = l1@{
object : Continuation<Any?> {
override fun resume(data: Any?) {
if (data == Unit) {
suspendHere(this)
this@l1.javaClass.getMethod("suspendHere", Continuation::class.java).invoke(this@l1, this)
return
}
@@ -3,7 +3,7 @@
package lib
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -4,36 +4,26 @@ package lib
@AllowSuspendExtensions
class Controller {
suspend fun String.suspendHere(x: Continuation<String>) {
suspend fun String.suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume(this)
}
inline suspend fun String.inlineSuspendHere(x: Continuation<String>) {
suspendHere(x)
}
inline suspend fun String.inlineSuspendHere(): String = suspendHere()
// INTERCEPT_RESUME_PLACEHOLDER
}
suspend fun Controller.suspendExtension(v: String, x: Continuation<String>) {
v.suspendHere(x)
}
suspend fun Controller.suspendExtension(v: String): String = v.suspendHere()
inline suspend fun Controller.inlineSuspendExtension(v: String, x: Continuation<String>) {
v.inlineSuspendHere(x)
}
inline suspend fun Controller.inlineSuspendExtension(v: String) = v.inlineSuspendHere()
// MODULE: main(controller)
// FILE: main.kt
import lib.*
suspend fun Controller.localSuspendExtension(v: String, x: Continuation<String>) {
v.suspendHere(x)
}
suspend fun Controller.localSuspendExtension(v: String) = v.suspendHere()
inline suspend fun Controller.localInlineSuspendExtension(v: String, x: Continuation<String>) {
v.inlineSuspendHere(x)
}
inline suspend fun Controller.localInlineSuspendExtension(v: String) = v.inlineSuspendHere()
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
c(Controller()).resume(Unit)
@@ -1,8 +1,9 @@
class Controller {
var lastSuspension: Continuation<String>? = null
var result = "fail"
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
lastSuspension = x
Unit
}
fun hasNext() = lastSuspension != null
@@ -1,8 +1,9 @@
class Controller {
var lastSuspension: Continuation<String>? = null
var result = "fail"
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
lastSuspension = x
Unit
}
fun hasNext() = lastSuspension != null
@@ -1,8 +1,9 @@
class Controller {
var lastSuspension: Continuation<String>? = null
var result = "fail"
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
lastSuspension = x
Unit
}
fun hasNext() = lastSuspension != null
@@ -1,8 +1,9 @@
class Controller {
var lastSuspension: Continuation<String>? = null
var result = "fail"
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
lastSuspension = x
Unit
}
fun hasNext() = lastSuspension != null
+2 -2
View File
@@ -4,13 +4,13 @@ var wasCalled = false
class Controller {
val postponedActions = ArrayList<() -> Unit>()
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
suspend fun suspendWithValue(v: String): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resume(v)
}
}
suspend fun suspendWithException(e: Exception, x: Continuation<String>) {
suspend fun suspendWithException(e: Exception): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resumeWithException(e)
}
@@ -1,6 +1,6 @@
class Controller {
var cResult = 0
suspend fun suspendHere(v: Int, x: Continuation<Int>) {
suspend fun suspendHere(v: Int): Int = suspendWithCurrentContinuation { x ->
x.resume(v * 2)
}
@@ -2,7 +2,7 @@
class Controller {
var cResult = 0
suspend fun suspendHere(v: Int, x: Continuation<Int>) {
suspend fun suspendHere(v: Int): Int = suspendWithCurrentContinuation { x ->
x.resume(v * 2)
}
+1 -1
View File
@@ -1,6 +1,6 @@
class Controller {
var res = 0
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
+1 -1
View File
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resumeWithException(RuntimeException("OK"))
}
@@ -1,6 +1,6 @@
class Controller {
var res = 0
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -1,6 +1,6 @@
var globalResult = ""
class Controller {
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
suspend fun suspendWithValue(v: String): String = suspendWithCurrentContinuation { x ->
x.resume(v)
}
@@ -1,9 +1,7 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspendThere(x)
}
suspend fun suspendHere(): String = suspendThere()
suspend fun suspendThere(x: Continuation<String>) {
suspend fun suspendThere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -1,23 +1,17 @@
@AllowSuspendExtensions
class Controller {
suspend fun String.suspendHere(x: Continuation<String>) {
suspend fun String.suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume(this)
}
inline suspend fun String.inlineSuspendHere(x: Continuation<String>) {
suspendHere(x)
}
inline suspend fun String.inlineSuspendHere(): String = suspendHere()
// INTERCEPT_RESUME_PLACEHOLDER
}
suspend fun Controller.suspendExtension(v: String, x: Continuation<String>) {
v.suspendHere(x)
}
suspend fun Controller.suspendExtension(v: String): String = v.suspendHere()
inline suspend fun Controller.inlineSuspendExtension(v: String, x: Continuation<String>) {
v.inlineSuspendHere(x)
}
inline suspend fun Controller.inlineSuspendExtension(v: String): String = v.inlineSuspendHere()
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
c(Controller()).resume(Unit)
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(v: Int, x: Continuation<Int>) {
suspend fun suspendHere(v: Int): Int = suspendWithCurrentContinuation { x ->
x.resume(v * 2)
}
+2 -2
View File
@@ -1,9 +1,9 @@
class Controller {
var i = 0
suspend fun suspendHere(x: Continuation<Int>) {
suspend fun suspendHere(): Int = suspendWithCurrentContinuation { x ->
x.resume(i++)
}
suspend fun suspendThere(x: Continuation<String>) {
suspend fun suspendThere(): String = suspendWithCurrentContinuation { x ->
x.resume("?")
}
@@ -1,13 +1,13 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("K")
}
suspend fun suspendWithArgument(v: String, x: Continuation<String>) {
suspend fun suspendWithArgument(v: String): String = suspendWithCurrentContinuation { x ->
x.resume(v)
}
suspend fun suspendWithDouble(v: Double, x: Continuation<Double>) {
suspend fun suspendWithDouble(v: Double): Double = suspendWithCurrentContinuation { x ->
x.resume(v)
}
@@ -4,13 +4,13 @@ var wasCalled = false
class Controller {
val postponedActions = ArrayList<() -> Unit>()
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
suspend fun suspendWithValue(v: String): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resume(v)
}
}
suspend fun suspendWithException(e: Exception, x: Continuation<String>) {
suspend fun suspendWithException(e: Exception): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resumeWithException(e)
}
@@ -4,13 +4,13 @@ var wasCalled = false
class Controller {
val postponedActions = ArrayList<() -> Unit>()
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
suspend fun suspendWithValue(v: String): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resume(v)
}
}
suspend fun suspendWithException(e: Exception, x: Continuation<String>) {
suspend fun suspendWithException(e: Exception): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resumeWithException(e)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(v: String, x: Continuation<String>) {
suspend fun suspendHere(v: String): String = suspendWithCurrentContinuation { x ->
x.resume(v)
}
@@ -4,13 +4,13 @@ var wasCalled = false
class Controller {
val postponedActions = mutableListOf<() -> Unit>()
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
suspend fun suspendWithValue(v: String): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resume(v)
}
}
suspend fun suspendWithException(e: Exception, x: Continuation<String>) {
suspend fun suspendWithException(e: Exception): String = suspendWithCurrentContinuation { x ->
postponedActions.add {
x.resumeWithException(e)
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
@@ -10,7 +10,8 @@ inline fun inline() {}
class External { external fun external() }
operator fun Unit.invoke() {}
infix fun Unit.infix(unit: Unit) {}
class Suspend { suspend fun suspend(c: Continuation<Unit>) {} }
// TODO: support or prohibit references to suspend functions
// class Suspend { suspend fun suspend(c: Continuation<Unit>) {} }
val externalGetter = Unit
external get
@@ -44,11 +45,11 @@ fun box(): String {
assertTrue(Unit::infix.isInfix)
assertFalse(Unit::infix.isSuspend)
assertFalse(Suspend::suspend.isInline)
assertFalse(Suspend::suspend.isExternal)
assertFalse(Suspend::suspend.isOperator)
assertFalse(Suspend::suspend.isInfix)
assertTrue(Suspend::suspend.isSuspend)
// assertFalse(Suspend::suspend.isInline)
// assertFalse(Suspend::suspend.isExternal)
// assertFalse(Suspend::suspend.isOperator)
// assertFalse(Suspend::suspend.isInfix)
// assertTrue(Suspend::suspend.isSuspend)
assertTrue(::externalGetter.getter.isExternal)
assertFalse(::externalGetter.getter.isInline)
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere() = suspendWithCurrentContinuation<String> { x ->
x.resume("OK")
}
}
+1 -2
View File
@@ -1,6 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
}
suspend fun suspendHere() = ""
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,6 +1,6 @@
// WITH_RUNTIME
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,6 +1,6 @@
// WITH_RUNTIME
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<Unit>) {
suspend fun suspendHere(): Unit = suspendWithCurrentContinuation { x ->
x.resume(Unit)
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
}
@@ -1,5 +1,5 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
x.resume("OK")
}
}
+1 -1
View File
@@ -53,7 +53,7 @@ class FutureController<T> {
val future = CompletableFuture<T>()
suspend fun <V> await(f: CompletableFuture<V>, machine: Continuation<V>) {
suspend fun <V> await(f: CompletableFuture<V>) = suspendWithCurrentContinuation<V> { machine ->
f.whenComplete { value, throwable ->
if (throwable == null)
machine.resume(value)
+1 -1
View File
@@ -49,7 +49,7 @@ fun <T> async(coroutine c: FutureController<T>.() -> Continuation<Unit>): Comple
class FutureController<T> {
val future = CompletableFuture<T>()
suspend fun <V> await(f: CompletableFuture<V>, machine: Continuation<V>) {
suspend fun <V> await(f: CompletableFuture<V>) = suspendWithCurrentContinuation<V> { machine ->
f.whenComplete { value, throwable ->
if (throwable == null)
machine.resume(value)