diff --git a/Interop/Indexer/prebuilt/nativeInteropStubs/kotlin/clang/clang.kt b/Interop/Indexer/prebuilt/nativeInteropStubs/kotlin/clang/clang.kt index 95d3e111507..5dabd5b5aa2 100644 --- a/Interop/Indexer/prebuilt/nativeInteropStubs/kotlin/clang/clang.kt +++ b/Interop/Indexer/prebuilt/nativeInteropStubs/kotlin/clang/clang.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -@file:Suppress("UNUSED_EXPRESSION") +@file:Suppress("UNUSED_EXPRESSION", "UNUSED_VARIABLE") package clang import kotlinx.cinterop.* diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt index f3d7ccf0645..9f05b1931e2 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt @@ -203,18 +203,17 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() { CXCursorKind.CXCursor_UnionDecl -> return false - CXCursorKind.CXCursor_StructDecl -> memScoped { - val hasAttributes = memScope.alloc() - hasAttributes.value = 0 - clang_visitChildren(structDefCursor, staticCFunction { cursor, parent, clientData -> - if (clang_isAttribute(cursor.kind.value) != 0) { - val hasAttributes = clientData!!.reinterpret().pointed - hasAttributes.value = 1 + CXCursorKind.CXCursor_StructDecl -> { + var hasAttributes = false + + visitChildren(structDefCursor) { cursor, _ -> + if (clang_isAttribute(cursor.kind) != 0) { + hasAttributes = true } CXChildVisitResult.CXChildVisit_Continue - }, hasAttributes.ptr) + } - return hasAttributes.value == 0 + return !hasAttributes } else -> throw IllegalArgumentException(defKind.toString()) @@ -332,6 +331,10 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() { CXIdxEntity_Enum -> { getEnumDefAt(cursor) } + + else -> { + // Ignore declaration. + } } } @@ -365,6 +368,7 @@ private fun indexDeclarations(library: NativeLibrary, nativeIndex: NativeIndexIm importedASTFile.value = null startedTranslationUnit.value = null indexDeclaration.value = staticCFunction { clientData, info -> + @Suppress("NAME_SHADOWING") val nativeIndex = StableObjPtr.fromValue(clientData!!).get() as NativeIndexImpl nativeIndex.indexDeclaration(info!!.pointed) } diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt index f425ef04155..a97d49d26b9 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt @@ -139,7 +139,7 @@ private fun processCodeSnippet( var longValue: Long? = null var doubleValue: Double? = null - val visitor: CursorVisitor = { cursor, parent -> + val visitor: CursorVisitor = { cursor, _ -> val kind = cursor.kind when { state == VisitorState.EXPECT_VARIABLE && kind == CXCursorKind.CXCursor_VarDecl -> { @@ -216,7 +216,7 @@ private fun collectMacroConstantsNames(library: NativeLibrary): List { val translationUnit = library.parse(index, options).ensureNoCompileErrors() try { - visitChildren(translationUnit) { cursor, parent -> + visitChildren(translationUnit) { cursor, _ -> if (cursor.kind == CXCursorKind.CXCursor_MacroDefinition && library.includesDeclaration(cursor) && canMacroBeConstant(cursor)) diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt index d4ce394dbcc..cf4aeaa5d93 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt @@ -117,6 +117,7 @@ internal fun visitChildren(parent: CValue, visitor: CursorVisitor) { val visitorPtr = StableObjPtr.create(visitor) val clientData = visitorPtr.value clang_visitChildren(parent, staticCFunction { cursor, parent, clientData -> + @Suppress("NAME_SHADOWING", "UNCHECKED_CAST") val visitor = StableObjPtr.fromValue(clientData!!).get() as CursorVisitor visitor(cursor.readValue(), parent.readValue()) }, clientData) diff --git a/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmCallbacks.kt b/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmCallbacks.kt index 9f8332e5249..264c947dda5 100644 --- a/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmCallbacks.kt +++ b/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmCallbacks.kt @@ -233,9 +233,10 @@ private fun ffiCreateCif(returnType: ffi_type, paramTypes: List): ffi_ return interpretPointed(res) } +@Suppress("UNUSED_PARAMETER") private fun ffiFunImpl0(ffiCif: Long, ret: Long, args: Long, userData: Any) { - ffiFunImpl(interpretPointed(ffiCif), - interpretCPointer(ret)!!, + @Suppress("UNCHECKED_CAST") + ffiFunImpl(interpretCPointer(ret)!!, interpretCPointer(args)!!, userData as UserData) } @@ -246,8 +247,7 @@ private fun ffiFunImpl0(ffiCif: Long, ret: Long, args: Long, userData: Any) { * @param ret pointer to memory to be filled with return value of the invoked native function * @param args pointer to array of pointers to arguments passed to the invoked native function */ -private fun ffiFunImpl(ffiCif: ffi_cif, ret: COpaquePointer, args: CArrayPointer, - userData: UserData) { +private fun ffiFunImpl(ret: COpaquePointer, args: CArrayPointer, userData: UserData) { userData.invoke(ret, args) } diff --git a/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmTypes.kt b/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmTypes.kt index 8863b72910e..d5c143c2376 100644 --- a/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmTypes.kt +++ b/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmTypes.kt @@ -16,8 +16,8 @@ package kotlinx.cinterop -import kotlin.reflect.companionObjectInstance -import kotlin.reflect.primaryConstructor +import kotlin.reflect.full.companionObjectInstance +import kotlin.reflect.full.primaryConstructor typealias NativePtr = Long val nativeNullPtr: NativePtr = 0L @@ -40,6 +40,7 @@ inline fun interpretNullablePointed(ptr: NativePtr): if (primaryConstructor == null) { throw IllegalArgumentException("${kClass.simpleName} doesn't have a constructor") } + @Suppress("UNCHECKED_CAST") return (primaryConstructor as (NativePtr) -> T)(ptr) } } diff --git a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt index 30be39f268a..5e070f1f89f 100644 --- a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt +++ b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt @@ -237,26 +237,32 @@ abstract class CEnumVar : CPrimitiveVar() // generics below are used for typedef support // these classes are not supposed to be used directly, instead the typealiases are provided. +@Suppress("FINAL_UPPER_BOUND") class CInt8VarWithValueMappedTo(override val rawPtr: NativePtr) : CPrimitiveVar() { companion object : Type(1) } +@Suppress("FINAL_UPPER_BOUND") class CInt16VarWithValueMappedTo(override val rawPtr: NativePtr) : CPrimitiveVar() { companion object : Type(2) } +@Suppress("FINAL_UPPER_BOUND") class CInt32VarWithValueMappedTo(override val rawPtr: NativePtr) : CPrimitiveVar() { companion object : Type(4) } +@Suppress("FINAL_UPPER_BOUND") class CInt64VarWithValueMappedTo(override val rawPtr: NativePtr) : CPrimitiveVar() { companion object : Type(8) } +@Suppress("FINAL_UPPER_BOUND") class CFloat32VarWithValueMappedTo(override val rawPtr: NativePtr) : CPrimitiveVar() { companion object : Type(4) } +@Suppress("FINAL_UPPER_BOUND") class CFloat64VarWithValueMappedTo(override val rawPtr: NativePtr) : CPrimitiveVar() { companion object : Type(8) } @@ -268,28 +274,34 @@ typealias CInt64Var = CInt64VarWithValueMappedTo typealias CFloat32Var = CFloat32VarWithValueMappedTo typealias CFloat64Var = CFloat64VarWithValueMappedTo +@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST") var CInt8VarWithValueMappedTo.value: T get() = nativeMemUtils.getByte(this) as T set(value) = nativeMemUtils.putByte(this, value) +@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST") var CInt16VarWithValueMappedTo.value: T get() = nativeMemUtils.getShort(this) as T set(value) = nativeMemUtils.putShort(this, value) +@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST") var CInt32VarWithValueMappedTo.value: T get() = nativeMemUtils.getInt(this) as T set(value) = nativeMemUtils.putInt(this, value) +@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST") var CInt64VarWithValueMappedTo.value: T get() = nativeMemUtils.getLong(this) as T set(value) = nativeMemUtils.putLong(this, value) // TODO: ensure native floats have the appropriate binary representation +@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST") var CFloat32VarWithValueMappedTo.value: T get() = nativeMemUtils.getFloat(this) as T set(value) = nativeMemUtils.putFloat(this, value) +@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST") var CFloat64VarWithValueMappedTo.value: T get() = nativeMemUtils.getDouble(this) as T set(value) = nativeMemUtils.putDouble(this, value) @@ -307,6 +319,7 @@ typealias CPointerVar = CPointerVarWithValueMappedTo> /** * The value of this variable. */ +@Suppress("UNCHECKED_CAST") inline var

> CPointerVarWithValueMappedTo

.value: P? get() = interpretCPointer(nativeMemUtils.getNativePtr(this)) as P? set(value) = nativeMemUtils.putNativePtr(this, value.rawValue) diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt index 33ced7b9617..f296a95bef0 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt @@ -1192,7 +1192,7 @@ class StubGenerator( * Produces to [out] the contents of file with Kotlin bindings. */ fun generateKotlinFile() { - out("@file:Suppress(\"UNUSED_EXPRESSION\")") + out("@file:Suppress(\"UNUSED_EXPRESSION\", \"UNUSED_VARIABLE\")") if (pkgName != "") { out("package $pkgName") out("") diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt index 526e523f20f..4d72a7a3825 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt @@ -136,6 +136,7 @@ private fun runCmd(command: Array, workDir: File, verbose: Boolean = fal private fun maybeExecuteHelper(dependenciesRoot: String, properties: Properties, dependencies: List) { try { val kClass = Class.forName("org.jetbrains.kotlin.konan.Helper0").kotlin + @Suppress("UNCHECKED_CAST") val ctor = kClass.constructors.single() as KFunction val result = ctor.call(dependenciesRoot, properties, dependencies) result.run() diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/IrValidator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/IrValidator.kt index 05cdd6a0793..3c50396a18b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/IrValidator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/IrValidator.kt @@ -42,7 +42,10 @@ fun validateIrModule(context: BackendContext, irModule: IrModuleFragment) { irModule.acceptVoid(visitor) // TODO: investigate and re-enable - return + val ENABLE_EXTENDED_VALIDATION = false + if (!ENABLE_EXTENDED_VALIDATION) { + return + } val moduleDeclarations = visitor.foundDeclarations diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/Autoboxing.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/Autoboxing.kt index 73b1f933246..42496808c23 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/Autoboxing.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/Autoboxing.kt @@ -188,6 +188,7 @@ private class AutoboxingTransformer(val context: Context) : AbstractValueUsageTr /** * Casts this expression to `type` without changing its representation in generated code. */ + @Suppress("UNUSED_PARAMETER") private fun IrExpression.uncheckedCast(type: KotlinType): IrExpression { // TODO: apply some cast if types are incompatible; not required currently. return this diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt index cb6366b431d..b2ab3fe9837 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt @@ -106,6 +106,7 @@ private class InteropTransformer(val context: Context, val irFile: IrFile) : IrB return alignOf(typeObject) } + @Suppress("UNUSED_PARAMETER") private fun IrBuilderWithScope.interpretPointed(expression: IrCall, type: KotlinType): IrExpression = irCall(interop.interpretNullablePointed).apply { putValueArgument(0, expression) @@ -149,6 +150,7 @@ private class InteropTransformer(val context: Context, val irFile: IrFile) : IrB } } + @Suppress("UNUSED_PARAMETER") private fun IrBuilderWithScope.nativePointedToCPointer( expression: IrExpression, pointeeType: KotlinType ): IrExpression = irCall(interop.interpretCPointer).apply {