Skip to content

Commit 179f142

Browse files
authored
Add build parameter to build coroutines with JVM IR compiler (#2389)
* Add build parameters to enable JVM IR and disable native targets * enable_jvm_ir enables JVM IR compiler * disable_native_targets disables native targets in train builds * enable_jvm_ir_api_check enables JVM IR API check (works only if enable_jvm_ir is set) * Fix "Return type must be specified in explicit API mode" in 1.4.20
1 parent 81577b2 commit 179f142

File tree

8 files changed

+58
-11
lines changed

8 files changed

+58
-11
lines changed

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ buildscript {
3333
throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
3434
}
3535
}
36+
// These three flags are enabled in train builds for JVM IR compiler testing
37+
ext.jvm_ir_enabled = rootProject.properties['enable_jvm_ir'] != null
38+
ext.jvm_ir_api_check_enabled = rootProject.properties['enable_jvm_ir_api_check'] != null
39+
ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null
3640

3741
// Determine if any project dependency is using a snapshot version
3842
ext.using_snapshot_version = build_snapshot_train
@@ -323,3 +327,12 @@ knit {
323327
}
324328

325329
knitPrepare.dependsOn getTasksByName("dokka", true)
330+
331+
// Disable binary compatibility check for JVM IR compiler output by default
332+
if (jvm_ir_enabled) {
333+
subprojects { project ->
334+
configure(tasks.matching { it.name == "apiCheck" }) {
335+
enabled = enabled && jvm_ir_api_check_enabled
336+
}
337+
}
338+
}

gradle/compile-jvm-multiplatform.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ sourceCompatibility = 1.6
66
targetCompatibility = 1.6
77

88
kotlin {
9-
targets {
10-
fromPreset(presets.jvm, 'jvm')
9+
jvm {
10+
if (rootProject.ext.jvm_ir_enabled) {
11+
compilations.all {
12+
kotlinOptions.useIR = true
13+
}
14+
}
1115
}
1216
sourceSets {
1317
jvmTest.dependencies {

gradle/compile-jvm.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ apply plugin: 'org.jetbrains.kotlin.jvm'
99
sourceCompatibility = 1.6
1010
targetCompatibility = 1.6
1111

12+
if (rootProject.ext.jvm_ir_enabled) {
13+
kotlin.target.compilations.all {
14+
kotlinOptions.useIR = true
15+
}
16+
}
17+
1218
dependencies {
1319
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
1420
// Workaround to make addSuppressed work in tests

kotlinx-coroutines-core/build.gradle

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
apply plugin: 'org.jetbrains.kotlin.multiplatform'
66
apply from: rootProject.file("gradle/compile-jvm-multiplatform.gradle")
77
apply from: rootProject.file("gradle/compile-common.gradle")
8+
9+
if (rootProject.ext.native_targets_enabled) {
10+
apply from: rootProject.file("gradle/compile-native-multiplatform.gradle")
11+
}
12+
813
apply from: rootProject.file("gradle/compile-js-multiplatform.gradle")
9-
apply from: rootProject.file("gradle/compile-native-multiplatform.gradle")
1014
apply from: rootProject.file('gradle/publish-npm-js.gradle')
1115

1216
/* ==========================================================================
@@ -52,8 +56,11 @@ static boolean isNativeDarwin(String name) { return ["ios", "macos", "tvos", "wa
5256
static boolean isNativeOther(String name) { return ["linux", "mingw"].any { name.startsWith(it) } }
5357

5458
defineSourceSet("concurrent", ["common"]) { it in ["jvm", "native"] }
55-
defineSourceSet("nativeDarwin", ["native"]) { isNativeDarwin(it) }
56-
defineSourceSet("nativeOther", ["native"]) { isNativeOther(it) }
59+
60+
if (rootProject.ext.native_targets_enabled) {
61+
defineSourceSet("nativeDarwin", ["native"]) { isNativeDarwin(it) }
62+
defineSourceSet("nativeOther", ["native"]) { isNativeOther(it) }
63+
}
5764

5865
/* ========================================================================== */
5966

@@ -129,7 +136,7 @@ def configureNativeSourceSetPreset(name, preset) {
129136
}
130137

131138
// :KLUDGE: Idea.active: Configure platform libraries for native source sets when working in IDEA
132-
if (Idea.active) {
139+
if (Idea.active && rootProject.ext.native_targets_enabled) {
133140
def manager = project.ext.hostManager
134141
def linuxPreset = kotlin.presets.linuxX64
135142
def macosPreset = kotlin.presets.macosX64
@@ -183,6 +190,13 @@ jvmTest {
183190
exclude '**/*StressTest.*'
184191
}
185192
systemProperty 'kotlinx.coroutines.scheduler.keep.alive.sec', '100000' // any unpark problem hangs test
193+
194+
// TODO: JVM IR generates different stacktrace so temporary disable stacktrace tests
195+
if (rootProject.ext.jvm_ir_enabled) {
196+
filter {
197+
excludeTestsMatching('kotlinx.coroutines.exceptions.StackTraceRecovery*')
198+
}
199+
}
186200
}
187201

188202
jvmJar {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal const val MODE_ATOMIC = 0
2323
* **DO NOT CHANGE THE CONSTANT VALUE**. It is being into the user code from [suspendCancellableCoroutine].
2424
*/
2525
@PublishedApi
26-
internal const val MODE_CANCELLABLE = 1
26+
internal const val MODE_CANCELLABLE: Int = 1
2727

2828
/**
2929
* Cancellable dispatch mode for [suspendCancellableCoroutineReusable].

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal class UnbiasedSelectBuilderImpl<in R>(uCont: Continuation<R>) :
3636
val clauses = arrayListOf<() -> Unit>()
3737

3838
@PublishedApi
39-
internal fun handleBuilderException(e: Throwable) = instance.handleBuilderException(e)
39+
internal fun handleBuilderException(e: Throwable): Unit = instance.handleBuilderException(e)
4040

4141
@PublishedApi
4242
internal fun initSelectResult(): Any? {

kotlinx-coroutines-core/jvm/src/internal/LockFreeLinkedList.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import kotlinx.coroutines.*
1111
private typealias Node = LockFreeLinkedListNode
1212

1313
@PublishedApi
14-
internal const val UNDECIDED = 0
14+
internal const val UNDECIDED: Int = 0
1515

1616
@PublishedApi
17-
internal const val SUCCESS = 1
17+
internal const val SUCCESS: Int = 1
1818

1919
@PublishedApi
20-
internal const val FAILURE = 2
20+
internal const val FAILURE: Int = 2
2121

2222
@PublishedApi
2323
internal val CONDITION_FALSE: Any = Symbol("CONDITION_FALSE")

kotlinx-coroutines-debug/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ dependencies {
2828
api "net.java.dev.jna:jna-platform:$jna_version"
2929
}
3030

31+
// TODO: JVM IR generates different stacktrace so temporary disable stacktrace tests
32+
if (rootProject.ext.jvm_ir_enabled) {
33+
tasks.named('test', Test) {
34+
filter {
35+
// excludeTest('kotlinx.coroutines.debug.CoroutinesDumpTest', 'testCreationStackTrace')
36+
excludeTestsMatching('kotlinx.coroutines.debug.DebugProbesTest')
37+
}
38+
}
39+
}
40+
3141
jar {
3242
manifest {
3343
attributes "Premain-Class": "kotlinx.coroutines.debug.AgentPremain"

0 commit comments

Comments
 (0)