Skip to content

Commit

Permalink
Add documentation about our compatibility policy and experimental ann…
Browse files Browse the repository at this point in the history
…otations

Fixes Kotlin#859
  • Loading branch information
qwwdfsad committed Feb 4, 2019
1 parent a68376c commit 4764e98
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 32 deletions.
25 changes: 0 additions & 25 deletions COMPATIBILITY.md

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
Library support for Kotlin coroutines with [multiplatform](#multiplatform) support.
This is a companion version for Kotlin `1.3.20` release.

**NOTE**: `0.30.2` was the last release with Kotlin 1.2 and experimental coroutines.
See [COMPATIBILITY.md](COMPATIBILITY.md) for details of migration onto the stable Kotlin 1.3 coroutines.

```kotlin
GlobalScope.launch {
delay(1000)
Expand Down Expand Up @@ -58,6 +55,7 @@ GlobalScope.launch {
* [Guide to UI programming with coroutines](ui/coroutines-guide-ui.md)
* [Guide to reactive streams with coroutines](reactive/coroutines-guide-reactive.md)
* [Debugging capabilities in kotlinx.coroutines](docs/debugging.md)
* [Compatibility policy and experimental annotations](docs/compatibility.md)
* [Change log for kotlinx.coroutines](CHANGES.md)
* [Coroutines design document (KEEP)](https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md)
* [Full kotlinx.coroutines API reference](http:https://kotlin.github.io/kotlinx.coroutines)
Expand Down
115 changes: 115 additions & 0 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!---
/*
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
--->

<!--- TOC -->

* [Compatibility](#compatibility)
* [Public API types](#public-api-types)
* [Experimental API](#experimental-api)
* [Obsolete API](#obsolete-api)
* [Internal API](#internal-api)
* [Stable API](#stable-api)
* [Deprecation cycle](#deprecation-cycle)
* [Using annotated API](#using-annotated-api)
* [Programmatically](#programmatically)
* [Gradle](#gradle)
* [Maven](#maven)

<!--- END_TOC -->

## Compatibility
This document describes the compatibility policy of `kotlinx.coroutines` library since version 1.0.0 and semantics of compatibility-specific annotations.


## Public API types
`kotlinx.coroutines` public API comes in five flavours: stable, experimental, obsolete, internal and deprecated.
All public API except stable is marked with the corresponding annotation.

### Experimental API
Experimental API is marked with [@ExperimentalCoroutinesApi][ExperimentalCoroutinesApi] annotation.
API is marked experimental when its design has potential open questions which may eventually lead to
either semantics changes of the API or its deprecation.

By default, most of the new API is marked as experimental and becomes stable in one of the next major releases if no new issues arise.
Otherwise, either semantics is fixed without changes in ABI or API goes through deprecation cycle.

When using experimental API may be dangerous:
* You are writing a library which depends on `kotlinx.coroutines` and want to use experimental coroutines API in a stable library API.
It may lead to undesired consequences when end users of your library update their `kotlinx.coroutines` version where experimental API
has slightly different semantics.
* You want to build core infrastructure of the application around experimental API.

### Obsolete API
Obsolete API is marked with [@ObsoleteCoroutinesApi][ObsoleteCoroutinesApi] annotation.
Obsolete API is similar to experimental, but already known to have serious design flaws and its potential replacement,
but replacement is not yet implemented.

The semantics of this API won't be changed, but it will go through a deprecation cycle as soon as the replacement is ready.

### Internal API
Internal API is marked with [@InternalCoroutinesApi][InternalCoroutinesApi] or is part of `kotlinx.coroutines.internal` package.
This API has no guarantees on its stability, can and will be changed and/or removed in the future releases.
If you can't avoid using internal API, please report it to [issue tracker](https://github.com/Kotlin/kotlinx.coroutines/issues/new).

### Stable API
Stable API is guaranteed to preserve its ABI and documented semantics. If at some point unfixable design flaws will be discovered,
this API will go through a deprecation cycle and remain binary compatible as long as possible.

### Deprecation cycle
When some API is deprecated, it goes through multiple stages and there is at least one major release between stages.
* Feature is deprecated with compilation warning. Most of the time, proper replacement
(and corresponding `replaceWith` declaration) is provided to automatically migrate deprecated usages with a help of IntelliJ IDEA.
* Deprecation level is increased to `error` or `hidden`. It is no longer possible to compile new code against deprecated API,
though it is still present in the ABI.
* API is completely removed. While we give our best efforts not to do so and have no plans of removing any API, we still are leaving
this option in case of unforeseen problems such as security holes.

## Using annotated API
All API annotations are [kotlin.Experimental](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-experimental/index.html).
It is done in order to produce compilation warning about using experimental or obsolete API.
Warnings can be disabled either programmatically for a specific call site or globally for the whole module.

### Programmatically
For a specific call-site, warning can be disabled by using [UseExperimental](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-use-experimental/index.html) annotation:
```kotlin
@UseExperimental(ExperimentalCoroutinesApi::class) // Disables warning about experimental coroutines API
fun experimentalApiUsage() {
someKotlinxCoroutinesExperimentalMethod()
}
```

### Gradle
For the Gradle project, a warning can be disabled by passing a compiler flag in your `build.gradle` file:

```groovy
tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi"]
}
```

### Maven
For the Maven project, a warning can be disabled by passing a compiler flag in your `pom.xml` file:
```xml
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
... your configuration ...
<configuration>
<args>
<arg>-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi</arg>
</args>
</configuration>
</plugin>
```


<!--- MODULE kotlinx-coroutines-core -->
<!--- INDEX kotlinx.coroutines -->
[ExperimentalCoroutinesApi]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/index.html
[ObsoleteCoroutinesApi]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/index.html
[InternalCoroutinesApi]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/index.html
<!--- END -->
3 changes: 2 additions & 1 deletion docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [Stacktrace recovery](#stacktrace-recovery)
* [Stacktrace recovery machinery](#stacktrace-recovery-machinery)
* [Debug agent](#debug-agent)
* [Debug agent and Android](#debug-agent-and-android)

<!--- END_TOC -->

Expand All @@ -32,7 +33,7 @@ Stacktrace recovery is another useful feature of debug mode. It is enabled by de
but can be separately disabled by setting `kotlinx.coroutines.stacktrace.recovery` system property to `false`.

Stacktrace recovery tries to knit asynchronous exception stacktrace with a stacktrace of the receiver by copying it, providing
not only information where an exception was thrown, but also where it was asynchronously rethrown or caught .
not only information where an exception was thrown, but also where it was asynchronously rethrown or caught.

It is easy to demonstrate with actual stacktraces of the same program that awaits asynchronous operation in `main` function:

Expand Down
2 changes: 0 additions & 2 deletions kotlinx-coroutines-core/common/src/Annotations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public annotation class ObsoleteCoroutinesApi
* Marks declarations that are **internal** in coroutines API, which means that should not be used outside of
* `kotlinx.coroutines`, because their signatures and semantics will be changing between release without any
* warnings and without providing any migration aids.
*
* @suppress **This an internal API and should not be used from general code.**
*/
@Retention(value = AnnotationRetention.BINARY)
@Experimental(level = Experimental.Level.ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ private tailrec fun Class<*>.fieldsCount(accumulator: Int = 0): Int {
val totalFields = accumulator + fieldsCount
val superClass = superclass ?: return totalFields
return superClass.fieldsCount(totalFields)
}
}

0 comments on commit 4764e98

Please sign in to comment.