Skip to content

Commit 36dab67

Browse files
committed
KEEP-0443-suspend-CoroutineContext-context-parameter: minor fixes
1 parent b7cdc6e commit 36dab67

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

proposals/KEEP-0443-suspend-CoroutineContext-context-parameter.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Make all `suspend` functions implicitly inject `CoroutineContext` context parameter
1+
# `CoroutineContext` context parameter in `suspend` functions
22

33
* **Type**: Design proposal
44
* **Author**: Nikita Bobko
@@ -10,11 +10,12 @@
1010
Roman Venediktov
1111
* **Issue:**
1212
[KT-15555 Support suspend get/set properties](https://youtrack.jetbrains.com/issue/KT-15555)
13-
* **Discussion**: [todo](https://github.com/Kotlin/KEEP/discussions/todo)
13+
* **Discussion**: [#452](https://github.com/Kotlin/KEEP/discussions/452)
14+
* **Status**: Public discussion
1415

1516
## Abstract
1617

17-
[KEEP-367](./context-parameters.md) introduces a context parameters feature to Kotlin.
18+
[KEEP-367](./KEEP-0367-context-parameters.md) introduces context parameters feature to Kotlin.
1819

1920
There are multiple ways on how you can think of context parameters.
2021
One of them is that it's possible to pass parameters by position,
@@ -90,7 +91,7 @@ A lot of existing Kotlin code that relies on coroutines already uses `suspend` f
9091
- [`CoroutineContext` becomes even more magical](#coroutinecontext-becomes-even-more-magical)
9192
- [Discarded idea. Interop with Compose](#discarded-idea-interop-with-compose)
9293
- [Dependencies](#dependencies)
93-
- [Mock example. `ScopedValues`-like API for `CoroutineContext`](#mock-example-scopedvalues-like-api-for-coroutinecontext)
94+
- [Illustrative example. `ScopedValues`-like API for `CoroutineContext`](#illustrative-example-scopedvalues-like-api-for-coroutinecontext)
9495
- [IDE integration](#ide-integration)
9596
- [Related features in other languages](#related-features-in-other-languages)
9697
- [Alternatives](#alternatives)
@@ -295,8 +296,8 @@ class ContextMarker(val marker: String) : AbstractCoroutineContextElement(Compan
295296
}
296297

297298
suspend fun main() {
298-
withContext(ContextMarker("implicit context")) {
299-
context(ContextMarker("explicit context")) {
299+
withContext(ContextMarker("implicit context")) { // coroutines: kotlinx.coroutines.withContext
300+
context(ContextMarker("explicit context")) { // stdlib (experimental): kotlin.context
300301
foo()
301302
}
302303
}
@@ -370,7 +371,7 @@ This proposal answers "no" to all the questions above:
370371
4. No, `context(_: CoroutineContext) fun` isn't equivalent to `suspend fun` from the overload resolution perspective.
371372

372373
We prefer to answer "no" because overridability is a very strong type of equivalence.
373-
The current Kotlin version doesn't allow dropping parameters when you override a function.
374+
For example, the current Kotlin version doesn't allow dropping parameters when you override a function.
374375

375376
And just to add a point, if we answered "yes", it'd introduce non-transitive equivalence into overload resolution.
376377
`suspend fun foo() {}` and `context(_: CoroutineContext) fun foo() {}` would be equivalent.
@@ -450,7 +451,7 @@ fun main() {
450451
```
451452

452453
- Given that \#5 is red, \#6 should be obviously red.
453-
- Since the context and `suspend` functions are different from the perspective of overload resolution ([see section](#declaration-site-conflicting_overloads-and-overridability)),
454+
- Since the context and `suspend` functions are different from the perspective of overload resolution ([see the section](#declaration-site-conflicting_overloads-and-overridability)),
454455
we propose to make \#3 red – `INITIALIZER_TYPE_MISMATCH`.
455456

456457
### `kotlin.synchronized` stdlib function
@@ -610,7 +611,7 @@ That's why the alternative design is not possible either.
610611

611612
## Dependencies
612613

613-
**(1)** This proposal, in general, depends on [KEEP-367 Context parameters](./context-parameters.md).
614+
**(1)** This proposal, in general, depends on [KEEP-367 Context parameters](./KEEP-0367-context-parameters.md).
614615

615616
**(2)** This proposal depends on the fact that contextual parameters _fill in_ neither extension, nor dispatch holes:
616617

@@ -625,7 +626,7 @@ fun foo() {
625626
fun String.functionWithExtensionHole() {}
626627
```
627628

628-
If not the decision to not fill in the extension and dispatch hole, this proposal would be a change of behavior:
629+
If not the decision, this proposal would be a behavioral change:
629630

630631
```kotlin
631632
suspend fun CoroutineContext.bar() {
@@ -638,7 +639,7 @@ fun CoroutineContext.baz() {}
638639
Thankfully, it's not the case.
639640
These examples are indicators of context parameters' good design.
640641

641-
## Mock example. `ScopedValues`-like API for `CoroutineContext`
642+
## Illustrative example. `ScopedValues`-like API for `CoroutineContext`
642643

643644
Imagine we want to provide [`ScopedValues`-like API](https://openjdk.org/jeps/506) for `CoroutineContext` so that storing data in `CoroutineContext` is as easy as declaring global variables:
644645

0 commit comments

Comments
 (0)