From 8663239369f79d65adf22e6630ff745afe6c4855 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Thu, 23 Mar 2023 14:42:25 +0200 Subject: [PATCH] [K/N] Mark UnhandledExceptionHook-related API as experimental As a part of efforts to stabilize Native stdlib. --- .../tests/interop/exceptions/exceptionHook.kt | 2 +- .../backend.native/tests/produce_dynamic/simple/hello.kt | 2 +- .../tests/produce_dynamic/unhandledException/unhandled.kt | 2 +- .../backend.native/tests/runtime/exceptions/custom_hook.kt | 2 +- .../tests/runtime/exceptions/custom_hook_memory_leak.kt | 2 +- .../tests/runtime/exceptions/custom_hook_throws.kt | 2 +- .../runtime/workers/worker_exceptions_terminate_hook.kt | 2 +- .../workers/worker_exceptions_terminate_hook_current.kt | 2 +- .../runtime/src/main/kotlin/kotlin/native/Runtime.kt | 4 +++- .../src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt | 6 +++--- 10 files changed, 14 insertions(+), 12 deletions(-) diff --git a/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt index 224d8770938..dfd51675ea4 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) +@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::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 43504ae3afc..f36f15f39ae 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) +@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::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 d12ec5cad7f..9e5d50e8524 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) +@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::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 220fe0c7fa5..362f3e6fb28 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) +@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::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 c28592247e2..5e29e4e1878 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) +@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::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 e2d9d80042a..ca164287a88 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) +@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::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 b7ef022c81a..548e72912c9 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) +@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::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 d55b988209e..5860b931ec3 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) +@file:OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::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 42125ab13a7..81d3a78d137 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt @@ -40,6 +40,7 @@ public class IncorrectDereferenceException : RuntimeException { /** * Typealias describing custom exception reporting hook. */ +@ExperimentalStdlibApi public typealias ReportUnhandledExceptionHook = Function1 /** @@ -55,6 +56,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 @OptIn(FreezingIsDeprecated::class) public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook?): ReportUnhandledExceptionHook? { try { @@ -66,7 +68,7 @@ public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook?): Repor @Suppress("CONFLICTING_OVERLOADS") @Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) -@OptIn(FreezingIsDeprecated::class) +@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook): ReportUnhandledExceptionHook? { try { return UnhandledExceptionHookHolder.hook.swap(hook) 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 beb0e9f905c..2022a758836 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 @@ -144,7 +144,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) +@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) internal object UnhandledExceptionHookHolder { internal val hook: FreezableAtomicReference = if (Platform.memoryModel == MemoryModel.EXPERIMENTAL) { @@ -157,7 +157,7 @@ internal object UnhandledExceptionHookHolder { // TODO: Can be removed only when native-mt coroutines stop using it. @PublishedApi @ExportForCppRuntime -@OptIn(FreezingIsDeprecated::class) +@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) internal fun OnUnhandledException(throwable: Throwable) { val handler = UnhandledExceptionHookHolder.hook.value if (handler == null) { @@ -172,7 +172,7 @@ internal fun OnUnhandledException(throwable: Throwable) { } @ExportForCppRuntime("Kotlin_runUnhandledExceptionHook") -@OptIn(FreezingIsDeprecated::class) +@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class) internal fun runUnhandledExceptionHook(throwable: Throwable) { val handler = UnhandledExceptionHookHolder.hook.value ?: throw throwable handler(throwable)