Skip to content

Update Kotlin to 2.1.0 #4284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Kotlin
version=1.9.0-SNAPSHOT
group=org.jetbrains.kotlinx
kotlin_version=2.0.0
kotlin_language_version=2.0
kotlin_version=2.1.0
kotlin_language_version=2.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this line do anything useful today other than accidentally disabling the "warnings are errors" flag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR release team uses it, but not sure. Will figure out separately

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The release team may override this property, this I get, but do we need to keep it in gradle.properties?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for the sake of having "release team" branch and mainline having the same configuration and catching the same warnings/errors.

# DO NOT rename this property without adapting kotlinx.train build chain:
atomicfu_version=0.26.1

Expand Down Expand Up @@ -43,7 +43,6 @@ kotlin.native.ignoreDisabledTargets=true
# TODO: Remove once KT-37187 is fixed
org.gradle.jvmargs=-Xmx3g

kotlin.mpp.stability.nowarn=true
kotlinx.atomicfu.enableJvmIrTransformation=true
# When the flag below is set to `true`, AtomicFU cannot process
# usages of `moveForward` in `ConcurrentLinkedList.kt` correctly.
Expand Down
2 changes: 1 addition & 1 deletion integration-testing/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin_version=2.0.0
kotlin_version=2.1.0
coroutines_version=1.9.0-SNAPSHOT
asm_version=9.3

Expand Down
4 changes: 4 additions & 0 deletions kotlinx-coroutines-core/common/src/Builders.common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public suspend fun <T> withContext(
// FAST PATH #1 -- new context is the same as the old one
if (newContext === oldContext) {
val coroutine = ScopeCoroutine(newContext, uCont)
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one (an one on the contract definition) is annoying, I'll report it to the team

return@sc coroutine.startUndispatchedOrReturn(coroutine, block)
}
// FAST PATH #2 -- the new dispatcher is the same as the old one (something else changed)
Expand All @@ -161,11 +162,14 @@ public suspend fun <T> withContext(
val coroutine = UndispatchedCoroutine(newContext, uCont)
// There are changes in the context, so this thread needs to be updated
withCoroutineContext(coroutine.context, null) {
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
return@sc coroutine.startUndispatchedOrReturn(coroutine, block)
}
}
// SLOW PATH -- use new dispatcher
val coroutine = DispatchedCoroutine(newContext, uCont)
// Contract is preserved, invoked immediately or throws
@Suppress("LEAKED_IN_PLACE_LAMBDA")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer that the comment is to the right of Suppress: typically, the comment above a line with a suppression refers to the line itself.

block.startCoroutineCancellable(coroutine, coroutine)
coroutine.getResult()
}
Expand Down
2 changes: 2 additions & 0 deletions kotlinx-coroutines-core/common/src/CoroutineScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ public suspend fun <R> coroutineScope(block: suspend CoroutineScope.() -> R): R
}
return suspendCoroutineUninterceptedOrReturn { uCont ->
val coroutine = ScopeCoroutine(uCont.context, uCont)
// Contract is preserved, invoked immediately or throws
@Suppress("LEAKED_IN_PLACE_LAMBDA")
coroutine.startUndispatchedOrReturn(coroutine, block)
}
}
Expand Down
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/common/src/Supervisor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public suspend fun <R> supervisorScope(block: suspend CoroutineScope.() -> R): R
}
return suspendCoroutineUninterceptedOrReturn { uCont ->
val coroutine = SupervisorCoroutine(uCont.context, uCont)
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
coroutine.startUndispatchedOrReturn(coroutine, block)
}
}
Expand Down
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/common/src/Timeout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineSco
}
if (timeMillis <= 0L) throw TimeoutCancellationException("Timed out immediately")
return suspendCoroutineUninterceptedOrReturn { uCont ->
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
setupTimeout(TimeoutCoroutine(timeMillis, uCont), block)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public inline fun <T> synchronized(lock: SynchronizedObject, block: () -> T): T
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
return synchronizedImpl(lock, block)
}
2 changes: 0 additions & 2 deletions kotlinx-coroutines-core/common/test/SupervisorTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913

package kotlinx.coroutines

import kotlinx.coroutines.testing.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE")

package kotlinx.coroutines.internal

import kotlinx.atomicfu.*
Expand Down
2 changes: 0 additions & 2 deletions kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package kotlinx.coroutines.internal
import java.util.*
import kotlin.concurrent.withLock as withLockJvm

@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias ReentrantLock = java.util.concurrent.locks.ReentrantLock

internal actual inline fun <T> ReentrantLock.withLock(action: () -> T) = this.withLockJvm(action)

@Suppress("ACTUAL_WITHOUT_EXPECT") // Visibility
internal actual typealias WorkaroundAtomicReference<T> = java.util.concurrent.atomic.AtomicReference<T>

// BenignDataRace is OptionalExpectation and doesn't have to be here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package kotlinx.coroutines.internal

@Suppress("ACTUAL_WITHOUT_EXPECT") // Not the same name to WA the bug in the compiler
internal actual typealias IgnoreJreRequirement = org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
1 change: 0 additions & 1 deletion kotlinx-coroutines-core/jvm/src/internal/LocalAtomics.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package kotlinx.coroutines.internal

