Skip to content

Commit 09ddc06

Browse files
authored
Remove the @PublishedApi that are no longer needed (#4089)
According to @mvicsokolova, the following entry points are not used by IDEA since 2020: kotlinx.coroutines.debug.internal.StackTraceFrame field callerFrame field stackTraceElement kotlinx.coroutines.StandaloneCoroutine field _state field context kotlinx.coroutines.ChildContinuation field child kotlinx.coroutines.CancellableContinuationImpl field _decision field delegate field resumeMode field submissionTime field context kotlinx.coroutines.DispatchedContinuation field continuation This leaves only the following *internal* entry points: kotlinx.coroutines.debug.internal.DebugCoroutineInfo method getCreationStackTrace() method getState() method lastObservedStackTrace() field context field sequenceNumber field lastObservedFrame field lastObservedThread kotlinx.coroutines.debug.internal.DebugCoroutineInfoImpl method getCreationStackTrace() method getContext() field lastObservedThread field _state field _lastObservedFrame field sequenceNumber kotlinx.coroutines.debug.internal.DebugProbesImpl field INSTANCE method isInstalled$kotlinx_coroutines_debug() method isInstalled$kotlinx_coroutines_core() method enhanceStackTraceWithThreadDump() method dumpCoroutinesInfo() method dumpCoroutinesInfoAsJsonAndReferences() method enhanceStackTraceWithThreadDumpAsJson() kotlinx.coroutines.debug.internal.DebugProbesImpl$CoroutineOwner field info kotlinx.coroutines.CoroutineId field Key method getId() ... the following *public* entry points: kotlinx.coroutines.CoroutineName field Key method getName() kotlinx.coroutines.Job field Key kotlinx.coroutines.CoroutineDispatcher field Key ... and these entry points outside of the library: kotlin.coroutines.CombinedContext method get() kotlin.coroutines.jvm.internal.DebugMetadataKt method getStackTraceElement() method getSpilledVariableFieldMapping() This commit updates the comments and removes the extraneous `@PublishedApi` annotations, giving us more flexibility to change code.
1 parent 7bdc901 commit 09ddc06

File tree

10 files changed

+24
-60
lines changed

10 files changed

+24
-60
lines changed

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public final class kotlinx/coroutines/CancellableContinuation$DefaultImpls {
5151
public static synthetic fun tryResume$default (Lkotlinx/coroutines/CancellableContinuation;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Ljava/lang/Object;
5252
}
5353

54-
public class kotlinx/coroutines/CancellableContinuationImpl : kotlinx/coroutines/DispatchedTask, kotlin/coroutines/jvm/internal/CoroutineStackFrame, kotlinx/coroutines/CancellableContinuation, kotlinx/coroutines/Waiter {
54+
public class kotlinx/coroutines/CancellableContinuationImpl : kotlin/coroutines/jvm/internal/CoroutineStackFrame, kotlinx/coroutines/CancellableContinuation, kotlinx/coroutines/Waiter {
5555
public fun <init> (Lkotlin/coroutines/Continuation;I)V
5656
public final fun callCancelHandler (Lkotlinx/coroutines/CancelHandler;Ljava/lang/Throwable;)V
5757
public final fun callOnCancellation (Lkotlin/jvm/functions/Function1;Ljava/lang/Throwable;)V
@@ -84,12 +84,6 @@ public final class kotlinx/coroutines/CancellableContinuationKt {
8484
public static final fun suspendCancellableCoroutine (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8585
}
8686

87-
public final class kotlinx/coroutines/ChildContinuation {
88-
public final field child Lkotlinx/coroutines/CancellableContinuationImpl;
89-
public fun <init> (Lkotlinx/coroutines/CancellableContinuationImpl;)V
90-
public fun invoke (Ljava/lang/Throwable;)V
91-
}
92-
9387
public abstract interface class kotlinx/coroutines/ChildHandle : kotlinx/coroutines/DisposableHandle {
9488
public abstract fun childCancelled (Ljava/lang/Throwable;)Z
9589
public abstract fun getParent ()Lkotlinx/coroutines/Job;
@@ -318,15 +312,6 @@ public final class kotlinx/coroutines/DelayKt {
318312
public abstract interface annotation class kotlinx/coroutines/DelicateCoroutinesApi : java/lang/annotation/Annotation {
319313
}
320314

321-
public final class kotlinx/coroutines/DispatchedCoroutine {
322-
public static final synthetic fun get_decision$volatile$FU$kotlinx_coroutines_core ()Ljava/util/concurrent/atomic/AtomicIntegerFieldUpdater;
323-
}
324-
325-
public abstract class kotlinx/coroutines/DispatchedTask : kotlinx/coroutines/scheduling/Task {
326-
public field resumeMode I
327-
public final fun run ()V
328-
}
329-
330315
public final class kotlinx/coroutines/DispatchedTaskKt {
331316
public static final field MODE_CANCELLABLE I
332317
}
@@ -970,12 +955,6 @@ public final class kotlinx/coroutines/debug/internal/DebuggerInfo : java/io/Seri
970955
public final fun getState ()Ljava/lang/String;
971956
}
972957

973-
public final class kotlinx/coroutines/debug/internal/StackTraceFrame : kotlin/coroutines/jvm/internal/CoroutineStackFrame {
974-
public final field stackTraceElement Ljava/lang/StackTraceElement;
975-
public fun getCallerFrame ()Lkotlin/coroutines/jvm/internal/CoroutineStackFrame;
976-
public fun getStackTraceElement ()Ljava/lang/StackTraceElement;
977-
}
978-
979958
public abstract class kotlinx/coroutines/flow/AbstractFlow : kotlinx/coroutines/flow/CancellableFlow, kotlinx/coroutines/flow/Flow {
980959
public fun <init> ()V
981960
public final fun collect (Lkotlinx/coroutines/flow/FlowCollector;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -1287,10 +1266,6 @@ public class kotlinx/coroutines/scheduling/ExperimentalCoroutineDispatcher : kot
12871266
public fun toString ()Ljava/lang/String;
12881267
}
12891268

1290-
public abstract class kotlinx/coroutines/scheduling/Task : java/lang/Runnable {
1291-
public field submissionTime J
1292-
}
1293-
12941269
public final class kotlinx/coroutines/selects/OnTimeoutKt {
12951270
public static final fun onTimeout (Lkotlinx/coroutines/selects/SelectBuilder;JLkotlin/jvm/functions/Function1;)V
12961271
public static final fun onTimeout-8Mi8wO0 (Lkotlinx/coroutines/selects/SelectBuilder;JLkotlin/jvm/functions/Function1;)V

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,13 @@ private const val SUSPENDED = 1
214214
private const val RESUMED = 2
215215

216216
// Used by withContext when context dispatcher changes
217-
@PublishedApi
218-
internal class DispatchedCoroutine<in T> internal constructor(
217+
internal class DispatchedCoroutine<in T>(
219218
context: CoroutineContext,
220219
uCont: Continuation<T>
221220
) : ScopeCoroutine<T>(context, uCont) {
222221
// this is copy-and-paste of a decision state machine inside AbstractionContinuation
223222
// todo: we may some-how abstract it via inline class
224-
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
225-
@JvmField
226-
public val _decision = atomic(UNDECIDED)
223+
private val _decision = atomic(UNDECIDED)
227224

228225
private fun trySuspend(): Boolean {
229226
_decision.loop { decision ->

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,3 +678,12 @@ private data class CompletedContinuation(
678678
onCancellation?.let { cont.callOnCancellation(it, cause) }
679679
}
680680
}
681+
682+
// Same as ChildHandleNode, but for cancellable continuation
683+
private class ChildContinuation(
684+
@JvmField val child: CancellableContinuationImpl<*>
685+
) : JobCancellingNode() {
686+
override fun invoke(cause: Throwable?) {
687+
child.parentCancelled(child.getContinuationCancellationCause(job))
688+
}
689+
}

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
121121
*/
122122

123123
// Note: use shared objects while we have no listeners
124-
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
125124
private val _state = atomic<Any?>(if (active) EMPTY_ACTIVE else EMPTY_NEW)
126125

127126
private val _parentHandle = atomic<ChildHandle?>(null)
@@ -1439,22 +1438,10 @@ private class InvokeOnCancelling(
14391438
}
14401439
}
14411440

1442-
internal class ChildHandleNode(
1441+
private class ChildHandleNode(
14431442
@JvmField val childJob: ChildJob
14441443
) : JobCancellingNode(), ChildHandle {
14451444
override val parent: Job get() = job
14461445
override fun invoke(cause: Throwable?) = childJob.parentCancelled(job)
14471446
override fun childCancelled(cause: Throwable): Boolean = job.childCancelled(cause)
14481447
}
1449-
1450-
// Same as ChildHandleNode, but for cancellable continuation
1451-
@PublishedApi
1452-
internal class ChildContinuation(
1453-
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
1454-
@JvmField val child: CancellableContinuationImpl<*>
1455-
) : JobCancellingNode() {
1456-
override fun invoke(cause: Throwable?) {
1457-
child.parentCancelled(child.getContinuationCancellationCause(job))
1458-
}
1459-
}
1460-

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ private val UNDEFINED = Symbol("UNDEFINED")
99
@JvmField
1010
internal val REUSABLE_CLAIMED = Symbol("REUSABLE_CLAIMED")
1111

12-
@PublishedApi
1312
internal class DispatchedContinuation<in T>(
1413
@JvmField internal val dispatcher: CoroutineDispatcher,
15-
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
1614
@JvmField val continuation: Continuation<T>
1715
) : DispatchedTask<T>(MODE_UNINITIALIZED), CoroutineStackFrame, Continuation<T> by continuation {
1816
@JvmField

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ internal const val MODE_UNINITIALIZED = -1
4343
internal val Int.isCancellableMode get() = this == MODE_CANCELLABLE || this == MODE_CANCELLABLE_REUSABLE
4444
internal val Int.isReusableMode get() = this == MODE_CANCELLABLE_REUSABLE
4545

46-
@PublishedApi
4746
internal abstract class DispatchedTask<in T> internal constructor(
48-
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
49-
@JvmField public var resumeMode: Int
47+
@JvmField var resumeMode: Int
5048
) : SchedulerTask() {
5149
internal abstract val delegate: Continuation<T>
5250

kotlinx-coroutines-core/jvm/src/debug/internal/DebugCoroutineInfoImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ internal class DebugCoroutineInfoImpl internal constructor(
3030
*/
3131
private val _context = WeakReference(context)
3232
public val context: CoroutineContext? // can be null when the coroutine was already garbage-collected
33+
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
3334
get() = _context.get()
3435

36+
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
3537
public val creationStackTrace: List<StackTraceElement> get() = creationStackTrace()
3638

3739
/**

kotlinx-coroutines-core/jvm/src/debug/internal/StackTraceFrame.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import kotlin.coroutines.jvm.internal.*
55
/**
66
* A stack-trace represented as [CoroutineStackFrame].
77
*/
8-
@PublishedApi
9-
internal class StackTraceFrame internal constructor(
8+
internal class StackTraceFrame(
109
override val callerFrame: CoroutineStackFrame?,
11-
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
12-
@JvmField public val stackTraceElement: StackTraceElement
10+
private val stackTraceElement: StackTraceElement
1311
) : CoroutineStackFrame {
1412
override fun getStackTraceElement(): StackTraceElement = stackTraceElement
1513
}

kotlinx-coroutines-core/jvm/src/scheduling/Tasks.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ internal val NonBlockingContext: TaskContext = TaskContextImpl(TASK_NON_BLOCKING
7575
@JvmField
7676
internal val BlockingContext: TaskContext = TaskContextImpl(TASK_PROBABLY_BLOCKING)
7777

78-
@PublishedApi
79-
internal abstract class Task internal constructor(
80-
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
78+
internal abstract class Task(
8179
@JvmField var submissionTime: Long,
82-
// Used by the IDEA debugger via reflection and must be kept binary-compatible, see KTIJ-24102
83-
@JvmField internal var taskContext: TaskContext
80+
@JvmField var taskContext: TaskContext
8481
) : Runnable {
8582
internal constructor() : this(0, NonBlockingContext)
8683
internal inline val mode: Int get() = taskContext.taskMode // TASK_XXX

kotlinx-coroutines-core/jvm/test/ReusableCancellableContinuationTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ class ReusableCancellableContinuationTest : TestBase() {
210210
for (value in channel) {
211211
delay(1)
212212
}
213-
FieldWalker.assertReachableCount(1, coroutineContext[Job]) { it is ChildContinuation }
213+
FieldWalker.assertReachableCount(1, coroutineContext[Job]) {
214+
// could be `it is ChildContinuation` if `ChildContinuation` wasn't private
215+
it::class.simpleName == "ChildContinuation"
216+
}
214217
}
215218
}

0 commit comments

Comments
 (0)