From 5407ac1c7266603d4279a17631ff1b6dee4efe8b Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Wed, 12 Apr 2023 23:13:46 +0300 Subject: [PATCH] [K/N] Mark UnhandledExceptionHook-related API with ExperimentalNativeApi Instead of ExperimentalStdlibApi As a part of efforts to stabilize Native stdlib #KT-55765. --- .../tests/interop/exceptions/exceptionHook.kt | 2 +- .../tests/produce_dynamic/simple/hello.kt | 2 +- .../produce_dynamic/unhandledException/unhandled.kt | 2 +- .../tests/runtime/exceptions/custom_hook.kt | 2 +- .../runtime/exceptions/custom_hook_memory_leak.kt | 2 +- .../tests/runtime/exceptions/custom_hook_throws.kt | 2 +- .../workers/worker_exceptions_terminate_hook.kt | 2 +- .../worker_exceptions_terminate_hook_current.kt | 2 +- .../runtime/src/main/kotlin/kotlin/native/Runtime.kt | 12 ++++++------ .../kotlin/native/internal/ObjCExportCoroutines.kt | 3 ++- .../kotlin/kotlin/native/internal/RuntimeUtils.kt | 7 ++++--- 11 files changed, 20 insertions(+), 18 deletions(-) diff --git a/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt index dfd51675ea4..36b714e79f1 100644 --- a/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt +++ b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt @@ -1,4 +1,4 @@ -@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) +@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class) import kotlin.native.concurrent.freeze diff --git a/kotlin-native/backend.native/tests/produce_dynamic/simple/hello.kt b/kotlin-native/backend.native/tests/produce_dynamic/simple/hello.kt index f36f15f39ae..91f9b81455c 100644 --- a/kotlin-native/backend.native/tests/produce_dynamic/simple/hello.kt +++ b/kotlin-native/backend.native/tests/produce_dynamic/simple/hello.kt @@ -4,7 +4,7 @@ */ // FILE: hello.kt -@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) +@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class) import kotlinx.cinterop.* diff --git a/kotlin-native/backend.native/tests/produce_dynamic/unhandledException/unhandled.kt b/kotlin-native/backend.native/tests/produce_dynamic/unhandledException/unhandled.kt index cbc90eacfd1..c6dfea8670a 100644 --- a/kotlin-native/backend.native/tests/produce_dynamic/unhandledException/unhandled.kt +++ b/kotlin-native/backend.native/tests/produce_dynamic/unhandledException/unhandled.kt @@ -2,7 +2,7 @@ * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class) +@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class) import kotlin.native.concurrent.* import kotlin.native.internal.* diff --git a/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook.kt b/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook.kt index 13f9c166c46..b2498a8d0e9 100644 --- a/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook.kt +++ b/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook.kt @@ -2,7 +2,7 @@ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ -@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class) +@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class) import kotlin.test.* diff --git a/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook_memory_leak.kt b/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook_memory_leak.kt index 5e29e4e1878..eccd017a267 100644 --- a/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook_memory_leak.kt +++ b/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook_memory_leak.kt @@ -2,7 +2,7 @@ * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ -@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) +@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class) import kotlin.test.* diff --git a/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook_throws.kt b/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook_throws.kt index ca164287a88..f30a2cb5324 100644 --- a/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook_throws.kt +++ b/kotlin-native/backend.native/tests/runtime/exceptions/custom_hook_throws.kt @@ -2,7 +2,7 @@ * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ -@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) +@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class) import kotlin.test.* diff --git a/kotlin-native/backend.native/tests/runtime/workers/worker_exceptions_terminate_hook.kt b/kotlin-native/backend.native/tests/runtime/workers/worker_exceptions_terminate_hook.kt index e3cb14a2365..5ff0a1ecc16 100644 --- a/kotlin-native/backend.native/tests/runtime/workers/worker_exceptions_terminate_hook.kt +++ b/kotlin-native/backend.native/tests/runtime/workers/worker_exceptions_terminate_hook.kt @@ -1,4 +1,4 @@ -@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class, ObsoleteWorkersApi::class) +@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, ObsoleteWorkersApi::class) import kotlin.native.concurrent.* diff --git a/kotlin-native/backend.native/tests/runtime/workers/worker_exceptions_terminate_hook_current.kt b/kotlin-native/backend.native/tests/runtime/workers/worker_exceptions_terminate_hook_current.kt index d3b85bef3d0..4df744caa7c 100644 --- a/kotlin-native/backend.native/tests/runtime/workers/worker_exceptions_terminate_hook_current.kt +++ b/kotlin-native/backend.native/tests/runtime/workers/worker_exceptions_terminate_hook_current.kt @@ -1,4 +1,4 @@ -@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class, ObsoleteWorkersApi::class) +@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, ObsoleteWorkersApi::class) import kotlin.native.concurrent.* diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt index 33e2cd1e08a..c13db6e2328 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt @@ -41,7 +41,7 @@ public class IncorrectDereferenceException : RuntimeException { /** * Typealias describing custom exception reporting hook. */ -@ExperimentalStdlibApi +@ExperimentalNativeApi public typealias ReportUnhandledExceptionHook = Function1 /** @@ -57,7 +57,7 @@ public typealias ReportUnhandledExceptionHook = Function1 * Set or default hook is also invoked by [processUnhandledException]. * With the legacy MM the hook must be a frozen lambda so that it could be called from any thread/worker. */ -@ExperimentalStdlibApi +@ExperimentalNativeApi @OptIn(FreezingIsDeprecated::class) public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook?): ReportUnhandledExceptionHook? { try { @@ -69,7 +69,7 @@ public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook?): Repor @Suppress("CONFLICTING_OVERLOADS") @Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) -@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) +@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class) public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook): ReportUnhandledExceptionHook? { try { return UnhandledExceptionHookHolder.hook.swap(hook) @@ -81,7 +81,7 @@ public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook): Report /** * Returns a user-defined unhandled exception hook set by [setUnhandledExceptionHook] or `null` if no user-defined hooks were set. */ -@ExperimentalStdlibApi +@ExperimentalNativeApi @SinceKotlin("1.6") @OptIn(FreezingIsDeprecated::class) public fun getUnhandledExceptionHook(): ReportUnhandledExceptionHook? { @@ -95,7 +95,7 @@ public fun getUnhandledExceptionHook(): ReportUnhandledExceptionHook? { * If the hook is not present, calls [terminateWithUnhandledException] with [throwable]. * If the hook fails with exception, calls [terminateWithUnhandledException] with exception from the hook. */ -@ExperimentalStdlibApi +@ExperimentalNativeApi @SinceKotlin("1.6") @GCUnsafeCall("Kotlin_processUnhandledException") public external fun processUnhandledException(throwable: Throwable): Unit @@ -106,7 +106,7 @@ public external fun processUnhandledException(throwable: Throwable): Unit * * `terminateWithUnhandledException` can be used to emulate an abrupt termination of the application with an uncaught exception. */ -@ExperimentalStdlibApi +@ExperimentalNativeApi @SinceKotlin("1.6") @GCUnsafeCall("Kotlin_terminateWithUnhandledException") public external fun terminateWithUnhandledException(throwable: Throwable): Nothing diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/ObjCExportCoroutines.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/ObjCExportCoroutines.kt index a6bb8b3e3e2..5fae512f7b5 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/ObjCExportCoroutines.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/ObjCExportCoroutines.kt @@ -5,6 +5,7 @@ package kotlin.native.internal +import kotlin.experimental.ExperimentalNativeApi import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* import kotlin.coroutines.native.internal.* @@ -29,7 +30,7 @@ private object EmptyCompletion : Continuation { override val context: CoroutineContext get() = EmptyCoroutineContext - @OptIn(ExperimentalStdlibApi::class) + @OptIn(ExperimentalNativeApi::class) override fun resumeWith(result: Result) { val exception = result.exceptionOrNull() ?: return processUnhandledException(exception) diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt index 6a5716c730e..f7e1cb29f6d 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt @@ -5,6 +5,7 @@ package kotlin.native.internal +import kotlin.experimental.ExperimentalNativeApi import kotlin.internal.getProgressionLastElement import kotlin.reflect.KClass import kotlin.native.concurrent.FreezableAtomicReference @@ -152,7 +153,7 @@ internal fun ReportUnhandledException(throwable: Throwable) { // Using object to make sure that `hook` is initialized when it's needed instead of // in a normal global initialization flow. This is important if some global happens // to throw an exception during it's initialization before this hook would've been initialized. -@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) +@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class) internal object UnhandledExceptionHookHolder { internal val hook: FreezableAtomicReference = if (Platform.memoryModel == MemoryModel.EXPERIMENTAL) { @@ -165,7 +166,7 @@ internal object UnhandledExceptionHookHolder { // TODO: Can be removed only when native-mt coroutines stop using it. @PublishedApi @ExportForCppRuntime -@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) +@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class) internal fun OnUnhandledException(throwable: Throwable) { val handler = UnhandledExceptionHookHolder.hook.value if (handler == null) { @@ -180,7 +181,7 @@ internal fun OnUnhandledException(throwable: Throwable) { } @ExportForCppRuntime("Kotlin_runUnhandledExceptionHook") -@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) +@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class) internal fun runUnhandledExceptionHook(throwable: Throwable) { val handler = UnhandledExceptionHookHolder.hook.value ?: throw throwable handler(throwable)