Support new suspend convention in frontend

#KT-14924 In Progress
This commit is contained in:
Denis Zharkov
2016-11-24 15:18:44 +03:00
parent e4a383f3e2
commit a34c9c2580
26 changed files with 168 additions and 356 deletions
@@ -1,13 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
class Controller {
suspend fun suspendHere(a: String, x: Continuation<Int>) {
}
suspend fun suspendHere(a: String) = 1
}
class A {
suspend fun suspendHere(a: Int, x: Continuation<Int>) {
}
suspend fun suspendHere(a: Int) = 1
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {}
@@ -18,9 +16,8 @@ fun test() {
with(A()) {
suspendHere("")
// This test checks that suspending functions
// that are not from coroutine controller can't be called by suspending convention
suspendHere(1<!NO_VALUE_FOR_PARAMETER!>)<!>
// With the new convention calling a suspension member with receiver different from the one obtained from the coroutine is OK
suspendHere(1)
}
}
}
@@ -7,7 +7,7 @@ public final class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final suspend fun suspendHere(/*0*/ a: kotlin.Int, /*1*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun suspendHere(/*0*/ a: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -15,6 +15,6 @@ public final class Controller {
public constructor Controller()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final suspend fun suspendHere(/*0*/ a: kotlin.String, /*1*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun suspendHere(/*0*/ a: kotlin.String): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,11 +1,9 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Controller<T> {
suspend fun suspendHere(x: Continuation<Int>) {
}
suspend fun suspendHere() = 1
suspend fun another(a: T, x: Continuation<Int>) {
}
suspend fun another(a: T) = 1
}
fun <T> builder(coroutine c: Controller<T>.() -> Continuation<Unit>) { }
@@ -62,7 +60,7 @@ fun foo() {
suspendHere()
another(1)
<!NON_LOCAL_SUSPENSION_POINT!>another<!>("")
another("")
}
}
}
@@ -8,9 +8,9 @@ public inline fun runCross(/*0*/ crossinline x: () -> kotlin.Unit): kotlin.Unit
public final class Controller</*0*/ T> {
public constructor Controller</*0*/ T>()
public final suspend fun another(/*0*/ a: T, /*1*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun another(/*0*/ a: T): kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final suspend fun suspendHere(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun suspendHere(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,44 +1,25 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -NOTHING_TO_INLINE
<!INAPPLICABLE_MODIFIER!>suspend<!> fun notMember(x: Continuation<Int>) {
suspend fun notMember(q: Double) = 1
}
suspend fun String.wrongExtension(x: Any) = 1
<!INAPPLICABLE_MODIFIER!>suspend<!> fun String.wrongExtension(x: Continuation<Int>) {
}
suspend fun Controller.controllerReceiver() = 1
suspend fun Controller.correctExtension(x: Continuation<Int>) {
}
@AllowSuspendExtensions
class Controller {
suspend fun valid(x: Continuation<Int>) {
// is still valid
suspend fun oldConvention(x: Continuation<Int>) {
}
inline suspend fun inlineFun(x: Continuation<Int>) {
suspend fun noParameters() {
}
<!INAPPLICABLE_MODIFIER!>suspend<!> fun noParams() {
suspend fun oneParameter(q: Any) {}
suspend fun varargParameter(vararg q: Any) {}
suspend fun returnsString(q: Any) = ""
}
inline suspend fun inlineFun(x: Int) {}
<!INAPPLICABLE_MODIFIER!>suspend<!> fun wrongParam(x: Collection<Int>) {
}
<!INAPPLICABLE_MODIFIER!>suspend<!> fun starProjection(x: Continuation<*>) {
}
<!INAPPLICABLE_MODIFIER!>suspend<!> fun varargs(vararg x: Continuation<Any>) {
}
suspend fun String.memberExtension(x: Continuation<Int>) {
}
suspend fun returnsUnit(x: Continuation<Int>) = Unit
<!INAPPLICABLE_MODIFIER!>suspend<!> fun returnsNotUnit(x: Continuation<Int>) = 1
suspend fun String.memberExtension() = 1
}
@@ -1,21 +1,19 @@
package
public suspend fun notMember(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public suspend fun Controller.correctExtension(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public suspend fun kotlin.String.wrongExtension(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public suspend fun notMember(/*0*/ q: kotlin.Double): kotlin.Int
public suspend fun Controller.controllerReceiver(): kotlin.Int
public suspend fun kotlin.String.wrongExtension(/*0*/ x: kotlin.Any): kotlin.Int
@kotlin.coroutines.AllowSuspendExtensions public final class Controller {
public final class Controller {
public constructor Controller()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final inline suspend fun inlineFun(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun noParams(): kotlin.Unit
public final suspend fun returnsNotUnit(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Int
public final suspend fun returnsUnit(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun starProjection(/*0*/ x: kotlin.coroutines.Continuation<*>): kotlin.Unit
public final inline suspend fun inlineFun(/*0*/ x: kotlin.Int): kotlin.Unit
public final suspend fun noParameters(): kotlin.Unit
public final suspend fun oldConvention(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun oneParameter(/*0*/ q: kotlin.Any): kotlin.Unit
public final suspend fun returnsString(/*0*/ q: kotlin.Any): kotlin.String
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final suspend fun valid(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun varargs(/*0*/ vararg x: kotlin.coroutines.Continuation<kotlin.Any> /*kotlin.Array<out kotlin.coroutines.Continuation<kotlin.Any>>*/): kotlin.Unit
public final suspend fun wrongParam(/*0*/ x: kotlin.collections.Collection<kotlin.Int>): kotlin.Unit
public final suspend fun kotlin.String.memberExtension(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
public final suspend fun varargParameter(/*0*/ vararg q: kotlin.Any /*kotlin.Array<out kotlin.Any>*/): kotlin.Unit
public final suspend fun kotlin.String.memberExtension(): kotlin.Int
}
@@ -1,60 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
@AllowSuspendExtensions
class Controller
suspend fun Controller.noParams(c: Continuation<Unit>) {
}
suspend fun Controller.yieldString(value: String, c: Continuation<Unit>) {
}
suspend fun <V> Controller.await(f: () -> V, machine: Continuation<V>) {
}
suspend fun <V> Controller.await(f: Int, machine: Continuation<V>) {
}
suspend fun Controller.severalParams(x: String, y: Int, machine: Continuation<Double>) {
}
// These two must be prohibited because String and Any are not properly annotated
<!INAPPLICABLE_MODIFIER!>suspend<!> fun String.wrongReceiver(y: Int, machine: Continuation<Double>) {
}
<!INAPPLICABLE_MODIFIER!>suspend<!> fun Any.anyReceiver(y: Int, machine: Continuation<Double>) {
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {}
fun test() {
builder {
noParams()
yieldString("abc") checkType { _<Unit>() }
yieldString(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>) checkType { _<Unit>() }
await<String> { "123" } checkType { _<String>() }
// Inference from lambda return type
await { 123 } checkType { _<Int>() }
// Inference from expected type
checkSubtype<String>(await(567))
await<Double>(123) checkType { _<Double>() }
severalParams("", 89) checkType { _<Double>() }
// TODO: prohibit such calls
severalParams("", 89, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>6.9<!>) checkType { _<Unit>() }
severalParams("", 89, this <!CAST_NEVER_SUCCEEDS!>as<!> Continuation<Double>) checkType { _<Unit>() }
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>wrongReceiver<!>(1)
with("") {
wrongReceiver(2<!NO_VALUE_FOR_PARAMETER!>)<!>
}
// Though such calls are allowed declarations with not-annotated receiver should be prohibited
anyReceiver(3)
}
}
@@ -1,18 +0,0 @@
package
public fun builder(/*0*/ coroutine c: Controller.() -> kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
public fun test(): kotlin.Unit
public suspend fun kotlin.Any.anyReceiver(/*0*/ y: kotlin.Int, /*1*/ machine: kotlin.coroutines.Continuation<kotlin.Double>): kotlin.Unit
public suspend fun </*0*/ V> Controller.await(/*0*/ f: () -> V, /*1*/ machine: kotlin.coroutines.Continuation<V>): kotlin.Unit
public suspend fun </*0*/ V> Controller.await(/*0*/ f: kotlin.Int, /*1*/ machine: kotlin.coroutines.Continuation<V>): kotlin.Unit
public suspend fun Controller.noParams(/*0*/ c: kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
public suspend fun Controller.severalParams(/*0*/ x: kotlin.String, /*1*/ y: kotlin.Int, /*2*/ machine: kotlin.coroutines.Continuation<kotlin.Double>): kotlin.Unit
public suspend fun kotlin.String.wrongReceiver(/*0*/ y: kotlin.Int, /*1*/ machine: kotlin.coroutines.Continuation<kotlin.Double>): kotlin.Unit
public suspend fun Controller.yieldString(/*0*/ value: kotlin.String, /*1*/ c: kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
@kotlin.coroutines.AllowSuspendExtensions public final class Controller {
public constructor Controller()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,53 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
class Controller
suspend fun noParams() {
}
suspend fun yieldString(value: String) {}
suspend fun <V> await(f: () -> V) = f()
suspend fun <V> Controller.await(f: Int): V = null!!
suspend fun Controller.severalParams(x: String, y: Int) = 1.0
suspend fun String.stringReceiver(y: Int) = 1.0
suspend fun Any.anyReceiver(y: Int) = 1.0
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {}
fun test() {
builder {
noParams()
yieldString("abc") checkType { _<Unit>() }
yieldString(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>) checkType { _<Unit>() }
await<String> { "123" } checkType { _<String>() }
// Inference from lambda return type
await { 123 } checkType { _<Int>() }
// Inference from expected type
checkSubtype<String>(await(567))
await<Double>(123) checkType { _<Double>() }
severalParams("", 89) checkType { _<Double>() }
// TODO: should we allow somehow to call with passing continuation explicitly?
severalParams("", 89, <!TOO_MANY_ARGUMENTS!>6.9<!>) checkType { <!TYPE_MISMATCH!>_<!><Unit>() }
severalParams("", 89, <!TOO_MANY_ARGUMENTS!>this <!CAST_NEVER_SUCCEEDS!>as<!> Continuation<Double><!>) checkType { <!TYPE_MISMATCH!>_<!><Unit>() }
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>stringReceiver<!>(1)
with("") {
stringReceiver(2)
}
// Though such calls are allowed declarations with not-annotated receiver should be prohibited
anyReceiver(3)
}
}
@@ -0,0 +1,18 @@
package
public suspend fun </*0*/ V> await(/*0*/ f: () -> V): V
public fun builder(/*0*/ coroutine c: Controller.() -> kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
public suspend fun noParams(): kotlin.Unit
public fun test(): kotlin.Unit
public suspend fun yieldString(/*0*/ value: kotlin.String): kotlin.Unit
public suspend fun kotlin.Any.anyReceiver(/*0*/ y: kotlin.Int): kotlin.Double
public suspend fun </*0*/ V> Controller.await(/*0*/ f: kotlin.Int): V
public suspend fun Controller.severalParams(/*0*/ x: kotlin.String, /*1*/ y: kotlin.Int): kotlin.Double
public suspend fun kotlin.String.stringReceiver(/*0*/ y: kotlin.Int): kotlin.Double
public final class Controller {
public constructor Controller()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,20 +1,16 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
class Controller {
suspend fun noParams(c: Continuation<Unit>) {
suspend fun noParams() {
}
suspend fun yieldString(value: String, c: Continuation<Unit>) {
}
suspend fun yieldString(value: String) {}
suspend fun <V> await(f: () -> V, machine: Continuation<V>) {
}
suspend fun <V> await(f: () -> V): V = f()
suspend fun <V> await(f: Int, machine: Continuation<V>) {
}
suspend fun <V> await(f: Int): V = null!!
suspend fun severalParams(x: String, y: Int, machine: Continuation<Double>) {
}
suspend fun severalParams(x: String, y: Int) = 1.0
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {}
@@ -36,8 +32,9 @@ fun test() {
await<Double>(123) checkType { _<Double>() }
severalParams("", 89) checkType { _<Double>() }
// TODO: prohibit such calls
severalParams("", 89, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>6.9<!>) checkType { _<Unit>() }
severalParams("", 89, this <!CAST_NEVER_SUCCEEDS!>as<!> Continuation<Double>) checkType { _<Unit>() }
// TODO: should we allow somehow to call with passing continuation explicitly?
severalParams("", 89, <!TOO_MANY_ARGUMENTS!>6.9<!>) checkType { <!TYPE_MISMATCH!>_<!><Unit>() }
severalParams("", 89, <!TOO_MANY_ARGUMENTS!>this <!CAST_NEVER_SUCCEEDS!>as<!> Continuation<Double><!>) checkType { <!TYPE_MISMATCH!>_<!><Unit>() }
}
}
@@ -5,12 +5,12 @@ public fun test(): kotlin.Unit
public final class Controller {
public constructor Controller()
public final suspend fun </*0*/ V> await(/*0*/ f: () -> V, /*1*/ machine: kotlin.coroutines.Continuation<V>): kotlin.Unit
public final suspend fun </*0*/ V> await(/*0*/ f: kotlin.Int, /*1*/ machine: kotlin.coroutines.Continuation<V>): kotlin.Unit
public final suspend fun </*0*/ V> await(/*0*/ f: () -> V): V
public final suspend fun </*0*/ V> await(/*0*/ f: kotlin.Int): V
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final suspend fun noParams(/*0*/ c: kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
public final suspend fun severalParams(/*0*/ x: kotlin.String, /*1*/ y: kotlin.Int, /*2*/ machine: kotlin.coroutines.Continuation<kotlin.Double>): kotlin.Unit
public final suspend fun noParams(): kotlin.Unit
public final suspend fun severalParams(/*0*/ x: kotlin.String, /*1*/ y: kotlin.Int): kotlin.Double
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final suspend fun yieldString(/*0*/ value: kotlin.String, /*1*/ c: kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
public final suspend fun yieldString(/*0*/ value: kotlin.String): kotlin.Unit
}
@@ -1,7 +1,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_VARIABLE
class GenericController<T> {
operator fun handleResult(x: T, c: Continuation<Nothing>) { }
suspend fun <V> await(f: V, machine: Continuation<V>) {}
suspend fun <V> await(f: V): V = f
}
fun <T> genericBuilder(coroutine c: GenericController<T>.() -> Continuation<Unit>): T = null!!
@@ -5,7 +5,7 @@ public fun </*0*/ T> genericBuilder(/*0*/ coroutine c: GenericController<T>.() -
public final class GenericController</*0*/ T> {
public constructor GenericController</*0*/ T>()
public final suspend fun </*0*/ V> await(/*0*/ f: V, /*1*/ machine: kotlin.coroutines.Continuation<V>): kotlin.Unit
public final suspend fun </*0*/ V> await(/*0*/ f: V): V
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun handleResult(/*0*/ x: T, /*1*/ c: kotlin.coroutines.Continuation<kotlin.Nothing>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
@@ -2,9 +2,7 @@
// !LANGUAGE: -Coroutines
class Controller {
<!UNSUPPORTED_FEATURE!>suspend<!> fun suspendHere(x: Continuation<String>) {
x.resume("OK")
}
<!UNSUPPORTED_FEATURE!>suspend<!> fun suspendHere(): String = "OK"
<!UNSUPPORTED_FEATURE!>operator<!> fun handleResult(x: String, y: Continuation<Nothing>) {}
@@ -10,6 +10,6 @@ public final class Controller {
public final operator fun handleResult(/*0*/ x: kotlin.String, /*1*/ y: kotlin.coroutines.Continuation<kotlin.Nothing>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun interceptResume(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
public final suspend fun suspendHere(/*0*/ x: kotlin.coroutines.Continuation<kotlin.String>): kotlin.Unit
public final suspend fun suspendHere(): kotlin.String
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}