From bf67bc38fc5c87e3bddcfe457de145dde251e2f2 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 18 Dec 2017 14:45:52 +0300 Subject: [PATCH] Fix few compiler warnings. (#1158) --- .../interop/gen/MappingBridgeGeneratorImpl.kt | 2 +- .../kotlin/native/interop/gen/Mappings.kt | 2 +- .../kotlin/native/interop/gen/jvm/main.kt | 2 +- .../backend/konan/NativeBackendFacade.kt | 27 ------------------- .../kotlin/backend/konan/descriptors/utils.kt | 22 --------------- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 17 +++++------- .../backend/konan/llvm/VariableManager.kt | 2 +- .../llvm/objcexport/BlockPointerSupport.kt | 4 +-- .../backend/konan/lower/ForLoopsLowering.kt | 2 +- .../backend/konan/lower/FunctionInlining.kt | 2 +- .../konan/lower/SuspendFunctionsLowering.kt | 2 +- 11 files changed, 16 insertions(+), 68 deletions(-) delete mode 100644 backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/NativeBackendFacade.kt diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/MappingBridgeGeneratorImpl.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/MappingBridgeGeneratorImpl.kt index afdd7141524..6c52e5d0971 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/MappingBridgeGeneratorImpl.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/MappingBridgeGeneratorImpl.kt @@ -38,7 +38,7 @@ class MappingBridgeGeneratorImpl( ): KotlinExpression { val bridgeArguments = mutableListOf() - kotlinValues.forEachIndexed { index, (type, value) -> + kotlinValues.forEach { (type, value) -> if (type.unwrapTypedefs() is RecordType) { builder.pushMemScoped() val bridgeArgument = "$value.getPointer(memScope).rawValue" diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/Mappings.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/Mappings.kt index 6d51b46ffe6..3ab4f3678f9 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/Mappings.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/Mappings.kt @@ -288,7 +288,7 @@ sealed class TypeInfo { ): KotlinExpression { val mappingBridgeGenerator = scope.mappingBridgeGenerator - val funParameters = type.parameterTypes.mapIndexed { index, it -> + val funParameters = type.parameterTypes.mapIndexed { index, _ -> "p$index" to kotlinType.parameterTypes[index] }.joinToString { "${it.first}: ${it.second.render(scope)}" } 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 32ec394756c..3e57ad4612c 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 @@ -391,7 +391,7 @@ private fun processLib(args: Map>, def.manifestAddendProperties["includedHeaders"] = nativeIndex.includedHeaders.joinToString(" ") { it.value } def.manifestAddendProperties.putAndRunOnReplace("package", outKtPkg) { - key, oldValue, newValue -> + _, oldValue, newValue -> warn("The package value `$oldValue` specified in .def file is overriden with explicit $newValue") } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/NativeBackendFacade.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/NativeBackendFacade.kt deleted file mode 100644 index 3d896be75e0..00000000000 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/NativeBackendFacade.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.backend.konan - -import org.jetbrains.kotlin.codegen.CompilationErrorHandler -import org.jetbrains.kotlin.codegen.state.GenerationState -import org.jetbrains.kotlin.psi.KtFile - -object NativeBackendFacade { - fun doGenerateFiles(files: Collection, state: GenerationState, errorHandler: CompilationErrorHandler) { - TODO() - } -} diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt index ee719ee84b3..7342511abd6 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt @@ -24,28 +24,6 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.types.KotlinType -fun ClassDescriptor?.getter2Descriptor(methodName: Name) = this?.let { - this.unsubstitutedMemberScope.getContributedDescriptors{true} - .firstOrNull { - it.name == methodName - } ?.let { - return@let (it as? PropertyDescriptor)?.getter - } -} - -fun ClassDescriptor?.signature2Descriptor(methodName: Name, signature:Array = emptyArray()) = this?.let { - this - .unsubstitutedMemberScope - .getContributedFunctions(methodName, NoLookupLocation.FROM_BACKEND) - .firstOrNull { - return@firstOrNull it.valueParameters.size == signature.size - && (signature.isEmpty() || it.valueParameters.any { - p -> val index = it.valueParameters.indexOf(p) - return@any p.type == signature[index] - }) - } -} - val DeserializedPropertyDescriptor.backingField: PropertyDescriptor? get() = if (this.proto.getExtension(KonanLinkData.hasBackingField)) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index bda5e7fd44d..99228a8fcaf 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -514,7 +514,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map return LLVMConstInt(LLVMInt16Type(), (value.value as Short).toLong(), 1)!! IrConstKind.Int -> return LLVMConstInt(LLVMInt32Type(), (value.value as Int).toLong(), 1)!! IrConstKind.Long -> return LLVMConstInt(LLVMInt64Type(), value.value as Long, 1)!! - IrConstKind.String -> return evaluateStringConst(value as IrConst) + IrConstKind.String -> return evaluateStringConst(@Suppress("UNCHECKED_CAST") value as IrConst) IrConstKind.Float -> return LLVMConstRealOfString(LLVMFloatType(), (value.value as Float).toString())!! IrConstKind.Double -> return LLVMConstRealOfString(LLVMDoubleType(), (value.value as Double).toString())!! } @@ -1634,6 +1634,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map { + @Suppress("UNCHECKED_CAST") val arg = expression.getValueArgument(0) as IrConst return context.llvm.staticData.createImmutableBinaryBlob(arg) } @@ -1666,12 +1667,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map return delegatingConstructorCall(value.descriptor, args) - value.descriptor is FunctionDescriptor -> - return evaluateFunctionCall( - value as IrCall, args, resultLifetime(value)) - else -> { - TODO(ir2string(value)) - } + else -> + return evaluateFunctionCall(value as IrCall, args, resultLifetime(value)) } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/VariableManager.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/VariableManager.kt index 8731e0caefc..004d4ab62fa 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/VariableManager.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/VariableManager.kt @@ -89,7 +89,7 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration } internal var skip = 0 - internal fun createParameter(descriptor: ValueDescriptor, value: LLVMValueRef? = null, variableLocation: VariableDebugLocation?) : Int { + internal fun createParameter(descriptor: ValueDescriptor, variableLocation: VariableDebugLocation?) : Int { assert(!contextVariablesToIndex.contains(descriptor)) val index = variables.size val type = functionGenerationContext.getLLVMType(descriptor.type) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/BlockPointerSupport.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/BlockPointerSupport.kt index f6aef0a8e61..6e223bc1c30 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/BlockPointerSupport.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/BlockPointerSupport.kt @@ -194,8 +194,8 @@ internal class BlockAdapterToFunctionGenerator(val objCExportCodeGenerator: ObjC val blockOnStackBase = structGep(blockOnStack, 0) val slot = structGep(blockOnStack, 1) - listOf(bitcast(int8TypePtr, isa), flags, reserved, invoke, descriptor).forEachIndexed { index, it -> - storeAny(it, structGep(blockOnStackBase, index)) + listOf(bitcast(int8TypePtr, isa), flags, reserved, invoke, descriptor).forEachIndexed { index, value -> + storeAny(value, structGep(blockOnStackBase, index)) } // Note: it is the slot in the block located on stack, so no need to manage it properly: diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ForLoopsLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ForLoopsLowering.kt index 982f34cd219..4a3c3525111 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ForLoopsLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ForLoopsLowering.kt @@ -113,7 +113,7 @@ private class ForLoopsTransformer(val context: Context) : IrElementTransformerVo pkg: FqName, filter: (SimpleFunctionDescriptor) -> Boolean): Set = mutableSetOf().apply { - progressionElementClasses.flatMapTo(this) { receiver -> + progressionElementClasses.flatMapTo(this) { _ /* receiver */ -> context.builtIns.builtInsModule.getPackage(pkg).memberScope .getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND) .filter(filter).map { symbols.symbolTable.referenceFunction(it) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt index 0847bcbb6f1..3ccf8d71335 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt @@ -204,7 +204,7 @@ private class Inliner(val globalSubstituteMap: MutableMap