Skip to content

Commit 1900c9c

Browse files
committed
Merge remote-tracking branch 'origin/develop' into shared-flow
2 parents a0f7666 + 8773a26 commit 1900c9c

File tree

84 files changed

+2304
-764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2304
-764
lines changed

benchmarks/src/jmh/kotlin/benchmarks/tailcall/SimpleChannel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ class NonCancellableChannel : SimpleChannel() {
7070
}
7171

7272
class CancellableChannel : SimpleChannel() {
73-
override suspend fun suspendReceive(): Int = suspendAtomicCancellableCoroutine {
73+
override suspend fun suspendReceive(): Int = suspendCancellableCoroutine {
7474
consumer = it.intercepted()
7575
COROUTINE_SUSPENDED
7676
}
7777

78-
override suspend fun suspendSend(element: Int) = suspendAtomicCancellableCoroutine<Unit> {
78+
override suspend fun suspendSend(element: Int) = suspendCancellableCoroutine<Unit> {
7979
enqueuedValue = element
8080
producer = it.intercepted()
8181
COROUTINE_SUSPENDED
@@ -84,13 +84,13 @@ class CancellableChannel : SimpleChannel() {
8484

8585
class CancellableReusableChannel : SimpleChannel() {
8686
@Suppress("INVISIBLE_MEMBER")
87-
override suspend fun suspendReceive(): Int = suspendAtomicCancellableCoroutineReusable {
87+
override suspend fun suspendReceive(): Int = suspendCancellableCoroutineReusable {
8888
consumer = it.intercepted()
8989
COROUTINE_SUSPENDED
9090
}
9191

9292
@Suppress("INVISIBLE_MEMBER")
93-
override suspend fun suspendSend(element: Int) = suspendAtomicCancellableCoroutineReusable<Unit> {
93+
override suspend fun suspendSend(element: Int) = suspendCancellableCoroutineReusable<Unit> {
9494
enqueuedValue = element
9595
producer = it.intercepted()
9696
COROUTINE_SUSPENDED

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ buildscript {
8989

9090
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
9191

92-
// Hierarchical project structures are not fully supported in 1.3.7x MPP, enable conditionally for 1.4.x
93-
if (VersionNumber.parse(kotlin_version) > VersionNumber.parse("1.3.79")) {
92+
// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
93+
if (!Idea.active) {
9494
ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
9595
}
9696

gradle.properties

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ kotlin.js.compiler=both
3636
gradle_node_version=1.2.0
3737
node_version=8.9.3
3838
npm_version=5.7.1
39-
mocha_version=4.1.0
39+
mocha_version=6.2.2
4040
mocha_headless_chrome_version=1.8.2
41-
mocha_teamcity_reporter_version=2.2.2
42-
source_map_support_version=0.5.3
41+
mocha_teamcity_reporter_version=3.0.0
42+
source_map_support_version=0.5.16
43+
jsdom_version=15.2.1
44+
jsdom_global_version=3.0.2
4345

4446
# Settings
4547
kotlin.incremental.multiplatform=true
@@ -56,7 +58,6 @@ org.gradle.jvmargs=-Xmx2g
5658
# https://github.com/gradle/gradle/issues/11412
5759
systemProp.org.gradle.internal.publish.checksums.insecure=true
5860

59-
# This is commented out, and the property is set conditionally in build.gradle, because 1.3.71 doesn't work with it.
60-
# Once this property is set by default in new versions or 1.3.71 is dropped, either uncomment or remove this line.
61+
# todo:KLUDGE: This is commented out, and the property is set conditionally in build.gradle, because IDEA doesn't work with it.
6162
#kotlin.mpp.enableGranularSourceSetsMetadata=true
6263
kotlin.mpp.enableCompatibilityMetadataVariant=true

gradle/compile-native-multiplatform.gradle

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,24 @@ kotlin {
1313
}
1414

1515
targets {
16-
if (project.ext.ideaActive) {
17-
fromPreset(project.ext.ideaPreset, 'native')
18-
} else {
19-
addTarget(presets.linuxX64)
20-
addTarget(presets.iosArm64)
21-
addTarget(presets.iosArm32)
22-
addTarget(presets.iosX64)
23-
addTarget(presets.macosX64)
24-
addTarget(presets.mingwX64)
25-
addTarget(presets.tvosArm64)
26-
addTarget(presets.tvosX64)
27-
addTarget(presets.watchosArm32)
28-
addTarget(presets.watchosArm64)
29-
addTarget(presets.watchosX86)
30-
}
16+
addTarget(presets.linuxX64)
17+
addTarget(presets.iosArm64)
18+
addTarget(presets.iosArm32)
19+
addTarget(presets.iosX64)
20+
addTarget(presets.macosX64)
21+
addTarget(presets.mingwX64)
22+
addTarget(presets.tvosArm64)
23+
addTarget(presets.tvosX64)
24+
addTarget(presets.watchosArm32)
25+
addTarget(presets.watchosArm64)
26+
addTarget(presets.watchosX86)
3127
}
3228

3329
sourceSets {
3430
nativeMain { dependsOn commonMain }
35-
// Empty source set is required in order to have native tests task
36-
nativeTest {}
31+
nativeTest { dependsOn commonTest }
3732

38-
if (!project.ext.ideaActive) {
39-
configure(nativeMainSets) {
40-
dependsOn nativeMain
41-
}
42-
43-
configure(nativeTestSets) {
44-
dependsOn nativeTest
45-
}
46-
}
33+
configure(nativeMainSets) { dependsOn nativeMain }
34+
configure(nativeTestSets) { dependsOn nativeTest }
4735
}
4836
}

gradle/targets.gradle

Lines changed: 0 additions & 28 deletions
This file was deleted.

gradle/test-mocha-js.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) {
8686
task installDependenciesMochaJsdom(type: NpmTask, dependsOn: [npmInstall]) {
8787
args = ['install',
8888
"mocha@$mocha_version",
89-
'jsdom@15.2.1',
90-
'jsdom-global@3.0.2',
89+
"jsdom@$jsdom_version",
90+
"jsdom-global@$jsdom_global_version",
9191
"source-map-support@$source_map_support_version",
9292
'--no-save']
9393
if (project.hasProperty("teamcity")) args += ["mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public abstract interface class kotlinx/coroutines/CancellableContinuation : kot
4646
public abstract fun resumeUndispatched (Lkotlinx/coroutines/CoroutineDispatcher;Ljava/lang/Object;)V
4747
public abstract fun resumeUndispatchedWithException (Lkotlinx/coroutines/CoroutineDispatcher;Ljava/lang/Throwable;)V
4848
public abstract fun tryResume (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
49+
public abstract fun tryResume (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
4950
public abstract fun tryResumeWithException (Ljava/lang/Throwable;)Ljava/lang/Object;
5051
}
5152

@@ -56,6 +57,8 @@ public final class kotlinx/coroutines/CancellableContinuation$DefaultImpls {
5657

5758
public class kotlinx/coroutines/CancellableContinuationImpl : kotlin/coroutines/jvm/internal/CoroutineStackFrame, kotlinx/coroutines/CancellableContinuation {
5859
public fun <init> (Lkotlin/coroutines/Continuation;I)V
60+
public final fun callCancelHandler (Lkotlinx/coroutines/CancelHandler;Ljava/lang/Throwable;)V
61+
public final fun callOnCancellation (Lkotlin/jvm/functions/Function1;Ljava/lang/Throwable;)V
5962
public fun cancel (Ljava/lang/Throwable;)Z
6063
public fun completeResume (Ljava/lang/Object;)V
6164
public fun getCallerFrame ()Lkotlin/coroutines/jvm/internal/CoroutineStackFrame;
@@ -75,14 +78,12 @@ public class kotlinx/coroutines/CancellableContinuationImpl : kotlin/coroutines/
7578
public fun resumeWith (Ljava/lang/Object;)V
7679
public fun toString ()Ljava/lang/String;
7780
public fun tryResume (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
81+
public fun tryResume (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
7882
public fun tryResumeWithException (Ljava/lang/Throwable;)Ljava/lang/Object;
7983
}
8084

8185
public final class kotlinx/coroutines/CancellableContinuationKt {
8286
public static final fun disposeOnCancellation (Lkotlinx/coroutines/CancellableContinuation;Lkotlinx/coroutines/DisposableHandle;)V
83-
public static final fun suspendAtomicCancellableCoroutine (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
84-
public static final fun suspendAtomicCancellableCoroutine (ZLkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
85-
public static synthetic fun suspendAtomicCancellableCoroutine$default (ZLkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
8687
public static final fun suspendCancellableCoroutine (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8788
}
8889

@@ -272,10 +273,6 @@ public final class kotlinx/coroutines/DelayKt {
272273
public static final fun delay-p9JZ4hM (DLkotlin/coroutines/Continuation;)Ljava/lang/Object;
273274
}
274275

275-
public final class kotlinx/coroutines/DispatchedContinuationKt {
276-
public static final fun resumeCancellableWith (Lkotlin/coroutines/Continuation;Ljava/lang/Object;)V
277-
}
278-
279276
public final class kotlinx/coroutines/Dispatchers {
280277
public static final field INSTANCE Lkotlinx/coroutines/Dispatchers;
281278
public static final fun getDefault ()Lkotlinx/coroutines/CoroutineDispatcher;
@@ -622,9 +619,9 @@ public final class kotlinx/coroutines/channels/ChannelIterator$DefaultImpls {
622619

623620
public final class kotlinx/coroutines/channels/ChannelKt {
624621
public static final synthetic fun Channel (I)Lkotlinx/coroutines/channels/Channel;
625-
public static final fun Channel (ILkotlinx/coroutines/channels/BufferOverflow;)Lkotlinx/coroutines/channels/Channel;
622+
public static final fun Channel (ILkotlinx/coroutines/channels/BufferOverflow;Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/channels/Channel;
626623
public static synthetic fun Channel$default (IILjava/lang/Object;)Lkotlinx/coroutines/channels/Channel;
627-
public static synthetic fun Channel$default (ILkotlinx/coroutines/channels/BufferOverflow;ILjava/lang/Object;)Lkotlinx/coroutines/channels/Channel;
624+
public static synthetic fun Channel$default (ILkotlinx/coroutines/channels/BufferOverflow;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/coroutines/channels/Channel;
628625
}
629626

630627
public final class kotlinx/coroutines/channels/ChannelsKt {

kotlinx-coroutines-core/build.gradle

Lines changed: 100 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,60 @@
33
*/
44

55
apply plugin: 'org.jetbrains.kotlin.multiplatform'
6-
apply from: rootProject.file("gradle/targets.gradle")
76
apply from: rootProject.file("gradle/compile-jvm-multiplatform.gradle")
87
apply from: rootProject.file("gradle/compile-common.gradle")
98
apply from: rootProject.file("gradle/compile-js-multiplatform.gradle")
109
apply from: rootProject.file("gradle/compile-native-multiplatform.gradle")
1110
apply from: rootProject.file('gradle/publish-npm-js.gradle')
1211

12+
/* ==========================================================================
13+
Configure source sets structure for kotlinx-coroutines-core:
14+
15+
TARGETS SOURCE SETS
16+
------- ----------------------------------------------
17+
18+
js -----------------------------------------------------+
19+
|
20+
V
21+
jvm -------------------------------> concurrent ---> common
22+
^
23+
ios \ |
24+
macos | ---> nativeDarwin ---> native --+
25+
tvos | ^
26+
watchos / |
27+
|
28+
linux \ ---> nativeOther -------+
29+
mingw /
30+
31+
========================================================================== */
32+
33+
project.ext.sourceSetSuffixes = ["Main", "Test"]
34+
35+
void defineSourceSet(newName, dependsOn, includedInPred) {
36+
for (suffix in project.ext.sourceSetSuffixes) {
37+
def newSS = kotlin.sourceSets.maybeCreate(newName + suffix)
38+
for (dep in dependsOn) {
39+
newSS.dependsOn(kotlin.sourceSets[dep + suffix])
40+
}
41+
for (curSS in kotlin.sourceSets) {
42+
def curName = curSS.name
43+
if (curName.endsWith(suffix)) {
44+
def prefix = curName.substring(0, curName.length() - suffix.length())
45+
if (includedInPred(prefix)) curSS.dependsOn(newSS)
46+
}
47+
}
48+
}
49+
}
50+
51+
static boolean isNativeDarwin(String name) { return ["ios", "macos", "tvos", "watchos"].any { name.startsWith(it) } }
52+
static boolean isNativeOther(String name) { return ["linux", "mingw"].any { name.startsWith(it) } }
53+
54+
defineSourceSet("concurrent", ["common"]) { it in ["jvm", "native"] }
55+
defineSourceSet("nativeDarwin", ["native"]) { isNativeDarwin(it) }
56+
defineSourceSet("nativeOther", ["native"]) { isNativeOther(it) }
57+
58+
/* ========================================================================== */
59+
1360
/*
1461
* All platform plugins and configuration magic happens here instead of build.gradle
1562
* because JMV-only projects depend on core, thus core should always be initialized before configuration.
@@ -18,7 +65,7 @@ kotlin {
1865
configure(sourceSets) {
1966
def srcDir = name.endsWith('Main') ? 'src' : 'test'
2067
def platform = name[0..-5]
21-
kotlin.srcDir "$platform/$srcDir"
68+
kotlin.srcDirs = ["$platform/$srcDir"]
2269
if (name == "jvmMain") {
2370
resources.srcDirs = ["$platform/resources"]
2471
} else if (name == "jvmTest") {
@@ -31,12 +78,18 @@ kotlin {
3178
}
3279

3380
configure(targets) {
34-
def targetName = it.name
35-
compilations.all { compilation ->
36-
def compileTask = tasks.getByName(compilation.compileKotlinTaskName)
37-
// binary compatibility support
38-
if (targetName.contains("jvm") && compilation.compilationName == "main") {
39-
compileTask.kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
81+
// Configure additional binaries and test runs -- one for each OS
82+
if (["macos", "linux", "mingw"].any { name.startsWith(it) }) {
83+
binaries {
84+
// Test for memory leaks using a special entry point that does not exit but returns from main
85+
binaries.getTest("DEBUG").freeCompilerArgs += ["-e", "kotlinx.coroutines.mainNoExit"]
86+
// Configure a separate test where code runs in background
87+
test("background", [org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG]) {
88+
freeCompilerArgs += ["-e", "kotlinx.coroutines.mainBackground"]
89+
}
90+
}
91+
testRuns {
92+
background { setExecutionSourceFrom(binaries.backgroundDebugTest) }
4093
}
4194
}
4295
}
@@ -54,23 +107,52 @@ compileKotlinMetadata {
54107
}
55108
}
56109

110+
// :KLUDGE: Idea.active: This is needed to workaround resolve problems after importing this project to IDEA
111+
def configureNativeSourceSetPreset(name, preset) {
112+
def hostMainCompilation = project.kotlin.targetFromPreset(preset).compilations.main
113+
// Look for platform libraries in "implementation" for default source set
114+
def implementationConfiguration = configurations[hostMainCompilation.defaultSourceSet.implementationMetadataConfigurationName]
115+
// Now find the libraries: Finds platform libs & stdlib, but platform declarations are still not resolved due to IDE bugs
116+
def hostNativePlatformLibs = files(
117+
provider {
118+
implementationConfiguration.findAll {
119+
it.path.endsWith(".klib") || it.absolutePath.contains("klib${File.separator}platform") || it.absolutePath.contains("stdlib")
120+
}
121+
}
122+
)
123+
// Add all those dependencies
124+
for (suffix in sourceSetSuffixes) {
125+
configure(kotlin.sourceSets[name + suffix]) {
126+
dependencies.add(implementationMetadataConfigurationName, hostNativePlatformLibs)
127+
}
128+
}
129+
}
130+
131+
// :KLUDGE: Idea.active: Configure platform libraries for native source sets when working in IDEA
132+
if (Idea.active) {
133+
def manager = project.ext.hostManager
134+
def linuxPreset = kotlin.presets.linuxX64
135+
def macosPreset = kotlin.presets.macosX64
136+
// linux should be always available (cross-compilation capable) -- use it as default
137+
assert manager.isEnabled(linuxPreset.konanTarget)
138+
// use macOS libs for nativeDarwin if available
139+
def macosAvailable = manager.isEnabled(macosPreset.konanTarget)
140+
// configure source sets
141+
configureNativeSourceSetPreset("native", linuxPreset)
142+
configureNativeSourceSetPreset("nativeOther", linuxPreset)
143+
configureNativeSourceSetPreset("nativeDarwin", macosAvailable ? macosPreset : linuxPreset)
144+
}
145+
57146
kotlin.sourceSets {
58147
jvmMain.dependencies {
59148
compileOnly "com.google.android:annotations:4.1.1.4"
60149
}
61150

62151
jvmTest.dependencies {
63-
// This is a workaround for https://youtrack.jetbrains.com/issue/KT-39037
64-
def excludingCurrentProject = { dependency ->
65-
def result = project.dependencies.create(dependency)
66-
result.exclude(module: project.name)
67-
return result
68-
}
69-
70-
api(excludingCurrentProject("org.jetbrains.kotlinx:lincheck:$lincheck_version"))
152+
api "org.jetbrains.kotlinx:lincheck:$lincheck_version"
71153
api "org.jetbrains.kotlinx:kotlinx-knit-test:$knit_version"
72154
api "com.esotericsoftware:kryo:4.0.0"
73-
implementation(excludingCurrentProject(project(":android-unit-tests")))
155+
implementation project(":android-unit-tests")
74156
}
75157
}
76158

@@ -97,7 +179,7 @@ jvmTest {
97179
enableAssertions = true
98180
systemProperty 'java.security.manager', 'kotlinx.coroutines.TestSecurityManager'
99181
// 'stress' is required to be able to run all subpackage tests like ":jvmTests --tests "*channels*" -Pstress=true"
100-
if (!project.ext.ideaActive && rootProject.properties['stress'] == null) {
182+
if (!Idea.active && rootProject.properties['stress'] == null) {
101183
exclude '**/*StressTest.*'
102184
}
103185
systemProperty 'kotlinx.coroutines.scheduler.keep.alive.sec', '100000' // any unpark problem hangs test

0 commit comments

Comments
 (0)