Skip to content

Commit

Permalink
Enable strict explicit mode (Kotlin#1877)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad authored and recheej committed Dec 28, 2020
1 parent 20517c4 commit ad1c22f
Show file tree
Hide file tree
Showing 65 changed files with 146 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package benchmarks.common

import java.util.concurrent.*

fun doGeomDistrWork(work: Int) {
public fun doGeomDistrWork(work: Int) {
// We use geometric distribution here. We also checked on macbook pro 13" (2017) that the resulting work times
// are distributed geometrically, see https://github.com/Kotlin/kotlinx.coroutines/pull/1464#discussion_r355705325
val p = 1.0 / work
Expand Down
5 changes: 5 additions & 0 deletions gradle/compile-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ kotlin.sourceSets {
api "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
}
}


kotlin.sourceSets.matching({ it.name.contains("Main") }).all { srcSet ->
project.ext.set("kotlin.mpp.freeCompilerArgsForSourceSet.${srcSet.name}", "-Xexplicit-api=strict")
}
6 changes: 6 additions & 0 deletions gradle/compile-jvm.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ repositories {
maven { url "https://dl.bintray.com/devexperts/Maven/" }
}

compileKotlin {
kotlinOptions {
freeCompilerArgs += ['-Xexplicit-api=strict']
}
}

tasks.withType(Test) {
testLogging {
showStandardStreams = true
Expand Down
9 changes: 4 additions & 5 deletions integration/kotlinx-coroutines-jdk8/src/time/Time.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ import java.time.temporal.*
/**
* "java.time" adapter method for [kotlinx.coroutines.delay].
*/
public suspend fun delay(duration: Duration) =
kotlinx.coroutines.delay(duration.coerceToMillis())
public suspend fun delay(duration: Duration): Unit = delay(duration.coerceToMillis())

/**
* "java.time" adapter method for [kotlinx.coroutines.flow.debounce].
*/
@FlowPreview
public fun <T> Flow<T>.debounce(timeout: Duration) = debounce(timeout.coerceToMillis())
public fun <T> Flow<T>.debounce(timeout: Duration): Flow<T> = debounce(timeout.coerceToMillis())

/**
* "java.time" adapter method for [kotlinx.coroutines.flow.sample].
*/
@FlowPreview
public fun <T> Flow<T>.sample(period: Duration) = sample(period.coerceToMillis())
public fun <T> Flow<T>.sample(period: Duration): Flow<T> = sample(period.coerceToMillis())

/**
* "java.time" adapter method for [SelectBuilder.onTimeout].
*/
public fun <R> SelectBuilder<R>.onTimeout(duration: Duration, block: suspend () -> R) =
public fun <R> SelectBuilder<R>.onTimeout(duration: Duration, block: suspend () -> R): Unit =
onTimeout(duration.coerceToMillis(), block)

/**
Expand Down
2 changes: 1 addition & 1 deletion integration/kotlinx-coroutines-slf4j/src/MDCContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MDCContext(
/**
* Key of [MDCContext] in [CoroutineContext].
*/
companion object Key : CoroutineContext.Key<MDCContext>
public companion object Key : CoroutineContext.Key<MDCContext>

/** @suppress */
override fun updateThreadContext(context: CoroutineContext): MDCContextMap {
Expand Down
2 changes: 1 addition & 1 deletion js/js-stub/src/Performance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
package org.w3c.performance

public abstract class Performance {
abstract fun now(): Double
public abstract fun now(): Double
}
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/common/src/AbstractCoroutine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public abstract class AbstractCoroutine<in T>(
afterResume(state)
}

protected open fun afterResume(state: Any?) = afterCompletion(state)
protected open fun afterResume(state: Any?): Unit = afterCompletion(state)

internal final override fun handleOnCompletionException(exception: Throwable) {
handleCoroutineException(context, exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ internal fun CancellableContinuation<*>.removeOnCancellation(node: LockFreeLinke
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
public fun CancellableContinuation<*>.disposeOnCancellation(handle: DisposableHandle) =
public fun CancellableContinuation<*>.disposeOnCancellation(handle: DisposableHandle): Unit =
invokeOnCancellation(handler = DisposeOnCancel(handle).asHandler)

// --------------- implementation details ---------------
Expand Down
3 changes: 2 additions & 1 deletion kotlinx-coroutines-core/common/src/CompletableDeferred.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public interface CompletableDeferred<T> : Deferred<T> {
* [CompletableDeferred.completeExceptionally].
*/
@ExperimentalCoroutinesApi // since 1.3.2, tentatively until 1.4.0
public fun <T> CompletableDeferred<T>.completeWith(result: Result<T>) = result.fold({ complete(it) }, { completeExceptionally(it) })
public fun <T> CompletableDeferred<T>.completeWith(result: Result<T>): Boolean =
result.fold({ complete(it) }, { completeExceptionally(it) })

/**
* Creates a [CompletableDeferred] in an _active_ state.
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/common/src/CoroutineDispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public abstract class CoroutineDispatcher :
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
public open fun dispatchYield(context: CoroutineContext, block: Runnable) = dispatch(context, block)
public open fun dispatchYield(context: CoroutineContext, block: Runnable): Unit = dispatch(context, block)

/**
* Returns a continuation that wraps the provided [continuation], thus intercepting all resumptions.
Expand Down Expand Up @@ -115,7 +115,7 @@ public abstract class CoroutineDispatcher :
"The dispatcher to the right of `+` just replaces the dispatcher to the left.",
level = DeprecationLevel.ERROR
)
public operator fun plus(other: CoroutineDispatcher) = other
public operator fun plus(other: CoroutineDispatcher): CoroutineDispatcher = other

/** @suppress for nicer debugging */
override fun toString(): String = "$classSimpleName@$hexAddress"
Expand Down
22 changes: 11 additions & 11 deletions kotlinx-coroutines-core/common/src/CoroutineStart.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE")
package kotlinx.coroutines

import kotlinx.coroutines.CoroutineStart.*
Expand Down Expand Up @@ -85,12 +85,12 @@ public enum class CoroutineStart {
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
public operator fun <T> invoke(block: suspend () -> T, completion: Continuation<T>) =
public operator fun <T> invoke(block: suspend () -> T, completion: Continuation<T>): Unit =
when (this) {
CoroutineStart.DEFAULT -> block.startCoroutineCancellable(completion)
CoroutineStart.ATOMIC -> block.startCoroutine(completion)
CoroutineStart.UNDISPATCHED -> block.startCoroutineUndispatched(completion)
CoroutineStart.LAZY -> Unit // will start lazily
DEFAULT -> block.startCoroutineCancellable(completion)
ATOMIC -> block.startCoroutine(completion)
UNDISPATCHED -> block.startCoroutineUndispatched(completion)
LAZY -> Unit // will start lazily
}

/**
Expand All @@ -104,12 +104,12 @@ public enum class CoroutineStart {
* @suppress **This an internal API and should not be used from general code.**
*/
@InternalCoroutinesApi
public operator fun <R, T> invoke(block: suspend R.() -> T, receiver: R, completion: Continuation<T>) =
public operator fun <R, T> invoke(block: suspend R.() -> T, receiver: R, completion: Continuation<T>): Unit =
when (this) {
CoroutineStart.DEFAULT -> block.startCoroutineCancellable(receiver, completion)
CoroutineStart.ATOMIC -> block.startCoroutine(receiver, completion)
CoroutineStart.UNDISPATCHED -> block.startCoroutineUndispatched(receiver, completion)
CoroutineStart.LAZY -> Unit // will start lazily
DEFAULT -> block.startCoroutineCancellable(receiver, completion)
ATOMIC -> block.startCoroutine(receiver, completion)
UNDISPATCHED -> block.startCoroutineUndispatched(receiver, completion)
LAZY -> Unit // will start lazily
}

/**
Expand Down
8 changes: 4 additions & 4 deletions kotlinx-coroutines-core/common/src/Delay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface Delay {
* If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
* immediately resumes with [CancellationException].
*/
suspend fun delay(time: Long) {
public suspend fun delay(time: Long) {
if (time <= 0) return // don't delay
return suspendCancellableCoroutine { scheduleResumeAfterDelay(time, it) }
}
Expand All @@ -45,7 +45,7 @@ public interface Delay {
* with(continuation) { resumeUndispatchedWith(Unit) }
* ```
*/
fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>)
public fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>)

/**
* Schedules invocation of a specified [block] after a specified delay [timeMillis].
Expand All @@ -54,7 +54,7 @@ public interface Delay {
*
* This implementation uses a built-in single-threaded scheduled executor service.
*/
fun invokeOnTimeout(timeMillis: Long, block: Runnable): DisposableHandle =
public fun invokeOnTimeout(timeMillis: Long, block: Runnable): DisposableHandle =
DefaultDelay.invokeOnTimeout(timeMillis, block)
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public suspend fun delay(timeMillis: Long) {
* Implementation note: how exactly time is tracked is an implementation detail of [CoroutineDispatcher] in the context.
*/
@ExperimentalTime
public suspend fun delay(duration: Duration) = delay(duration.toDelayMillis())
public suspend fun delay(duration: Duration): Unit = delay(duration.toDelayMillis())

/** Returns [Delay] implementation of the given context */
internal val CoroutineContext.delay: Delay get() = get(ContinuationInterceptor) as? Delay ?: DefaultDelay
Expand Down
12 changes: 6 additions & 6 deletions kotlinx-coroutines-core/common/src/Job.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public interface Job : CoroutineContext.Element {
* @suppress This method implements old version of JVM ABI. Use [cancel].
*/
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
public fun cancel() = cancel(null)
public fun cancel(): Unit = cancel(null)

/**
* @suppress This method has bad semantics when cause is not a [CancellationException]. Use [cancel].
Expand Down Expand Up @@ -337,7 +337,7 @@ public interface Job : CoroutineContext.Element {
"Job is a coroutine context element and `+` is a set-sum operator for coroutine contexts. " +
"The job to the right of `+` just replaces the job the left of `+`.",
level = DeprecationLevel.ERROR)
public operator fun plus(other: Job) = other
public operator fun plus(other: Job): Job = other
}

/**
Expand Down Expand Up @@ -382,7 +382,7 @@ public interface DisposableHandle {
*/
@Suppress("FunctionName")
@InternalCoroutinesApi
public inline fun DisposableHandle(crossinline block: () -> Unit) =
public inline fun DisposableHandle(crossinline block: () -> Unit): DisposableHandle =
object : DisposableHandle {
override fun dispose() {
block()
Expand Down Expand Up @@ -496,7 +496,7 @@ public fun Job.cancelChildren(cause: CancellationException? = null) {
* @suppress This method implements old version of JVM ABI. Use [cancel].
*/
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
public fun Job.cancelChildren() = cancelChildren(null)
public fun Job.cancelChildren(): Unit = cancelChildren(null)

/**
* @suppress This method has bad semantics when cause is not a [CancellationException]. Use [Job.cancelChildren].
Expand Down Expand Up @@ -539,7 +539,7 @@ public fun CoroutineContext.cancel(cause: CancellationException? = null) {
* @suppress This method implements old version of JVM ABI. Use [CoroutineContext.cancel].
*/
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
public fun CoroutineContext.cancel() = cancel(null)
public fun CoroutineContext.cancel(): Unit = cancel(null)

/**
* Ensures that current job is [active][Job.isActive].
Expand Down Expand Up @@ -605,7 +605,7 @@ public fun CoroutineContext.cancelChildren(cause: CancellationException? = null)
* @suppress This method implements old version of JVM ABI. Use [CoroutineContext.cancelChildren].
*/
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
public fun CoroutineContext.cancelChildren() = cancelChildren(null)
public fun CoroutineContext.cancelChildren(): Unit = cancelChildren(null)

/**
* @suppress This method has bad semantics when cause is not a [CancellationException]. Use [CoroutineContext.cancelChildren].
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/common/src/JobSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
* Makes this [Job] cancelled with a specified [cause].
* It is used in [AbstractCoroutine]-derived classes when there is an internal failure.
*/
public fun cancelCoroutine(cause: Throwable?) = cancelImpl(cause)
public fun cancelCoroutine(cause: Throwable?): Boolean = cancelImpl(cause)

// cause is Throwable or ParentJob when cancelChild was invoked
// returns true is exception was handled, false otherwise
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/common/src/channels/Broadcast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import kotlin.native.concurrent.*
*
* @param start coroutine start option. The default value is [CoroutineStart.LAZY].
*/
fun <E> ReceiveChannel<E>.broadcast(
public fun <E> ReceiveChannel<E>.broadcast(
capacity: Int = 1,
start: CoroutineStart = CoroutineStart.LAZY
): BroadcastChannel<E> {
Expand Down
20 changes: 10 additions & 10 deletions kotlinx-coroutines-core/common/src/channels/Channel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
package kotlinx.coroutines.channels

import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
import kotlinx.coroutines.channels.Channel.Factory.CHANNEL_DEFAULT_CAPACITY
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
import kotlinx.coroutines.channels.Channel.Factory.RENDEZVOUS
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
import kotlinx.coroutines.channels.Channel.Factory.CHANNEL_DEFAULT_CAPACITY
import kotlinx.coroutines.internal.systemProp
import kotlinx.coroutines.internal.*
import kotlinx.coroutines.selects.*
import kotlin.jvm.*
import kotlin.internal.*
import kotlin.jvm.*

/**
* Sender's interface to [Channel].
Expand Down Expand Up @@ -314,7 +314,7 @@ public interface ReceiveChannel<out E> {
* @suppress This method implements old version of JVM ABI. Use [cancel].
*/
@Deprecated(level = DeprecationLevel.HIDDEN, message = "Since 1.2.0, binary compatibility with versions <= 1.1.x")
public fun cancel() = cancel(null)
public fun cancel(): Unit = cancel(null)

/**
* @suppress This method has bad semantics when cause is not a [CancellationException]. Use [cancel].
Expand Down Expand Up @@ -517,25 +517,25 @@ public interface Channel<E> : SendChannel<E>, ReceiveChannel<E> {
/**
* Requests a channel with an unlimited capacity buffer in the `Channel(...)` factory function
*/
public const val UNLIMITED = Int.MAX_VALUE
public const val UNLIMITED: Int = Int.MAX_VALUE

/**
* Requests a rendezvous channel in the `Channel(...)` factory function &mdash; a `RendezvousChannel` gets created.
*/
public const val RENDEZVOUS = 0
public const val RENDEZVOUS: Int = 0

/**
* Requests a conflated channel in the `Channel(...)` factory function &mdash; a `ConflatedChannel` gets created.
*/
public const val CONFLATED = -1
public const val CONFLATED: Int = -1

/**
* Requests a buffered channel with the default buffer capacity in the `Channel(...)` factory function &mdash;
* an `ArrayChannel` gets created with the default capacity.
* The default capacity is 64 and can be overridden by setting
* [DEFAULT_BUFFER_PROPERTY_NAME] on JVM.
*/
public const val BUFFERED = -2
public const val BUFFERED: Int = -2

// only for internal use, cannot be used with Channel(...)
internal const val OPTIONAL_CHANNEL = -3
Expand All @@ -544,7 +544,7 @@ public interface Channel<E> : SendChannel<E>, ReceiveChannel<E> {
* Name of the property that defines the default channel capacity when
* [BUFFERED] is used as parameter in `Channel(...)` factory function.
*/
public const val DEFAULT_BUFFER_PROPERTY_NAME = "kotlinx.coroutines.channels.defaultBuffer"
public const val DEFAULT_BUFFER_PROPERTY_NAME: String = "kotlinx.coroutines.channels.defaultBuffer"

internal val CHANNEL_DEFAULT_CAPACITY = systemProp(DEFAULT_BUFFER_PROPERTY_NAME,
64, 1, UNLIMITED - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public fun <E : Any> ReceiveChannel<E>.onReceiveOrNull(): SelectClause1<E?> {
* See [issue #254](https://github.com/Kotlin/kotlinx.coroutines/issues/254).
*/
@ObsoleteCoroutinesApi
public suspend inline fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit) =
public suspend inline fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit): Unit =
consume {
for (element in this) action(element)
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public inline fun <E, R> ReceiveChannel<E>.consume(block: ReceiveChannel<E>.() -
* This function [consumes][ReceiveChannel.consume] all elements of the original [ReceiveChannel].
*/
@ExperimentalCoroutinesApi // since 1.3.0, tentatively graduates in 1.4.0
public suspend inline fun <E> ReceiveChannel<E>.consumeEach(action: (E) -> Unit) =
public suspend inline fun <E> ReceiveChannel<E>.consumeEach(action: (E) -> Unit): Unit =
consume {
for (e in this) action(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ConflatedBroadcastChannel<E>() : BroadcastChannel<E> {
* It is as a shortcut to creating an instance with a default constructor and
* immediately sending an element: `ConflatedBroadcastChannel().apply { offer(value) }`.
*/
constructor(value: E) : this() {
public constructor(value: E) : this() {
_state.lazySet(State<E>(value, null))
}

Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/common/src/channels/Produce.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface ProducerScope<in E> : CoroutineScope, SendChannel<E> {
* All the [SendChannel] functions on this interface delegate to
* the channel instance returned by this property.
*/
val channel: SendChannel<E>
public val channel: SendChannel<E>
}

/**
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/common/src/flow/Channels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
* See [consumeEach][ReceiveChannel.consumeEach].
*/
@ExperimentalCoroutinesApi // since version 1.3.0
public suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>) =
public suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>): Unit =
emitAllImpl(channel, consume = true)

private suspend fun <T> FlowCollector<T>.emitAllImpl(channel: ReceiveChannel<T>, consume: Boolean) {
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/common/src/flow/Migration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@file:JvmMultifileClass
@file:JvmName("FlowKt")
@file:Suppress("unused", "DeprecatedCallableAddReplaceWith", "UNUSED_PARAMETER")
@file:Suppress("unused", "DeprecatedCallableAddReplaceWith", "UNUSED_PARAMETER", "NO_EXPLICIT_RETURN_TYPE_IN_API_MODE")

package kotlinx.coroutines.flow

Expand Down
Loading

0 comments on commit ad1c22f

Please sign in to comment.