From 25739a08ea462c8ef113d25aec278ff912c03dfb Mon Sep 17 00:00:00 2001 From: Roman Elizarov Date: Mon, 16 Jan 2017 10:01:02 +0300 Subject: [PATCH] CoroutineContext Key and Element are now inside CoroutineContext interface itself (just like Map.Entry) ContinuationInterceptor companion object is named Key CoroutineContext.Element property for key is named just key AbstractCoroutineContextElement implements all of CoroutineContext.Element, including key --- .../default/kotlin-coroutines.txt | 42 +++++++++---------- .../codegen/box/coroutines/dispatchResume.kt | 7 +--- .../dispatchResume.kt | 7 +--- .../coroutines/dispatchResume.txt | 6 --- .../dispatchResume.txt | 6 --- .../coroutines/ContinuationInterceptor.kt | 15 +++++-- .../src/kotlin/coroutines/CoroutineContext.kt | 41 +++++++++--------- .../kotlin/coroutines/CoroutineContextImpl.kt | 38 +++++++++-------- .../test/coroutines/CoroutineContextTest.kt | 25 +++++------ .../reference-public-api/kotlin-runtime.txt | 16 +++---- .../reference-public-api/kotlin-stdlib.txt | 13 +++--- 11 files changed, 98 insertions(+), 118 deletions(-) diff --git a/compiler/testData/builtin-classes/default/kotlin-coroutines.txt b/compiler/testData/builtin-classes/default/kotlin-coroutines.txt index 9b78b274125..f985ece0885 100644 --- a/compiler/testData/builtin-classes/default/kotlin-coroutines.txt +++ b/compiler/testData/builtin-classes/default/kotlin-coroutines.txt @@ -7,37 +7,37 @@ package-fragment kotlin.coroutines public abstract fun resumeWithException(/*0*/ exception: kotlin.Throwable): kotlin.Unit } -@kotlin.SinceKotlin(version = "1.1") public interface ContinuationInterceptor : kotlin.coroutines.CoroutineContextElement { - public abstract override /*1*/ /*fake_override*/ val contextKey: kotlin.coroutines.CoroutineContextKey<*> - public abstract override /*1*/ /*fake_override*/ fun (): kotlin.coroutines.CoroutineContextKey<*> - public abstract override /*1*/ /*fake_override*/ fun fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContextElement) -> R): R - public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ key: kotlin.coroutines.CoroutineContextKey): E? +@kotlin.SinceKotlin(version = "1.1") public interface ContinuationInterceptor : kotlin.coroutines.CoroutineContext.Element { + public abstract override /*1*/ /*fake_override*/ val key: kotlin.coroutines.CoroutineContext.Key<*> + public abstract override /*1*/ /*fake_override*/ fun (): kotlin.coroutines.CoroutineContext.Key<*> + public abstract override /*1*/ /*fake_override*/ fun fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContext.Element) -> R): R + public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ key: kotlin.coroutines.CoroutineContext.Key): E? public abstract fun interceptContinuation(/*0*/ continuation: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation - public abstract override /*1*/ /*fake_override*/ fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContextKey<*>): kotlin.coroutines.CoroutineContext + public abstract override /*1*/ /*fake_override*/ fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<*>): kotlin.coroutines.CoroutineContext public abstract override /*1*/ /*fake_override*/ fun plus(/*0*/ context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext - public companion object Companion : kotlin.coroutines.CoroutineContextKey { - /*primary*/ private constructor Companion() + public companion object Key : kotlin.coroutines.CoroutineContext.Key { + /*primary*/ private constructor Key() } } @kotlin.SinceKotlin(version = "1.1") public interface CoroutineContext { - public abstract fun fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContextElement) -> R): R - public abstract operator fun get(/*0*/ key: kotlin.coroutines.CoroutineContextKey): E? - public abstract fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContextKey<*>): kotlin.coroutines.CoroutineContext + public abstract fun fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContext.Element) -> R): R + public abstract operator fun get(/*0*/ key: kotlin.coroutines.CoroutineContext.Key): E? + public abstract fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<*>): kotlin.coroutines.CoroutineContext public abstract operator fun plus(/*0*/ context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext -} -@kotlin.SinceKotlin(version = "1.1") public interface CoroutineContextElement : kotlin.coroutines.CoroutineContext { - public abstract val contextKey: kotlin.coroutines.CoroutineContextKey<*> - public abstract fun (): kotlin.coroutines.CoroutineContextKey<*> - public abstract override /*1*/ /*fake_override*/ fun fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContextElement) -> R): R - public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ key: kotlin.coroutines.CoroutineContextKey): E? - public abstract override /*1*/ /*fake_override*/ fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContextKey<*>): kotlin.coroutines.CoroutineContext - public abstract override /*1*/ /*fake_override*/ fun plus(/*0*/ context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext -} + public interface Element : kotlin.coroutines.CoroutineContext { + public abstract val key: kotlin.coroutines.CoroutineContext.Key<*> + public abstract fun (): kotlin.coroutines.CoroutineContext.Key<*> + public abstract override /*1*/ /*fake_override*/ fun fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContext.Element) -> R): R + public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ key: kotlin.coroutines.CoroutineContext.Key): E? + public abstract override /*1*/ /*fake_override*/ fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<*>): kotlin.coroutines.CoroutineContext + public abstract override /*1*/ /*fake_override*/ fun plus(/*0*/ context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext + } -@kotlin.SinceKotlin(version = "1.1") public interface CoroutineContextKey { + public interface Key { + } } @kotlin.SinceKotlin(version = "1.1") @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS}) @kotlin.annotation.Retention(value = AnnotationRetention.BINARY) public final annotation class RestrictsSuspension : kotlin.Annotation { diff --git a/compiler/testData/codegen/box/coroutines/dispatchResume.kt b/compiler/testData/codegen/box/coroutines/dispatchResume.kt index 9d9a0ee0c9b..5d725d0e05e 100644 --- a/compiler/testData/codegen/box/coroutines/dispatchResume.kt +++ b/compiler/testData/codegen/box/coroutines/dispatchResume.kt @@ -20,15 +20,10 @@ class Controller { } } -abstract class ContinuationDispatcher : ContinuationInterceptor { - override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor +abstract class ContinuationDispatcher : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor { abstract fun dispatchResume(value: T, continuation: Continuation): Boolean abstract fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean override fun interceptContinuation(continuation: Continuation): Continuation = DispatchedContinuation(this, continuation) - override operator fun get(key: CoroutineContextKey): E? = if (this.contextKey == key) this as E else null - override fun 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( diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt index c0aea34e9e3..69b3af8718d 100644 --- a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt @@ -21,15 +21,10 @@ class Controller { } } -abstract class ContinuationDispatcher : ContinuationInterceptor { - override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor +abstract class ContinuationDispatcher : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor { abstract fun dispatchResume(value: T, continuation: Continuation): Boolean abstract fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean override fun interceptContinuation(continuation: Continuation): Continuation = DispatchedContinuation(this, continuation) - override operator fun get(key: CoroutineContextKey): E? = if (this.contextKey == key) this as E else null - override fun 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( diff --git a/compiler/testData/codegen/light-analysis/coroutines/dispatchResume.txt b/compiler/testData/codegen/light-analysis/coroutines/dispatchResume.txt index 04a259693fd..516ec66e27d 100644 --- a/compiler/testData/codegen/light-analysis/coroutines/dispatchResume.txt +++ b/compiler/testData/codegen/light-analysis/coroutines/dispatchResume.txt @@ -1,15 +1,9 @@ @kotlin.Metadata public abstract class ContinuationDispatcher { - private final @org.jetbrains.annotations.NotNull field contextKey: kotlin.coroutines.CoroutineContextKey public method (): void public abstract method dispatchResume(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): boolean public abstract method dispatchResumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): boolean - public method fold(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function2): java.lang.Object - public @org.jetbrains.annotations.Nullable method get(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContextKey): kotlin.coroutines.CoroutineContextElement - public @org.jetbrains.annotations.NotNull method getContextKey(): kotlin.coroutines.CoroutineContextKey public @org.jetbrains.annotations.NotNull method interceptContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation - public @org.jetbrains.annotations.NotNull method minusKey(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContextKey): kotlin.coroutines.CoroutineContext - public @org.jetbrains.annotations.NotNull method plus(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext } @kotlin.Metadata diff --git a/compiler/testData/codegen/light-analysis/coroutines/suspendFunctionAsCoroutine/dispatchResume.txt b/compiler/testData/codegen/light-analysis/coroutines/suspendFunctionAsCoroutine/dispatchResume.txt index 9621892d868..e3893895867 100644 --- a/compiler/testData/codegen/light-analysis/coroutines/suspendFunctionAsCoroutine/dispatchResume.txt +++ b/compiler/testData/codegen/light-analysis/coroutines/suspendFunctionAsCoroutine/dispatchResume.txt @@ -1,15 +1,9 @@ @kotlin.Metadata public abstract class ContinuationDispatcher { - private final @org.jetbrains.annotations.NotNull field contextKey: kotlin.coroutines.CoroutineContextKey public method (): void public abstract method dispatchResume(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): boolean public abstract method dispatchResumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): boolean - public method fold(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function2): java.lang.Object - public @org.jetbrains.annotations.Nullable method get(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContextKey): kotlin.coroutines.CoroutineContextElement - public @org.jetbrains.annotations.NotNull method getContextKey(): kotlin.coroutines.CoroutineContextKey public @org.jetbrains.annotations.NotNull method interceptContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation - public @org.jetbrains.annotations.NotNull method minusKey(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContextKey): kotlin.coroutines.CoroutineContext - public @org.jetbrains.annotations.NotNull method plus(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext } @kotlin.Metadata diff --git a/core/builtins/src/kotlin/coroutines/ContinuationInterceptor.kt b/core/builtins/src/kotlin/coroutines/ContinuationInterceptor.kt index 5c2087e4f50..b2592cde09b 100644 --- a/core/builtins/src/kotlin/coroutines/ContinuationInterceptor.kt +++ b/core/builtins/src/kotlin/coroutines/ContinuationInterceptor.kt @@ -18,17 +18,24 @@ package kotlin.coroutines /** * Marks coroutine context element that intercepts coroutine continuations. + * The coroutines framework uses [ContinuationInterceptor.Key] to retrieve the interceptor and + * intercepts all coroutine continuations with [interceptContinuation] invocations. */ @SinceKotlin("1.1") -public interface ContinuationInterceptor : CoroutineContextElement { +public interface ContinuationInterceptor : CoroutineContext.Element { /** * The key that defines *the* context interceptor. */ - companion object : CoroutineContextKey + companion object Key : CoroutineContext.Key /** - * Intercepts the given [continuation] by wrapping it. Application code should not call this method directly as - * it is invoked by coroutines framework appropriately and the resulting continuations are efficiently cached. + * Returns continuation that wraps the original [continuation], thus intercepting all resumptions. + * This function is invoked by coroutines framework when needed and the resulting continuations are + * cached internally per each instance of the original [continuation]. + * + * By convention, implementations that install themselves as *the* interceptor in the context with + * the [Key] shall also scan the context for other element that implement [ContinuationInterceptor] interface + * and use their [interceptContinuation] functions, too. */ public fun interceptContinuation(continuation: Continuation): Continuation } diff --git a/core/builtins/src/kotlin/coroutines/CoroutineContext.kt b/core/builtins/src/kotlin/coroutines/CoroutineContext.kt index ebe9dbce6cd..2f808e1b372 100644 --- a/core/builtins/src/kotlin/coroutines/CoroutineContext.kt +++ b/core/builtins/src/kotlin/coroutines/CoroutineContext.kt @@ -17,25 +17,25 @@ package kotlin.coroutines /** - * Persistent context for the coroutine. It is an indexed set of [CoroutineContextElement] instances. + * Persistent context for the coroutine. It is an indexed set of [Element] instances. * An indexed set is a mix between a set and a map. - * Every element in this set has a unique [CoroutineContextKey]. + * Every element in this set has a unique [Key]. */ @SinceKotlin("1.1") public interface CoroutineContext { /** - * Returns an element with the given [key] in this context or `null`. + * Returns the element with the given [key] from this context or `null`. */ - public operator fun get(key: CoroutineContextKey): E? + public operator fun get(key: Key): E? /** * Accumulates entries of this context starting with [initial] value and applying [operation] * from left to right to current accumulator value and each element of this context. */ - public fun fold(initial: R, operation: (R, CoroutineContextElement) -> R): R + public fun fold(initial: R, operation: (R, Element) -> R): R /** - * Returns a context containing elements from this context and elements from other [context]. + * Returns a context containing elements from this context and elements from other [context]. * The elements from this context with the same key as in the other one are dropped. */ public operator fun plus(context: CoroutineContext): CoroutineContext @@ -44,23 +44,20 @@ public interface CoroutineContext { * Returns a context containing elements from this context, but without an element with * the specified [key]. */ - public fun minusKey(key: CoroutineContextKey<*>): CoroutineContext -} + public fun minusKey(key: Key<*>): CoroutineContext -/** - * An element of the [CoroutineContext]. An element of the coroutine context is a singleton context by itself. - */ -@SinceKotlin("1.1") -public interface CoroutineContextElement : CoroutineContext { /** - * A key of this coroutine context element. + * An element of the [CoroutineContext]. An element of the coroutine context is a singleton context by itself. */ - public val contextKey: CoroutineContextKey<*> + public interface Element : CoroutineContext { + /** + * A key of this coroutine context element. + */ + public val key: Key<*> + } + + /** + * Key for the elements of [CoroutineContext]. [E] is a type of element with this key. + */ + public interface Key } - -/** - * Key for the elements of [CoroutineContext]. [E] is a type of the element with this key. - */ -@SinceKotlin("1.1") -public interface CoroutineContextKey - diff --git a/libraries/stdlib/src/kotlin/coroutines/CoroutineContextImpl.kt b/libraries/stdlib/src/kotlin/coroutines/CoroutineContextImpl.kt index 6f8eb7cb707..6f707233ea2 100644 --- a/libraries/stdlib/src/kotlin/coroutines/CoroutineContextImpl.kt +++ b/libraries/stdlib/src/kotlin/coroutines/CoroutineContextImpl.kt @@ -16,23 +16,25 @@ package kotlin.coroutines +import kotlin.coroutines.CoroutineContext.* + /** - * Base class for [CoroutineContextElement] implementations. + * Base class for [CoroutineContext.Element] implementations. */ @SinceKotlin("1.1") -public abstract class AbstractCoroutineContextElement : CoroutineContextElement { +public abstract class AbstractCoroutineContextElement(public override val key: Key<*>) : Element { @Suppress("UNCHECKED_CAST") - public override operator fun get(key: CoroutineContextKey): E? = - if (this.contextKey == key) this as E else null + public override operator fun get(key: Key): E? = + if (this.key == key) this as E else null - public override fun fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = + public override fun fold(initial: R, operation: (R, Element) -> R): R = operation(initial, this) public override operator fun plus(context: CoroutineContext): CoroutineContext = plusImpl(context) - public override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = - if (this.contextKey == key) EmptyCoroutineContext else this + public override fun minusKey(key: Key<*>): CoroutineContext = + if (this.key == key) EmptyCoroutineContext else this } /** @@ -40,10 +42,10 @@ public abstract class AbstractCoroutineContextElement : CoroutineContextElement */ @SinceKotlin("1.1") public object EmptyCoroutineContext : CoroutineContext { - public override fun get(key: CoroutineContextKey): E? = null - public override fun fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = initial + public override fun get(key: Key): E? = null + public override fun fold(initial: R, operation: (R, Element) -> R): R = initial public override fun plus(context: CoroutineContext): CoroutineContext = context - public override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = this + public override fun minusKey(key: Key<*>): CoroutineContext = this public override fun hashCode(): Int = 0 public override fun toString(): String = "EmptyCoroutineContext" } @@ -52,8 +54,8 @@ public object EmptyCoroutineContext : CoroutineContext { // this class is not exposed, but is hidden inside implementations // this is a left-biased list, so that `plus` works naturally -private class CombinedContext(val left: CoroutineContext, val element: CoroutineContextElement) : CoroutineContext { - override fun get(key: CoroutineContextKey): E? { +private class CombinedContext(val left: CoroutineContext, val element: Element) : CoroutineContext { + override fun get(key: Key): E? { var cur = this while (true) { cur.element[key]?.let { return it } @@ -66,13 +68,13 @@ private class CombinedContext(val left: CoroutineContext, val element: Coroutine } } - public override fun fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = + public override fun fold(initial: R, operation: (R, Element) -> R): R = operation(left.fold(initial, operation), element) public override operator fun plus(context: CoroutineContext): CoroutineContext = plusImpl(context) - public override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext { + public override fun minusKey(key: Key<*>): CoroutineContext { element[key]?.let { return left } val newLeft = left.minusKey(key) return when (newLeft) { @@ -85,8 +87,8 @@ private class CombinedContext(val left: CoroutineContext, val element: Coroutine private fun size(): Int = if (left is CombinedContext) left.size() + 1 else 2 - private fun contains(element: CoroutineContextElement): Boolean = - get(element.contextKey) == element + private fun contains(element: Element): Boolean = + get(element.key) == element private fun containsAll(context: CombinedContext): Boolean { var cur = context @@ -96,7 +98,7 @@ private class CombinedContext(val left: CoroutineContext, val element: Coroutine if (next is CombinedContext) { cur = next } else { - return contains(next as CoroutineContextElement) + return contains(next as Element) } } } @@ -115,7 +117,7 @@ private class CombinedContext(val left: CoroutineContext, val element: Coroutine private fun CoroutineContext.plusImpl(context: CoroutineContext): CoroutineContext = if (context == EmptyCoroutineContext) this else // fast path -- avoid lambda creation context.fold(this) { acc, element -> - val removed = acc.minusKey(element.contextKey) + val removed = acc.minusKey(element.key) if (removed == EmptyCoroutineContext) element else { // make sure interceptor is always last in the context (and thus is fast to get when present) val interceptor = removed[ContinuationInterceptor] diff --git a/libraries/stdlib/test/coroutines/CoroutineContextTest.kt b/libraries/stdlib/test/coroutines/CoroutineContextTest.kt index 9d7e2ac2b7b..69f262164eb 100644 --- a/libraries/stdlib/test/coroutines/CoroutineContextTest.kt +++ b/libraries/stdlib/test/coroutines/CoroutineContextTest.kt @@ -21,30 +21,25 @@ import org.junit.Test import kotlin.coroutines.* class CoroutineContextTest { - data class CtxA(val i: Int) : AbstractCoroutineContextElement() { - companion object : CoroutineContextKey - override val contextKey get() = CtxA + data class CtxA(val i: Int) : AbstractCoroutineContextElement(CtxA) { + companion object Key : CoroutineContext.Key } - data class CtxB(val i: Int) : AbstractCoroutineContextElement() { - companion object : CoroutineContextKey - override val contextKey get() = CtxB + data class CtxB(val i: Int) : AbstractCoroutineContextElement(CtxB) { + companion object Key : CoroutineContext.Key } - data class CtxC(val i: Int) : AbstractCoroutineContextElement() { - companion object : CoroutineContextKey - override val contextKey get() = CtxC + data class CtxC(val i: Int) : AbstractCoroutineContextElement(CtxC) { + companion object Key : CoroutineContext.Key } - object Disp1 : AbstractCoroutineContextElement(), ContinuationInterceptor { + object Disp1 : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor { override fun interceptContinuation(continuation: Continuation): Continuation = continuation - override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor override fun toString(): String = "Disp1" } - object Disp2 : AbstractCoroutineContextElement(), ContinuationInterceptor { + object Disp2 : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor { override fun interceptContinuation(continuation: Continuation): Continuation = continuation - override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor override fun toString(): String = "Disp2" } @@ -171,10 +166,10 @@ class CoroutineContextTest { assertNotEquals(ctx3, ctx4) } - private fun assertContents(ctx: CoroutineContext, vararg elements: CoroutineContextElement) { + private fun assertContents(ctx: CoroutineContext, vararg elements: CoroutineContext.Element) { val set = ctx.fold(setOf()) { a, b -> a + b } assertEquals(listOf(*elements), set.toList()) for (elem in elements) - assertTrue(ctx[elem.contextKey] == elem) + assertTrue(ctx[elem.key] == elem) } } \ No newline at end of file diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt index 04a9f837a0e..a2d8590344a 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt @@ -185,26 +185,26 @@ public abstract interface class kotlin/coroutines/Continuation { public abstract fun resumeWithException (Ljava/lang/Throwable;)V } -public abstract interface class kotlin/coroutines/ContinuationInterceptor : kotlin/coroutines/CoroutineContextElement { - public static final field Companion Lkotlin/coroutines/ContinuationInterceptor$Companion; +public abstract interface class kotlin/coroutines/ContinuationInterceptor : kotlin/coroutines/CoroutineContext$Element { + public static final field Key Lkotlin/coroutines/ContinuationInterceptor$Key; public abstract fun interceptContinuation (Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation; } -public final class kotlin/coroutines/ContinuationInterceptor$Companion : kotlin/coroutines/CoroutineContextKey { +public final class kotlin/coroutines/ContinuationInterceptor$Key : kotlin/coroutines/CoroutineContext$Key { } public abstract interface class kotlin/coroutines/CoroutineContext { public abstract fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun get (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContextElement; - public abstract fun minusKey (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContext; + public abstract fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element; + public abstract fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext; public abstract fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext; } -public abstract interface class kotlin/coroutines/CoroutineContextElement : kotlin/coroutines/CoroutineContext { - public abstract fun getContextKey ()Lkotlin/coroutines/CoroutineContextKey; +public abstract interface class kotlin/coroutines/CoroutineContext$Element : kotlin/coroutines/CoroutineContext { + public abstract fun getKey ()Lkotlin/coroutines/CoroutineContext$Key; } -public abstract interface class kotlin/coroutines/CoroutineContextKey { +public abstract interface class kotlin/coroutines/CoroutineContext$Key { } public abstract interface annotation class kotlin/coroutines/RestrictsSuspension : java/lang/annotation/Annotation { diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt index 78ee8eef65d..49c217c65ca 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt @@ -1754,11 +1754,12 @@ public final class kotlin/concurrent/TimersKt { public static final fun timer (Ljava/lang/String;Z)Ljava/util/Timer; } -public abstract class kotlin/coroutines/AbstractCoroutineContextElement : kotlin/coroutines/CoroutineContextElement { - public fun ()V +public abstract class kotlin/coroutines/AbstractCoroutineContextElement : kotlin/coroutines/CoroutineContext$Element { + public fun (Lkotlin/coroutines/CoroutineContext$Key;)V public fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun get (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContextElement; - public fun minusKey (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContext; + public fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element; + public fun getKey ()Lkotlin/coroutines/CoroutineContext$Key; + public fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext; public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext; } @@ -1773,9 +1774,9 @@ public final class kotlin/coroutines/CoroutinesKt { public final class kotlin/coroutines/EmptyCoroutineContext : kotlin/coroutines/CoroutineContext { public static final field INSTANCE Lkotlin/coroutines/EmptyCoroutineContext; public fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun get (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContextElement; + public fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element; public fun hashCode ()I - public fun minusKey (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContext; + public fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext; public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext; public fun toString ()Ljava/lang/String; }