Skip to content

Commit 63f6743

Browse files
authored
Cleanup: remove or hide some InternalCoroutinesApi (#4548)
* No one is using `runSingleTaskFromCurrentSystemDispatcher`: <#3439 (comment)>, * The Ktor usage of `processNextEventInCurrentThread` got removed in 2024. * `synchronizedImpl` is mentioned in other repositories, but people use their own copies. `synchronized`, on the other hand, is actually used. * `Continuation<T>.resumeCancellableWith` doesn't seem to be used, but it was public, and there may have been accidental usages, so it goes through a deprecation cycle.
1 parent d209433 commit 63f6743

File tree

18 files changed

+43
-305
lines changed

18 files changed

+43
-305
lines changed

kotlinx-coroutines-core/api/kotlinx-coroutines-core.api

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,6 @@ public abstract interface class kotlinx/coroutines/DisposableHandle {
343343
public abstract fun dispose ()V
344344
}
345345

346-
public final class kotlinx/coroutines/EventLoopKt {
347-
public static final fun isIoDispatcherThread (Ljava/lang/Thread;)Z
348-
public static final fun processNextEventInCurrentThread ()J
349-
public static final fun runSingleTaskFromCurrentSystemDispatcher ()J
350-
}
351-
352346
public final class kotlinx/coroutines/ExceptionsKt {
353347
public static final fun CancellationException (Ljava/lang/String;Ljava/lang/Throwable;)Ljava/util/concurrent/CancellationException;
354348
}

kotlinx-coroutines-core/common/src/Builders.common.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ internal class DispatchedCoroutine<in T>(
253253
override fun afterResume(state: Any?) {
254254
if (tryResume()) return // completed before getResult invocation -- bail out
255255
// Resume in a cancellable way because we have to switch back to the original dispatcher
256-
uCont.intercepted().resumeCancellableWith(recoverResult(state, uCont))
256+
uCont.intercepted().resumeCancellableWithInternal(recoverResult(state, uCont))
257257
}
258258

259259
internal fun getResult(): Any? {

kotlinx-coroutines-core/common/src/CancellableContinuation.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public interface CancellableContinuation<in T> : Continuation<T> {
160160
* Implementation note: current implementation always returns RESUME_TOKEN or `null`
161161
*
162162
* @suppress **This is unstable API and it is subject to change.**
163+
* Used in ktor.
163164
*/
164165
@InternalCoroutinesApi
165166
public fun <R: T> tryResume(
@@ -172,6 +173,7 @@ public interface CancellableContinuation<in T> : Continuation<T> {
172173
* [completeResume] must be invoked with it.
173174
*
174175
* @suppress **This is unstable API and it is subject to change.**
176+
* Used in ktor.
175177
*/
176178
@InternalCoroutinesApi
177179
public fun tryResumeWithException(exception: Throwable): Any?
@@ -180,6 +182,7 @@ public interface CancellableContinuation<in T> : Continuation<T> {
180182
* Completes the execution of [tryResume] or [tryResumeWithException] on its non-null result.
181183
*
182184
* @suppress **This is unstable API and it is subject to change.**
185+
* Used in ktor.
183186
*/
184187
@InternalCoroutinesApi
185188
public fun completeResume(token: Any)
@@ -191,6 +194,7 @@ public interface CancellableContinuation<in T> : Continuation<T> {
191194
* Exposed in our ABI since 1.0.0 within `suspendCancellableCoroutine` body.
192195
*
193196
* @suppress **This is unstable API and it is subject to change.**
197+
* Used in ktor.
194198
*/
195199
@InternalCoroutinesApi
196200
public fun initCancellability()

kotlinx-coroutines-core/common/src/Job.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public interface Job : CoroutineContext.Element {
240240
public val children: Sequence<Job>
241241

242242
/**
243-
* Attaches child job so that this job becomes its parent and
243+
* Attaches a child job so that this job becomes its parent and
244244
* returns a handle that should be used to detach it.
245245
*
246246
* A parent-child relation has the following effect:
@@ -256,7 +256,8 @@ public interface Job : CoroutineContext.Element {
256256
* lookup a [Job] instance in the parent context and use this function to attach themselves as a child.
257257
* They also store a reference to the resulting [ChildHandle] and dispose a handle when they complete.
258258
*
259-
* @suppress This is an internal API. This method is too error prone for public API.
259+
* @suppress This is an internal API. This method is too error-prone for public API.
260+
* Used in IntelliJ.
260261
*/
261262
// ChildJob and ChildHandle are made internal on purpose to further deter 3rd-party impl of Job
262263
@InternalCoroutinesApi

kotlinx-coroutines-core/common/src/internal/DispatchedContinuation.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,23 @@ internal fun CoroutineDispatcher.safeIsDispatchNeeded(context: CoroutineContext)
271271
* It may appear in stack traces when coroutines are started/resumed with unconfined dispatcher.
272272
* @suppress **This an internal API and should not be used from general code.**
273273
*/
274-
@InternalCoroutinesApi
275-
public fun <T> Continuation<T>.resumeCancellableWith(
274+
internal fun <T> Continuation<T>.resumeCancellableWithInternal(
276275
result: Result<T>,
277276
): Unit = when (this) {
278277
is DispatchedContinuation -> resumeCancellableWith(result)
279278
else -> resumeWith(result)
280279
}
281280

281+
@InternalCoroutinesApi
282+
@Deprecated(
283+
"This function was intended for internal use only and will be removed. " +
284+
"If you have a use case for it, please file an issue in the issue tracker.",
285+
level = DeprecationLevel.WARNING
286+
) // WARNING in 1.11, ERROR in 1.12, REMOVE in 1.13, was @InternalCoroutinesApi
287+
public fun <T> Continuation<T>.resumeCancellableWith(
288+
result: Result<T>,
289+
): Unit = resumeCancellableWithInternal(result)
290+
282291
internal fun DispatchedContinuation<Unit>.yieldUndispatched(): Boolean =
283292
executeUnconfined(Unit, MODE_CANCELLABLE, doYield = true) {
284293
run()

kotlinx-coroutines-core/common/src/internal/Scopes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal open class ScopeCoroutine<in T>(
2020

2121
override fun afterCompletion(state: Any?) {
2222
// Resume in a cancellable way by default when resuming from another context
23-
uCont.intercepted().resumeCancellableWith(recoverResult(state, uCont))
23+
uCont.intercepted().resumeCancellableWithInternal(recoverResult(state, uCont))
2424
}
2525

2626
/**

kotlinx-coroutines-core/common/src/internal/Synchronized.common.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ import kotlin.contracts.*
1111
@InternalCoroutinesApi
1212
public expect open class SynchronizedObject() // marker abstract class
1313

14-
/**
15-
* @suppress **This an internal API and should not be used from general code.**
16-
*/
17-
@InternalCoroutinesApi
18-
public expect inline fun <T> synchronizedImpl(lock: SynchronizedObject, block: () -> T): T
14+
@PublishedApi
15+
internal expect inline fun <T> synchronizedImpl(lock: SynchronizedObject, block: () -> T): T
1916

2017
/**
2118
* @suppress **This an internal API and should not be used from general code.**

kotlinx-coroutines-core/common/src/intrinsics/Cancellable.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlin.coroutines.intrinsics.*
1313
*/
1414
@InternalCoroutinesApi
1515
public fun <T> (suspend () -> T).startCoroutineCancellable(completion: Continuation<T>): Unit = runSafely(completion) {
16-
createCoroutineUnintercepted(completion).intercepted().resumeCancellableWith(Result.success(Unit))
16+
createCoroutineUnintercepted(completion).intercepted().resumeCancellableWithInternal(Result.success(Unit))
1717
}
1818

1919
/**
@@ -23,7 +23,7 @@ public fun <T> (suspend () -> T).startCoroutineCancellable(completion: Continuat
2323
internal fun <R, T> (suspend (R) -> T).startCoroutineCancellable(
2424
receiver: R, completion: Continuation<T>,
2525
) = runSafely(completion) {
26-
createCoroutineUnintercepted(receiver, completion).intercepted().resumeCancellableWith(Result.success(Unit))
26+
createCoroutineUnintercepted(receiver, completion).intercepted().resumeCancellableWithInternal(Result.success(Unit))
2727
}
2828

2929
/**
@@ -32,7 +32,7 @@ internal fun <R, T> (suspend (R) -> T).startCoroutineCancellable(
3232
*/
3333
internal fun Continuation<Unit>.startCoroutineCancellable(fatalCompletion: Continuation<*>) =
3434
runSafely(fatalCompletion) {
35-
intercepted().resumeCancellableWith(Result.success(Unit))
35+
intercepted().resumeCancellableWithInternal(Result.success(Unit))
3636
}
3737

3838
/**

kotlinx-coroutines-core/common/src/selects/Select.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,8 @@ public typealias ProcessResultFunction = (clauseObject: Any, param: Any?, clause
162162
* or [SelectInstance.selectInRegistrationPhase], should be processed in case of this `select`
163163
* cancellation while dispatching. Unfortunately, we cannot pass this function only in [SelectInstance.trySelect],
164164
* as [SelectInstance.selectInRegistrationPhase] can be called when the coroutine is already cancelled.
165-
*
166-
* @suppress **This is unstable API, and it is subject to change.**
167165
*/
168-
@InternalCoroutinesApi
169-
public typealias OnCancellationConstructor = (select: SelectInstance<*>, param: Any?, internalResult: Any?) ->
166+
internal typealias OnCancellationConstructor = (select: SelectInstance<*>, param: Any?, internalResult: Any?) ->
170167
(Throwable, Any?, CoroutineContext) -> Unit
171168

172169
/**

kotlinx-coroutines-core/jsAndWasmShared/src/internal/Synchronized.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public actual open class SynchronizedObject
1111
/**
1212
* @suppress **This an internal API and should not be used from general code.**
1313
*/
14-
@InternalCoroutinesApi
15-
public actual inline fun <T> synchronizedImpl(lock: SynchronizedObject, block: () -> T): T = block()
14+
@PublishedApi
15+
internal actual inline fun <T> synchronizedImpl(lock: SynchronizedObject, block: () -> T): T = block()

0 commit comments

Comments
 (0)