Skip to content

Commit 1bdbb3e

Browse files
committed
Cleanup: get rid of workarounds, cleanup guide, suppress/fix compilation warnings
1 parent e6e8239 commit 1bdbb3e

File tree

13 files changed

+24
-34
lines changed

13 files changed

+24
-34
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, ChildJob, Par
393393
public final override fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle =
394394
invokeOnCompletion(onCancelling = false, invokeImmediately = true, handler = handler)
395395

396-
// todo: non-final as a workaround for KT-21968, should be final in the future
397-
public override fun invokeOnCompletion(
396+
public final override fun invokeOnCompletion(
398397
onCancelling: Boolean,
399398
invokeImmediately: Boolean,
400399
handler: CompletionHandler

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,16 @@ public suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineSco
5050
public suspend fun <T> withTimeoutOrNull(timeMillis: Long, block: suspend CoroutineScope.() -> T): T? {
5151
if (timeMillis <= 0L) return null
5252

53-
// Workaround for K/N bug
54-
val array = arrayOfNulls<TimeoutCoroutine<T?, T?>>(1)
53+
var coroutine: TimeoutCoroutine<T?, T?>? = null
5554
try {
5655
return suspendCoroutineUninterceptedOrReturn { uCont ->
5756
val timeoutCoroutine = TimeoutCoroutine(timeMillis, uCont)
58-
array[0] = timeoutCoroutine
57+
coroutine = timeoutCoroutine
5958
setupTimeout<T?, T?>(timeoutCoroutine, block)
6059
}
6160
} catch (e: TimeoutCancellationException) {
6261
// Return null iff it's our exception, otherwise propagate it upstream (e.g. in case of nested withTimeouts)
63-
if (e.coroutine === array[0]) {
62+
if (e.coroutine === coroutine) {
6463
return null
6564
}
6665
throw e

common/kotlinx-coroutines-core-common/src/channels/AbstractChannel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ internal abstract class AbstractSendChannel<E> : SendChannel<E> {
265265
if (handler !== null && handler !== HANDLER_INVOKED
266266
&& onCloseHandler.compareAndSet(handler, HANDLER_INVOKED)) {
267267
// CAS failed -> concurrent invokeOnClose() invoked handler
268+
@Suppress("UNCHECKED_CAST")
268269
(handler as Handler)(cause)
269270
}
270271
}

common/kotlinx-coroutines-core-common/src/channels/ConflatedBroadcastChannel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public class ConflatedBroadcastChannel<E>() : BroadcastChannel<E> {
181181
val handler = onCloseHandler.value
182182
if (handler !== null && handler !== HANDLER_INVOKED
183183
&& onCloseHandler.compareAndSet(handler, HANDLER_INVOKED)) {
184+
@Suppress("UNCHECKED_CAST")
184185
(handler as Handler)(cause)
185186
}
186187
}

common/kotlinx-coroutines-core-common/test/AsyncTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
5+
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "UNREACHABLE_CODE") // KT-21913
66

77
package kotlinx.coroutines
88

common/kotlinx-coroutines-core-common/test/CoroutineExceptionHandlerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CoroutineExceptionHandlerTest : TestBase() {
3131
@Test
3232
fun testCompletableDeferred() = runTest {
3333
expect(1)
34-
val handler = CoroutineExceptionHandler { _, ex ->
34+
val handler = CoroutineExceptionHandler { _, _ ->
3535
expectUnreached()
3636
}
3737
val parent = CompletableDeferred<Unit>()

common/kotlinx-coroutines-core-common/test/CoroutineScopeTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("UNREACHABLE_CODE")
6+
57
package kotlinx.coroutines
68

79
import kotlinx.coroutines.internal.*
@@ -146,7 +148,7 @@ class CoroutineScopeTest : TestBase() {
146148
expect(3)
147149
throw TestException1()
148150
}
149-
val two = async<Int>(start = CoroutineStart.ATOMIC) {
151+
val two = async(start = CoroutineStart.ATOMIC) {
150152
try {
151153
expect(4)
152154
delay(Long.MAX_VALUE) // Emulates very long computation

common/kotlinx-coroutines-core-common/test/WithTimeoutTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
44
*/
55

6-
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
6+
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "UNREACHABLE_CODE") // KT-21913
77

88
package kotlinx.coroutines
99

common/kotlinx-coroutines-core-common/test/channels/ConflatedBroadcastChannelTest.kt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ConflatedBroadcastChannelTest : TestBase() {
3636
fun testBasicScenario() = runTest {
3737
expect(1)
3838
val broadcast = ConflatedBroadcastChannel<String>()
39-
assertTrue(exceptionFromNotInline { broadcast.value } is IllegalStateException)
39+
assertTrue(exceptionFrom { broadcast.value } is IllegalStateException)
4040
assertNull(broadcast.valueOrNull)
4141

4242
launch(start = CoroutineStart.UNDISPATCHED) {
@@ -88,7 +88,7 @@ class ConflatedBroadcastChannelTest : TestBase() {
8888
yield() // to second receiver
8989
expect(18)
9090
broadcast.close()
91-
assertTrue(exceptionFromNotInline { broadcast.value } is IllegalStateException)
91+
assertTrue(exceptionFrom { broadcast.value } is IllegalStateException)
9292
assertNull(broadcast.valueOrNull)
9393
expect(19)
9494
yield() // to second receiver
@@ -117,22 +117,12 @@ class ConflatedBroadcastChannelTest : TestBase() {
117117
finish(7)
118118
}
119119

120-
inline fun exceptionFrom(block: () -> Unit): Throwable? {
121-
try {
120+
private inline fun exceptionFrom(block: () -> Unit): Throwable? {
121+
return try {
122122
block()
123-
return null
123+
null
124124
} catch (e: Throwable) {
125-
return e
126-
}
127-
}
128-
129-
// Workaround for KT-23921
130-
fun exceptionFromNotInline(block: () -> Unit): Throwable? {
131-
try {
132-
block()
133-
return null
134-
} catch (e: Throwable) {
135-
return e
125+
e
136126
}
137127
}
138128
}

core/kotlinx-coroutines-core/src/internal/LockFreeMPSCQueue.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package kotlinx.coroutines.internal
66

77
import kotlinx.atomicfu.*
8-
import kotlinx.coroutines.*
98
import java.util.concurrent.atomic.*
109

1110
private typealias Core<E> = LockFreeMPSCQueueCore<E>
@@ -59,13 +58,12 @@ internal class LockFreeMPSCQueue<E : Any> {
5958
* *Note: This queue is NOT linearizable. It provides only quiescent consistency for its operations.*
6059
*
6160
* @see LockFreeMPSCQueue
62-
* @suppress **This is unstable API and it is subject to change.**
6361
*/
6462
internal class LockFreeMPSCQueueCore<E : Any>(private val capacity: Int) {
6563
private val mask = capacity - 1
6664
private val _next = atomic<Core<E>?>(null)
6765
private val _state = atomic(0L)
68-
private val array = AtomicReferenceArray<Any?>(capacity);
66+
private val array = AtomicReferenceArray<Any?>(capacity)
6967

7068
init {
7169
check(mask <= MAX_CAPACITY_MASK)
@@ -148,6 +146,7 @@ internal class LockFreeMPSCQueueCore<E : Any>(private val capacity: Int) {
148146
// Slow-path for remove in case of interference
149147
var cur = this
150148
while (true) {
149+
@Suppress("UNUSED_VALUE")
151150
cur = cur.removeSlowPath(head, newHead) ?: return element
152151
}
153152
}

0 commit comments

Comments
 (0)