Skip to content

Commit

Permalink
Merge pull request #3815 from Kotlin/roman.efremov/MR/expect-annotations
Browse files Browse the repository at this point in the history
Make annotations on expect declarations comply with new compiler restriction
  • Loading branch information
merfemor authored Jul 21, 2023
2 parents c675e3f + 3c9e856 commit 387628b
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions kotlinx-coroutines-core/api/kotlinx-coroutines-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ public final class kotlinx/coroutines/DebugKt {
public static final field DEBUG_PROPERTY_VALUE_AUTO Ljava/lang/String;
public static final field DEBUG_PROPERTY_VALUE_OFF Ljava/lang/String;
public static final field DEBUG_PROPERTY_VALUE_ON Ljava/lang/String;
public static final fun getRECOVER_STACK_TRACES ()Z
}

public final class kotlinx/coroutines/DefaultExecutorKt {
public static final fun getDefaultDelay ()Lkotlinx/coroutines/Delay;
}

public abstract interface class kotlinx/coroutines/Deferred : kotlinx/coroutines/Job {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public expect fun CoroutineScope.newCoroutineContext(context: CoroutineContext):
@InternalCoroutinesApi
public expect fun CoroutineContext.newCoroutineContext(addedContext: CoroutineContext): CoroutineContext

@PublishedApi
@PublishedApi // to have unmangled name when using from other modules via suppress
@Suppress("PropertyName")
internal expect val DefaultDelay: Delay

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
package kotlinx.coroutines.internal

// Ignore JRE requirements for animal-sniffer, compileOnly dependency
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.CONSTRUCTOR,
AnnotationTarget.CLASS,
AnnotationTarget.FILE
)
@OptionalExpectation
internal expect annotation class IgnoreJreRequirement()
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ internal expect suspend inline fun recoverAndThrow(exception: Throwable): Nothin
* The opposite of [recoverStackTrace].
* It is guaranteed that `unwrap(recoverStackTrace(e)) === e`
*/
@PublishedApi // Used from kotlinx-coroutines-test and reactor modules via suppress, not part of ABI
internal expect fun <E: Throwable> unwrap(exception: E): E

internal expect class StackTraceElement
Expand Down
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/js/src/CoroutineContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private fun isJsdom() = jsTypeOf(navigator) != UNDEFINED &&
jsTypeOf(navigator.userAgent.match) != UNDEFINED &&
navigator.userAgent.match("\\bjsdom\\b")

@PublishedApi // Used from kotlinx-coroutines-test via suppress, not part of ABI
internal actual val DefaultDelay: Delay
get() = Dispatchers.Default as Delay

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal actual fun <E: Throwable> recoverStackTrace(exception: E, continuation:
internal actual fun <E: Throwable> recoverStackTrace(exception: E): E = exception
internal actual suspend inline fun recoverAndThrow(exception: Throwable): Nothing = throw exception

@PublishedApi
internal actual fun <E : Throwable> unwrap(exception: E): E = exception

@Suppress("UNUSED")
Expand Down
3 changes: 2 additions & 1 deletion kotlinx-coroutines-core/jvm/src/Debug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ internal actual val DEBUG = systemProp(DEBUG_PROPERTY_NAME).let { value ->

// Note: stack-trace recovery is enabled only in debug mode
// @JvmField: Don't use JvmField here to enable R8 optimizations via "assumenosideeffects"
internal actual val RECOVER_STACK_TRACES =
@PublishedApi
internal actual val RECOVER_STACK_TRACES: Boolean =
DEBUG && systemProp(STACKTRACE_RECOVERY_PROPERTY_NAME, true)

// It is used only in debug mode
Expand Down
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/jvm/src/DefaultExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlin.coroutines.*

private val defaultMainDelayOptIn = systemProp("kotlinx.coroutines.main.delay", false)

@PublishedApi
internal actual val DefaultDelay: Delay = initializeDefaultDelay()

private fun initializeDefaultDelay(): Delay {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ internal actual suspend inline fun recoverAndThrow(exception: Throwable): Nothin
}
}

@PublishedApi
@Suppress("NOTHING_TO_INLINE") // Inline for better R8 optimizations
internal actual inline fun <E : Throwable> unwrap(exception: E): E =
if (!RECOVER_STACK_TRACES) exception else unwrapImpl(exception)

@PublishedApi
internal fun <E : Throwable> unwrapImpl(exception: E): E {
val cause = exception.cause
// Fast-path to avoid array cloning
Expand Down
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/native/src/CoroutineContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal actual object DefaultExecutor : CoroutineDispatcher(), Delay {

internal expect fun createDefaultDispatcher(): CoroutineDispatcher

@PublishedApi
internal actual val DefaultDelay: Delay = DefaultExecutor

public actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import kotlin.coroutines.*

internal actual fun <E: Throwable> recoverStackTrace(exception: E, continuation: Continuation<*>): E = exception
internal actual fun <E: Throwable> recoverStackTrace(exception: E): E = exception

@PublishedApi
internal actual fun <E : Throwable> unwrap(exception: E): E = exception
internal actual suspend inline fun recoverAndThrow(exception: Throwable): Nothing = throw exception

Expand Down

0 comments on commit 387628b

Please sign in to comment.