diff --git a/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeStableRef.kt b/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeStableRef.kt index 9652444137d..ccabbabce63 100644 --- a/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeStableRef.kt +++ b/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeStableRef.kt @@ -6,9 +6,11 @@ package kotlinx.cinterop import kotlin.native.* +import kotlin.native.internal.Escapes import kotlin.native.internal.GCUnsafeCall @GCUnsafeCall("Kotlin_Interop_createStablePointer") +@Escapes(0b01) // any escapes into stable ref. internal external fun createStablePointer(any: Any): COpaquePointer @GCUnsafeCall("Kotlin_Interop_disposeStablePointer") diff --git a/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeTypes.kt b/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeTypes.kt index e8716c1ce87..de8b326a567 100644 --- a/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeTypes.kt +++ b/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeTypes.kt @@ -62,6 +62,7 @@ internal fun CPointer<*>.cPointerToString() = "CPointer(raw=$rawValue)" */ @ExperimentalForeignApi @TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) +// function is static, so it's never heap allocated anyway; no need to use @Escapes public external fun staticCFunction(@VolatileLambda function: () -> R): CPointer R>> @ExperimentalForeignApi 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 24bf28adebd..1e22b077605 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt @@ -6,11 +6,7 @@ package kotlin.native import kotlin.experimental.ExperimentalNativeApi import kotlin.native.concurrent.InvalidMutabilityException -import kotlin.native.internal.ExportForCppRuntime -import kotlin.native.internal.GCUnsafeCall -import kotlin.native.internal.UnhandledExceptionHookHolder -import kotlin.native.internal.runUnhandledExceptionHook -import kotlin.native.internal.ReportUnhandledException +import kotlin.native.internal.* /** * Initializes Kotlin runtime for the current thread, if not inited already. @@ -80,6 +76,7 @@ public fun getUnhandledExceptionHook(): ReportUnhandledExceptionHook? { @ExperimentalNativeApi @SinceKotlin("1.6") @GCUnsafeCall("Kotlin_processUnhandledException") +@Escapes(0b01) // throwable may be passed to the user code via unhandled exception hook. public external fun processUnhandledException(throwable: Throwable): Unit /* @@ -91,6 +88,7 @@ public external fun processUnhandledException(throwable: Throwable): Unit @ExperimentalNativeApi @SinceKotlin("1.6") @GCUnsafeCall("Kotlin_terminateWithUnhandledException") +// No need to mark throwable as @Escapes because this function never returns. public external fun terminateWithUnhandledException(throwable: Throwable): Nothing /** diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt index 001dedf9eee..15d82478160 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt @@ -6,14 +6,11 @@ package kotlin.native.concurrent import kotlin.experimental.ExperimentalNativeApi -import kotlin.native.internal.DescribeObjectForDebugging -import kotlin.native.internal.ExportForCppRuntime -import kotlin.native.internal.GCUnsafeCall -import kotlin.native.internal.InternalForKotlinNative -import kotlin.native.internal.debugDescription import kotlin.native.identityHashCode -import kotlin.reflect.KClass -import kotlinx.cinterop.* +import kotlinx.cinterop.CPointer +import kotlinx.cinterop.CFunction +import kotlinx.cinterop.ExperimentalForeignApi +import kotlin.native.internal.* @GCUnsafeCall("Kotlin_Any_isShareable") @FreezingIsDeprecated @@ -38,7 +35,7 @@ external internal fun waitForAnyFuture(versionToken: Int, millis: Int): Boolean @ObsoleteWorkersApi external internal fun versionToken(): Int -@kotlin.native.internal.ExportForCompiler +@ExportForCompiler @ObsoleteWorkersApi internal fun executeImpl(worker: Worker, mode: TransferMode, producer: () -> Any?, job: CPointer>): Future = @@ -46,6 +43,7 @@ internal fun executeImpl(worker: Worker, mode: TransferMode, producer: () -> Any @GCUnsafeCall("Kotlin_Worker_startInternal") @ObsoleteWorkersApi +@Escapes(0b10) // name is stored in the Worker instance. external internal fun startInternal(errorReporting: Boolean, name: String?): Int @GCUnsafeCall("Kotlin_Worker_currentInternal") @@ -63,6 +61,7 @@ external internal fun executeInternal( @GCUnsafeCall("Kotlin_Worker_executeAfterInternal") @ObsoleteWorkersApi +@Escapes(0b10) // operation escapes into stable ref. external internal fun executeAfterInternal(id: Int, operation: () -> Unit, afterMicroseconds: Long): Unit @GCUnsafeCall("Kotlin_Worker_processQueueInternal") diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/WorkerBoundReference.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/WorkerBoundReference.kt index 9b7c1afb101..33056e0a45e 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/WorkerBoundReference.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/WorkerBoundReference.kt @@ -11,6 +11,7 @@ import kotlinx.cinterop.ExperimentalForeignApi @GCUnsafeCall("Kotlin_WorkerBoundReference_create") @ObsoleteWorkersApi +@Escapes(0b01) // value escapes into stable ref. external private fun createWorkerBoundReference(value: Any): NativePtr @GCUnsafeCall("Kotlin_WorkerBoundReference_deref") diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/ObjCExportUtils.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/ObjCExportUtils.kt index 1c9e36be71f..14bf9ad0fc8 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/ObjCExportUtils.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/ObjCExportUtils.kt @@ -281,6 +281,7 @@ public class ObjCErrorException( @PublishedApi @GCUnsafeCall("Kotlin_ObjCExport_trapOnUndeclaredException") @ExportForCppRuntime +// No need to mark throwable as @Escapes because this function actually never returns. internal external fun trapOnUndeclaredException(exception: Throwable) @ExportForCppRuntime diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/ref/Cleaner.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/ref/Cleaner.kt index 7653a9423c8..a64b61a9b09 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/ref/Cleaner.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/ref/Cleaner.kt @@ -122,5 +122,6 @@ private class CleanerImpl( @GCUnsafeCall("CreateStablePointer") +@Escapes(0b01) // obj escapes into stable ref. external private fun createStablePointer(obj: Any): NativePtr