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
+13 -5
View File
@@ -1,11 +1,14 @@
/*
* 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.
*/
import org.jetbrains.kotlin.cpp.CppConsumerPlugin
import org.jetbrains.kotlin.cpp.CppUsage
import org.jetbrains.kotlin.cpp.DependencyHandlerExKt
import org.jetbrains.kotlin.tools.NativePluginKt
/*
* 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.
*/
buildscript {
apply from: "../../kotlin-native/gradle/kotlinGradlePlugin.gradle"
apply plugin: 'project-report'
@@ -31,7 +34,12 @@ sourceSets {
compileCompilerKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += ['-opt-in=kotlin.RequiresOptIn', '-opt-in=org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI', '-Xskip-prerelease-check']
kotlinOptions.freeCompilerArgs += [
'-opt-in=kotlin.RequiresOptIn',
'-opt-in=org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI',
"-opt-in=kotlinx.cinterop.BetaInteropApi",
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
'-Xskip-prerelease-check']
}
compileCli_bcKotlin {
@@ -116,6 +116,7 @@ if (!isExperimentalMM) {
tasks.withType(KonanCompileNativeBinary).configureEach {
extraOpts "-XXLanguage:+ImplicitSignedToUnsignedIntegerConversion"
extraOpts "-opt-in=kotlinx.cinterop.ExperimentalForeignApi"
}
allprojects {
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
package codegen.bridges.nativePointed
import kotlinx.cinterop.*
@@ -1,8 +1,8 @@
/*
* Copyright 2010-2021 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(kotlinx.cinterop.ExperimentalForeignApi::class)
package codegen.funInterface.kt43887
import kotlin.test.*
@@ -1,5 +1,6 @@
package codegen.intrinsics.interop_convert
@file:OptIn(ExperimentalForeignApi::class)
package codegen.intrinsics.interop_convert
import kotlin.test.*
import kotlinx.cinterop.*
@@ -1,3 +1,6 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.native.internal.InternalForKotlinNative::class)
package codegen.intrinsics.interop_sourceCodeStruct
import kotlinx.cinterop.*
@@ -5,8 +8,8 @@ import kotlinx.cinterop.internal.*
import kotlin.test.*
// Just making sure this doesn't get accidentally forbidden or otherwise broken.
// (however defining structs this way is still strongly discouraged, please define
// structs in C headers or .def files instead).
// Used by auto-generated code, user-defined structs should be declared via
// structs in C headers or .def files instead.
@CStruct("struct { int p0; int p1; }")
class S(rawPtr: NativePtr) : CStructVar(rawPtr) {
@@ -1,7 +1,10 @@
/*
* 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.
* Copyright 2010-2023 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(kotlinx.cinterop.ExperimentalForeignApi::class)
import signext_zeroext_interop_input.*
import kotlinx.cinterop.*
@@ -1,7 +1,9 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import auxiliaryCppSources.*
import kotlin.test.*
import kotlinx.cinterop.*
fun main() {
assertEquals(name()!!.toKString(), "Hello from C++")
}
}
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import sysstat.*
import kotlinx.cinterop.*
@@ -11,4 +12,4 @@ fun main(args: Array<String>) {
val res = stat("/", statBuf.ptr)
println(res)
println(statBuf.st_uid)
}
}
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import cstdlib.*
import kotlinx.cinterop.*
@@ -14,4 +15,4 @@ fun main(args: Array<String>) {
println(quot)
println(rem)
}
}
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import cstdio.*
import kotlinx.cinterop.*
@@ -19,4 +20,4 @@ fun main(args: Array<String>) {
val sscanfResult = sscanf("42", "%d%d", aVar.ptr, bVar.ptr)
printf("%d %d\n", sscanfResult, aVar.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(kotlinx.cinterop.ExperimentalForeignApi::class)
import platform.posix.printf
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import carrayPointers.*
import kotlin.test.*
import kotlinx.cinterop.*
@@ -13,4 +15,4 @@ fun main() {
struct.arrayPointer = globalArray
assertEquals(globalArray[0], struct.arrayPointer!![0])
}
}
}
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlin.native.*
import kotlin.test.*
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import bitfields.*
import kotlinx.cinterop.*
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlin.test.*
import kotlinx.cinterop.*
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import sockets.*
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 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(kotlinx.cinterop.ExperimentalForeignApi::class)
import cenums.*
import kotlinx.cinterop.*
@@ -27,4 +28,4 @@ fun main() {
// assertEquals(entries[0], E.A)
// assertEquals(entries[1], E.B)
// assertEquals(entries[2], E.C)
}
}
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import cfunptr.*
@@ -43,4 +44,4 @@ fun main(args: Array<String>) {
printIntPtr(notSoLongSignatureFunction(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}
fun Boolean.ifThenOneElseZero() = if (this) 1 else 0
fun Boolean.ifThenOneElseZero() = if (this) 1 else 0
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import cglobals.*
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlin.test.*
import cmacros.*
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import platform.GLUT.*
@@ -113,4 +114,4 @@ fun main(args: Array<String>) {
// run GLUT mainloop
glutMainLoop()
}
}
@@ -1,7 +1,8 @@
/*
* 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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlin.test.*
import kotlinx.cinterop.*
@@ -1,3 +1,6 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import kotlin.test.*
import structAnonym.*
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import cstructs.*
import kotlinx.cinterop.*
import kotlin.test.*
@@ -116,4 +118,4 @@ fun <T : E> checkEnumSubTyping(e: T) = memScoped {
fun <T : Int> checkIntSubTyping(x: T) = memScoped {
val s = alloc<Trivial>()
s.i = x
}
}
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import ctoKString.*
import kotlinx.cinterop.*
import kotlin.native.*
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import kotlin.native.*
import kotlin.test.*
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import cunion.*
import kotlinx.cinterop.*
import kotlin.native.*
@@ -33,4 +35,4 @@ fun main() {
union.i = 0u
assertEquals(0u, union.b)
}
}
}
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import kotlin.test.*
import cvalues.*
@@ -7,4 +9,4 @@ fun main() {
assertTrue(isNullWString(null))
assertFalse(isNullString("a"))
assertFalse(isNullWString("b"))
}
}
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import kotlin.native.*
import kotlin.test.*
@@ -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.
*/
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import kotlin.test.*
@@ -132,4 +134,4 @@ fun test2() {
println("x.useContents {iPub} = ${x.useContents {iPub}}" )
}
*/
*/
@@ -1,3 +1,4 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
@file:Suppress("OPT_IN_USAGE_ERROR")
import kotlinx.cinterop.*
@@ -1,3 +1,4 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
@file:Suppress("OPT_IN_USAGE_ERROR")
import kotlinx.cinterop.*
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import kotlin.test.*
import kotlin.random.*
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.staticCFunction
import cCallback.runAndCatch
@@ -8,4 +10,4 @@ fun throwingCallback() {
fun main() {
runAndCatch(staticCFunction(::throwingCallback))
}
}
@@ -1,4 +1,5 @@
// This test mostly checks frontend behaviour.
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import cForwardDeclarations.*
import cnames.structs.StructDeclared
@@ -1,4 +1,5 @@
// This test mostly checks frontend behaviour.
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import cForwardDeclarationsTwoLibs1.*
import cForwardDeclarationsTwoLibs2.*
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import library.*
import kotlinx.cinterop.*
import kotlin.test.*
@@ -23,4 +25,4 @@ fun main() {
for (i in 0 until arrayLength()) {
assertEquals(0x1, array[i])
}
}
}
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 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(kotlinx.cinterop.ExperimentalForeignApi::class)
import kt51925.*
import kotlinx.cinterop.*
@@ -20,4 +21,4 @@ inline fun foo2(): Int {
s.d = 42
return bar2(s)
}
}
}
@@ -3,7 +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(FreezingIsDeprecated::class)
@file:OptIn(FreezingIsDeprecated::class, kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.atomics.atomic_smoke
import kotlin.test.*
@@ -2,7 +2,8 @@
* Copyright 2010-2020 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(ExperimentalStdlibApi::class, FreezingIsDeprecated::class, kotlin.native.runtime.NativeRuntimeApi::class)
@file:OptIn(ExperimentalStdlibApi::class, FreezingIsDeprecated::class,
kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.basic.cleaner_basic
@@ -1,7 +1,8 @@
/*
* Copyright 2010-2019 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(kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.basic.simd
@@ -1,7 +1,8 @@
/*
* 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(kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.collections.array5
@@ -1,3 +1,5 @@
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.interop.interop_alloc_value
import kotlinx.cinterop.*
@@ -3,7 +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(kotlin.ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
@file:OptIn(kotlin.ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlin.native.runtime.GC
import kotlin.test.*
@@ -2,7 +2,7 @@
* Copyright 2010-2020 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, ObsoleteWorkersApi::class)
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.memory.stable_ref_cross_thread_check
@@ -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(kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.text.utf8
@@ -1,4 +1,5 @@
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class, ObsoleteWorkersApi::class)
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class, ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.workers.worker10
import kotlin.test.*
@@ -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, ObsoleteWorkersApi::class)
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
package runtime.workers.worker8