@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias LocalAtomicInt = java.util.concurrent.atomic.AtomicInteger
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ private fun StackTraceElement.elementWiseEquals(e: StackTraceElement): Boolean {
&& fileName == e.fileName && className == e.className
}

@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias CoroutineStackFrame = kotlin.coroutines.jvm.internal.CoroutineStackFrame

@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias StackTraceElement = java.lang.StackTraceElement

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
Expand Down
1 change: 0 additions & 1 deletion kotlinx-coroutines-core/jvm/src/internal/ThreadLocal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package kotlinx.coroutines.internal

import java.lang.ThreadLocal

@Suppress("ACTUAL_WITHOUT_EXPECT") // internal visibility
internal actual typealias CommonThreadLocal<T> = ThreadLocal<T>

internal actual fun<T> commonThreadLocal(name: Symbol): CommonThreadLocal<T> = ThreadLocal()
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/native/src/Builders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public actual fun <T> runBlocking(context: CoroutineContext, block: suspend Coro
var completed = false
ThreadLocalKeepAlive.addCheck { !completed }
try {
@Suppress("LEAKED_IN_PLACE_LAMBDA") // Contract is preserved, invoked immediately or throws
coroutine.start(CoroutineStart.DEFAULT, coroutine, block)
return coroutine.joinBlocking()
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ private class MultiWorkerDispatcher(
*/
private val tasksAndWorkersCounter = atomic(0L)

@Suppress("NOTHING_TO_INLINE")
private inline fun Long.isClosed() = this and 1L == 1L
@Suppress("NOTHING_TO_INLINE")
private inline fun Long.hasTasks() = this >= 2
@Suppress("NOTHING_TO_INLINE")
private inline fun Long.hasWorkers() = this < 0

private fun workerRunLoop() = runBlocking {
Expand Down
2 changes: 0 additions & 2 deletions kotlinx-coroutines-core/native/src/internal/Concurrent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import kotlinx.atomicfu.*
import kotlinx.cinterop.*
import kotlinx.atomicfu.locks.withLock as withLock2

@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias ReentrantLock = kotlinx.atomicfu.locks.SynchronizedObject

internal actual inline fun <T> ReentrantLock.withLock(action: () -> T): T = this.withLock2(action)

internal actual fun <E> identitySet(expectedSize: Int): MutableSet<E> = HashSet()

@Suppress("ACTUAL_WITHOUT_EXPECT") // This suppress can be removed in 2.0: KT-59355
internal actual typealias BenignDataRace = kotlin.concurrent.Volatile

internal actual class WorkaroundAtomicReference<V> actual constructor(value: V) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal actual interface CoroutineStackFrame {
public actual fun getStackTraceElement(): StackTraceElement?
}

@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias StackTraceElement = Any

internal actual fun Throwable.initCause(cause: Throwable) {
Expand Down
2 changes: 0 additions & 2 deletions kotlinx-coroutines-test/common/src/TestBuilders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import kotlin.time.Duration.Companion.seconds
* with a [TestResult] is to immediately `return` it from a test.
* - Don't nest functions returning a [TestResult].
*/
@Suppress("NO_ACTUAL_FOR_EXPECT")
public expect class TestResult

/**
Expand Down Expand Up @@ -409,7 +408,6 @@ public fun TestScope.runTest(
/**
* Runs [testProcedure], creating a [TestResult].
*/
@Suppress("NO_ACTUAL_FOR_EXPECT") // actually suppresses `TestResult`
internal expect fun createTestResult(testProcedure: suspend CoroutineScope.() -> Unit): TestResult

/** A coroutine context element indicating that the coroutine is running inside `runTest`. */
Expand Down
1 change: 0 additions & 1 deletion kotlinx-coroutines-test/common/src/TestScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ internal class TestScopeImpl(context: CoroutineContext) :
}

/** Use the knowledge that any [TestScope] that we receive is necessarily a [TestScopeImpl]. */
@Suppress("NO_ELSE_IN_WHEN") // TODO: a problem with `sealed` in MPP not allowing total pattern-matching
internal fun TestScope.asSpecificImplementation(): TestScopeImpl = when (this) {
is TestScopeImpl -> this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import kotlinx.coroutines.*
/**
* A variant of [SupervisorJob] that additionally notifies about child failures via a callback.
*/
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "CANNOT_OVERRIDE_INVISIBLE_MEMBER")
internal class ReportingSupervisorJob(parent: Job? = null, val onChildCancellation: (Throwable) -> Unit) :
JobImpl(parent) {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
internal class ReportingSupervisorJob(
parent: Job? = null,
val onChildCancellation: (Throwable) -> Unit
) : JobImpl(parent) {
override fun childCancelled(cause: Throwable): Boolean =
try {
onChildCancellation(cause)
Expand Down
1 change: 0 additions & 1 deletion kotlinx-coroutines-test/native/src/TestBuilders.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kotlinx.coroutines.test
import kotlinx.coroutines.*

@Suppress("ACTUAL_WITHOUT_EXPECT")
public actual typealias TestResult = Unit

internal actual fun createTestResult(testProcedure: suspend CoroutineScope.() -> Unit) {
Expand Down