Explicitly declare stability levels of declarations in kotlinx.cinterop package

* @ExperimentalForeignApi for all declarations that operate on
    unmanaged memory (i.e. pointers and references)
* @BetaInteropApi for the rest of the interoperability declarations,
    namely Swift/CInterop-specific interfaces and convenience-functions

### Implementation details

* Some typealiases are not marked explicitly because it crashes the compiler,
    yet their experimentality is properly propagated
* License header is adjusted where it previously had been existing
* Deprecated with ERROR interop declarations that are deprecated for more than
    two years are removed
* WASM target interop declarations are deprecated
* Deliberately make Boolean.toByte and Byte.toBoolean foreign-experimental to scare
    people away

^KT-57728 fixed

Merge-request: KT-MR-9788
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
This commit is contained in:
Vsevolod Tolstopyatov
2023-05-04 13:52:21 +00:00
committed by Space Team
parent 82611ad124
commit f4e8ae5191
96 changed files with 784 additions and 345 deletions
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin
@@ -12,6 +13,7 @@ import kotlin.native.internal.ExportForCppRuntime
import kotlin.native.internal.ExportTypeInfo
import kotlin.native.internal.GCUnsafeCall
import kotlin.native.internal.NativePtrArray
import kotlinx.cinterop.ExperimentalForeignApi
/**
* The base class for all errors and exceptions. Only instances of this class can be thrown or caught.
@@ -6,6 +6,7 @@
package kotlin.concurrent
import kotlinx.cinterop.NativePtr
import kotlinx.cinterop.ExperimentalForeignApi
import kotlin.native.internal.*
import kotlin.reflect.*
import kotlin.concurrent.*
@@ -306,6 +307,7 @@ public class AtomicReference<T> {
@Frozen
@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class)
@SinceKotlin("1.9")
@ExperimentalForeignApi
public class AtomicNativePtr(@Volatile public var value: NativePtr) {
/**
* Atomically sets the value to the given [new value][newValue] and returns the old value.
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native
import kotlin.native.internal.*
@@ -1,10 +1,12 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.concurrent
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.NativePtr
import kotlin.native.internal.*
import kotlin.reflect.*
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.concurrent
@@ -9,6 +10,9 @@ import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.internal.*
import kotlinx.cinterop.*
private const val DEPRECATED_API_MESSAGE = "This API is deprecated without replacement"
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
public class Continuation0(block: () -> Unit,
private val invoker: CPointer<CFunction<(COpaquePointer?) -> Unit>>,
@@ -33,6 +37,7 @@ public class Continuation0(block: () -> Unit,
}
}
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
public class Continuation1<T1>(
block: (p1: T1) -> Unit,
@@ -65,6 +70,7 @@ public class Continuation1<T1>(
}
}
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
public class Continuation2<T1, T2>(
block: (p1: T1, p2: T2) -> Unit,
@@ -98,16 +104,20 @@ public class Continuation2<T1, T2>(
}
}
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
public fun COpaquePointer.callContinuation0() {
val single = this.asStableRef<() -> Unit>()
single.get()()
}
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
public fun <T1> COpaquePointer.callContinuation1() {
val pair = this.asStableRef<Pair<StableRef<(T1) -> Unit>, T1>>().get()
pair.first.get()(pair.second)
}
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
public fun <T1, T2> COpaquePointer.callContinuation2() {
val triple = this.asStableRef<Triple<StableRef<(T1, T2) -> Unit>, T1, T2>>().get()
triple.first.get()(triple.second, triple.third)
@@ -1,8 +1,8 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.concurrent
import kotlin.experimental.ExperimentalNativeApi
@@ -1,16 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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:Suppress("DEPRECATION")
@file:OptIn(ExperimentalForeignApi::class)
package kotlin.native.concurrent
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.internal.Frozen
import kotlin.concurrent.AtomicReference
import kotlinx.cinterop.ExperimentalForeignApi
@FreezingIsDeprecated
internal class FreezeAwareLazyImpl<out T>(initializer: () -> T) : Lazy<T> {
private val value_ = FreezableAtomicReference<Any?>(UNINITIALIZED)
// This cannot be made atomic because of the legacy MM. See https://github.com/JetBrains/kotlin-native/pull/3944
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.concurrent
@@ -1,8 +1,8 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.concurrent
import kotlinx.cinterop.*
@@ -77,6 +77,7 @@ public class DetachedObjectGraph<T> internal constructor(pointer: NativePtr) {
/**
* Returns raw C pointer value, usable for interoperability with C scenarious.
*/
@ExperimentalForeignApi
public fun asCPointer(): COpaquePointer? = interpretCPointer<COpaque>(stable.value)
}
@@ -1,8 +1,8 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.concurrent
import kotlin.experimental.ExperimentalNativeApi
@@ -1,11 +1,13 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.concurrent
import kotlin.native.internal.*
import kotlinx.cinterop.ExperimentalForeignApi
@GCUnsafeCall("Kotlin_WorkerBoundReference_create")
@ObsoleteWorkersApi
@@ -35,6 +37,7 @@ external private fun describeWorkerBoundReference(ref: NativePtr): String
@HasFreezeHook
@FreezingIsDeprecated
@ObsoleteWorkersApi
@OptIn(ExperimentalForeignApi::class)
public class WorkerBoundReference<out T : Any>(value: T) {
private var ptr = NativePtr.NULL
@@ -1,13 +1,15 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.internal
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.NativePointed
import kotlinx.cinterop.NativePtr
import kotlinx.cinterop.ExperimentalForeignApi
import kotlin.native.internal.TypedIntrinsic
import kotlin.native.internal.IntrinsicType
@@ -32,4 +34,4 @@ import kotlin.native.internal.IntrinsicType
@TypedIntrinsic(IntrinsicType.IDENTITY) @PublishedApi external internal fun <T, R> T.reinterpret(): R
@TypedIntrinsic(IntrinsicType.THE_UNIT_INSTANCE) @ExportForCompiler external internal fun theUnitInstance(): Unit
@TypedIntrinsic(IntrinsicType.THE_UNIT_INSTANCE) @ExportForCompiler external internal fun theUnitInstance(): Unit
@@ -1,11 +1,13 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.internal
import kotlin.reflect.KClass
import kotlinx.cinterop.*
@ExportForCompiler
internal class KClassImpl<T : Any>(private val typeInfo: NativePtr) : KClass<T> {
@@ -1,16 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
@file:Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS")
package kotlin.native.internal
import kotlinx.cinterop.*
@TypedIntrinsic(IntrinsicType.INTEROP_GET_NATIVE_NULL_PTR)
@PublishedApi
internal external fun getNativeNullPtr(): NativePtr
@ExperimentalForeignApi
class NativePtr @PublishedApi internal constructor(private val value: NonNullNativePtr?) {
companion object {
// TODO: make it properly precreated, maybe use an intrinsic for that.
@@ -1,11 +1,12 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.internal
import kotlin.experimental.ExperimentalNativeApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
import kotlin.coroutines.native.internal.*
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
@file:Suppress("DEPRECATION", "DEPRECATION_ERROR") // Char.toInt()
package kotlin.native.internal
@@ -10,6 +11,7 @@ import kotlin.experimental.ExperimentalNativeApi
import kotlin.internal.getProgressionLastElement
import kotlin.reflect.KClass
import kotlin.native.concurrent.freeze
import kotlinx.cinterop.*
import kotlin.native.concurrent.FreezableAtomicReference
@ExportForCppRuntime
@@ -1,11 +1,13 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.internal
import kotlin.reflect.KClass
import kotlinx.cinterop.*
@ExportForCppRuntime
internal fun DescribeObjectForDebugging(typeInfo: NativePtr, address: NativePtr): String {
@@ -51,4 +53,4 @@ public fun Any.collectReferenceFieldValues() : List<Any> {
getObjectReferenceFieldByIndex(this@collectReferenceFieldValues, it)
}
}
}
}
@@ -3,12 +3,14 @@
* 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(ExperimentalForeignApi::class)
package kotlin.native.ref
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.concurrent.*
import kotlin.native.internal.*
import kotlinx.cinterop.NativePtr
import kotlinx.cinterop.*
/**
* The marker interface for objects that have a cleanup action associated with them.
@@ -1,11 +1,11 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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(ExperimentalForeignApi::class)
package kotlin.native.ref
import kotlinx.cinterop.COpaquePointer
import kotlinx.cinterop.*
import kotlin.native.internal.*
/**
@@ -3,6 +3,7 @@
* 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(ExperimentalForeignApi::class)
package kotlin.native.runtime
import kotlin.native.internal.*
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2023 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.
*/
package kotlin.native
@@ -7,8 +7,10 @@ package kotlin.native
import kotlin.native.internal.GCUnsafeCall
import kotlin.native.internal.TypedIntrinsic
import kotlin.native.internal.IntrinsicType
import kotlinx.cinterop.ExperimentalForeignApi
@ExperimentalForeignApi
public final class Vector128 private constructor() {
@TypedIntrinsic(IntrinsicType.EXTRACT_ELEMENT)
external fun getByteAt(index: Int): Byte
@@ -52,8 +54,10 @@ public final class Vector128 private constructor() {
}
}
@ExperimentalForeignApi
@GCUnsafeCall("Kotlin_Vector4f_of")
external fun vectorOf(f0: Float, f1: Float, f2: Float, f3: Float): Vector128
@ExperimentalForeignApi
@GCUnsafeCall("Kotlin_Vector4i32_of")
external fun vectorOf(f0: Int, f1: Int, f2: Int, f3: Int): Vector128