diff --git a/kotlinx-coroutines-core/common/src/CompletionState.kt b/kotlinx-coroutines-core/common/src/CompletionState.kt index b9042874cd..43330af460 100644 --- a/kotlinx-coroutines-core/common/src/CompletionState.kt +++ b/kotlinx-coroutines-core/common/src/CompletionState.kt @@ -40,7 +40,7 @@ internal data class CompletedWithCancellation( * or artificial [CancellationException] if no cause was provided */ internal open class CompletedExceptionally( - @JvmField public val cause: Throwable, + @JvmField val cause: Throwable, handled: Boolean = false ) { private val _handled = atomic(handled) diff --git a/kotlinx-coroutines-core/common/src/Yield.kt b/kotlinx-coroutines-core/common/src/Yield.kt index 98e210412b..db3bfa5359 100644 --- a/kotlinx-coroutines-core/common/src/Yield.kt +++ b/kotlinx-coroutines-core/common/src/Yield.kt @@ -5,7 +5,6 @@ package kotlinx.coroutines import kotlinx.coroutines.internal.* -import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* /** diff --git a/kotlinx-coroutines-core/common/src/channels/Channel.kt b/kotlinx-coroutines-core/common/src/channels/Channel.kt index b8ee0be366..5ceb515f95 100644 --- a/kotlinx-coroutines-core/common/src/channels/Channel.kt +++ b/kotlinx-coroutines-core/common/src/channels/Channel.kt @@ -448,7 +448,6 @@ public value class ChannelResult override fun toString(): String = "Closed($cause)" } - @Suppress("NOTHING_TO_INLINE") @InternalCoroutinesApi public companion object { private val failed = Failed() @@ -512,7 +511,6 @@ public inline fun ChannelResult.onFailure(action: (exception: Throwable?) contract { callsInPlace(action, InvocationKind.AT_MOST_ONCE) } - @Suppress("UNCHECKED_CAST") if (holder is ChannelResult.Failed) action(exceptionOrNull()) return this } @@ -531,7 +529,6 @@ public inline fun ChannelResult.onClosed(action: (exception: Throwable?) contract { callsInPlace(action, InvocationKind.AT_MOST_ONCE) } - @Suppress("UNCHECKED_CAST") if (holder is ChannelResult.Closed) action(exceptionOrNull()) return this } diff --git a/kotlinx-coroutines-core/common/src/channels/ChannelCoroutine.kt b/kotlinx-coroutines-core/common/src/channels/ChannelCoroutine.kt index 57b2797de6..3fcf388a67 100644 --- a/kotlinx-coroutines-core/common/src/channels/ChannelCoroutine.kt +++ b/kotlinx-coroutines-core/common/src/channels/ChannelCoroutine.kt @@ -7,7 +7,6 @@ package kotlinx.coroutines.channels import kotlinx.coroutines.* import kotlin.coroutines.* -@Suppress("DEPRECATION") internal open class ChannelCoroutine( parentContext: CoroutineContext, protected val _channel: Channel, @@ -17,6 +16,7 @@ internal open class ChannelCoroutine( val channel: Channel get() = this + @Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x") override fun cancel() { cancelInternal(defaultCancellationException()) } diff --git a/kotlinx-coroutines-core/common/src/channels/Channels.common.kt b/kotlinx-coroutines-core/common/src/channels/Channels.common.kt index a78e2f186d..ac2e4cf6f0 100644 --- a/kotlinx-coroutines-core/common/src/channels/Channels.common.kt +++ b/kotlinx-coroutines-core/common/src/channels/Channels.common.kt @@ -11,7 +11,6 @@ package kotlinx.coroutines.channels import kotlinx.coroutines.* import kotlinx.coroutines.selects.* import kotlin.contracts.* -import kotlin.coroutines.* import kotlin.jvm.* internal const val DEFAULT_CLOSE_MESSAGE = "Channel was closed" @@ -54,7 +53,6 @@ public inline fun BroadcastChannel.consume(block: ReceiveChannel.() ) // Warning since 1.5.0, ERROR in 1.6.0, HIDDEN in 1.7.0 @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public suspend fun ReceiveChannel.receiveOrNull(): E? { - @Suppress("DEPRECATION", "UNCHECKED_CAST") return (this as ReceiveChannel).receiveOrNull() } @@ -66,7 +64,6 @@ public suspend fun ReceiveChannel.receiveOrNull(): E? { level = DeprecationLevel.ERROR ) // Warning since 1.5.0, ERROR in 1.6.0, HIDDEN in 1.7.0 public fun ReceiveChannel.onReceiveOrNull(): SelectClause1 { - @Suppress("DEPRECATION", "UNCHECKED_CAST") return (this as ReceiveChannel).onReceiveOrNull } diff --git a/kotlinx-coroutines-core/common/src/flow/Channels.kt b/kotlinx-coroutines-core/common/src/flow/Channels.kt index 51ed4270c0..aed15913df 100644 --- a/kotlinx-coroutines-core/common/src/flow/Channels.kt +++ b/kotlinx-coroutines-core/common/src/flow/Channels.kt @@ -31,35 +31,10 @@ public suspend fun FlowCollector.emitAll(channel: ReceiveChannel): Uni private suspend fun FlowCollector.emitAllImpl(channel: ReceiveChannel, consume: Boolean) { ensureActive() - // Manually inlined "consumeEach" implementation that does not use iterator but works via "receiveCatching". - // It has smaller and more efficient spilled state which also allows to implement a manual kludge to - // fix retention of the last emitted value. - // See https://youtrack.jetbrains.com/issue/KT-16222 - // See https://github.com/Kotlin/kotlinx.coroutines/issues/1333 var cause: Throwable? = null try { - while (true) { - // :KLUDGE: This "run" call is resolved to an extension function "run" and forces the size of - // spilled state to increase by an additional slot, so there are 4 object local variables spilled here - // which makes the size of spill state equal to the 4 slots that are spilled around subsequent "emit" - // call, ensuring that the previously emitted value is not retained in the state while receiving - // the next one. - // L$0 <- this - // L$1 <- channel - // L$2 <- cause - // L$3 <- this$run (actually equal to this) - val result = run { channel.receiveCatching() } - if (result.isClosed) { - result.exceptionOrNull()?.let { throw it } - break // returns normally when result.closeCause == null - } - // result is spilled here to the coroutine state and retained after the call, even though - // it is not actually needed in the next loop iteration. - // L$0 <- this - // L$1 <- channel - // L$2 <- cause - // L$3 <- result - emit(result.getOrThrow()) + for (element in channel) { + emit(element) } } catch (e: Throwable) { cause = e diff --git a/kotlinx-coroutines-core/common/src/flow/internal/AbstractSharedFlow.kt b/kotlinx-coroutines-core/common/src/flow/internal/AbstractSharedFlow.kt index e717717cc4..d263d61227 100644 --- a/kotlinx-coroutines-core/common/src/flow/internal/AbstractSharedFlow.kt +++ b/kotlinx-coroutines-core/common/src/flow/internal/AbstractSharedFlow.kt @@ -19,7 +19,6 @@ internal abstract class AbstractSharedFlowSlot { } internal abstract class AbstractSharedFlow> : SynchronizedObject() { - @Suppress("UNCHECKED_CAST") protected var slots: Array? = null // allocated when needed private set protected var nCollectors = 0 // number of allocated (!free) slots diff --git a/kotlinx-coroutines-core/common/src/flow/internal/Combine.kt b/kotlinx-coroutines-core/common/src/flow/internal/Combine.kt index c924c09025..63ea55a585 100644 --- a/kotlinx-coroutines-core/common/src/flow/internal/Combine.kt +++ b/kotlinx-coroutines-core/common/src/flow/internal/Combine.kt @@ -1,7 +1,7 @@ /* * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -@file:Suppress("UNCHECKED_CAST", "NON_APPLICABLE_CALL_FOR_BUILDER_INFERENCE") // KT-32203 +@file:Suppress("UNCHECKED_CAST") // KT-32203 package kotlinx.coroutines.flow.internal @@ -9,9 +9,6 @@ import kotlinx.coroutines.* import kotlinx.coroutines.channels.* import kotlinx.coroutines.flow.* import kotlinx.coroutines.internal.* -import kotlin.coroutines.* -import kotlin.coroutines.intrinsics.* - private typealias Update = IndexedValue @PublishedApi diff --git a/kotlinx-coroutines-core/common/src/flow/terminal/Count.kt b/kotlinx-coroutines-core/common/src/flow/terminal/Count.kt index 5eb99fc8ef..a15567e222 100644 --- a/kotlinx-coroutines-core/common/src/flow/terminal/Count.kt +++ b/kotlinx-coroutines-core/common/src/flow/terminal/Count.kt @@ -7,7 +7,6 @@ package kotlinx.coroutines.flow -import kotlinx.coroutines.* import kotlin.jvm.* /** diff --git a/kotlinx-coroutines-core/common/src/internal/Concurrent.common.kt b/kotlinx-coroutines-core/common/src/internal/Concurrent.common.kt index fb254a0ebc..6b42dd15db 100644 --- a/kotlinx-coroutines-core/common/src/internal/Concurrent.common.kt +++ b/kotlinx-coroutines-core/common/src/internal/Concurrent.common.kt @@ -18,7 +18,7 @@ internal expect fun subscriberList(): SubscribersList internal expect class ReentrantLock() { fun tryLock(): Boolean - fun unlock(): Unit + fun unlock() } internal expect inline fun ReentrantLock.withLock(action: () -> T): T diff --git a/kotlinx-coroutines-core/common/src/internal/DispatchedContinuation.kt b/kotlinx-coroutines-core/common/src/internal/DispatchedContinuation.kt index 63e0677fad..bb2bbf6d92 100644 --- a/kotlinx-coroutines-core/common/src/internal/DispatchedContinuation.kt +++ b/kotlinx-coroutines-core/common/src/internal/DispatchedContinuation.kt @@ -207,7 +207,6 @@ internal class DispatchedContinuation( // We inline it to save an entry on the stack in cases where it shows (unconfined dispatcher) // It is used only in Continuation.resumeCancellableWith - @Suppress("NOTHING_TO_INLINE") inline fun resumeCancellableWith( result: Result, noinline onCancellation: ((cause: Throwable) -> Unit)? @@ -235,7 +234,8 @@ internal class DispatchedContinuation( } } - @Suppress("NOTHING_TO_INLINE") + // inline here is to save us an entry on the stack for the sake of better stacktraces + inline fun resumeCancelled(state: Any?): Boolean { val job = context[Job] if (job != null && !job.isActive) { @@ -247,7 +247,6 @@ internal class DispatchedContinuation( return false } - @Suppress("NOTHING_TO_INLINE") // we need it inline to save us an entry on the stack inline fun resumeUndispatchedWith(result: Result) { withContinuationContext(continuation, countOrElement) { continuation.resumeWith(result) diff --git a/kotlinx-coroutines-core/common/src/selects/SelectUnbiased.kt b/kotlinx-coroutines-core/common/src/selects/SelectUnbiased.kt index 0b68e411d5..5329a15a0f 100644 --- a/kotlinx-coroutines-core/common/src/selects/SelectUnbiased.kt +++ b/kotlinx-coroutines-core/common/src/selects/SelectUnbiased.kt @@ -58,7 +58,6 @@ internal open class UnbiasedSelectImplementation(context: CoroutineContext) : return super.doSelect() } - @Suppress("UNCHECKED_CAST") private fun shuffleAndRegisterClauses() = try { clausesToRegister.shuffle() clausesToRegister.forEach { it.register() } diff --git a/kotlinx-coroutines-core/common/src/selects/WhileSelect.kt b/kotlinx-coroutines-core/common/src/selects/WhileSelect.kt index 98a9c67238..ccda6568ae 100644 --- a/kotlinx-coroutines-core/common/src/selects/WhileSelect.kt +++ b/kotlinx-coroutines-core/common/src/selects/WhileSelect.kt @@ -28,5 +28,5 @@ import kotlinx.coroutines.* */ @ExperimentalCoroutinesApi public suspend inline fun whileSelect(crossinline builder: SelectBuilder.() -> Unit) { - while(select(builder)) {} + while(select(builder)) { /* do nothing */ } } diff --git a/kotlinx-coroutines-core/common/src/sync/Mutex.kt b/kotlinx-coroutines-core/common/src/sync/Mutex.kt index 945bac07b5..40e4308f4e 100644 --- a/kotlinx-coroutines-core/common/src/sync/Mutex.kt +++ b/kotlinx-coroutines-core/common/src/sync/Mutex.kt @@ -165,7 +165,7 @@ internal open class MutexImpl(locked: Boolean) : SemaphoreImpl(1, if (locked) 1 lockSuspend(owner) } - private suspend fun lockSuspend(owner: Any?) = suspendCancellableCoroutineReusable { cont -> + private suspend fun lockSuspend(owner: Any?) = suspendCancellableCoroutineReusable { cont -> val contWithOwner = CancellableContinuationWithOwner(cont, owner) acquire(contWithOwner) }