From 00a3dfc4b7a6ddd8210588670f7aa2f7bde89afd Mon Sep 17 00:00:00 2001 From: Konstantin Anisimov Date: Wed, 12 Apr 2017 15:23:15 +0700 Subject: [PATCH] Get rid of warnings in inliner code Fix problem with "Duplicate IR node" warning --- .../common/DeepCopyIrTreeWithDescriptoros.kt | 2 +- .../backend/konan/lower/FunctionInlining.kt | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDescriptoros.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDescriptoros.kt index 2502a8eeb20..1187ab295e1 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDescriptoros.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDescriptoros.kt @@ -392,7 +392,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, override fun mapEnumEntryDeclaration (descriptor: ClassDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as ClassDescriptor override fun mapVariableDeclaration (descriptor: VariableDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as VariableDescriptor override fun mapCatchParameterDeclaration (descriptor: VariableDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as VariableDescriptor - override fun mapErrorDeclaration (descriptor: DeclarationDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as DeclarationDescriptor + override fun mapErrorDeclaration (descriptor: DeclarationDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) override fun mapClassReference (descriptor: ClassDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as ClassDescriptor override fun mapValueReference (descriptor: ValueDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as ValueDescriptor 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 f8890778997..23b58a54199 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 @@ -14,6 +14,8 @@ * limitations under the License. */ +@file:Suppress("FoldInitializerAndIfToElvis") + package org.jetbrains.kotlin.backend.konan.lower import org.jetbrains.kotlin.backend.common.DeepCopyIrTreeWithDescriptors @@ -166,7 +168,7 @@ private class Inliner(val currentScope: ScopeWithIr, val context: Context) { if (functionArgument == null) return super.visitCall(expression) // It is not call of argument lambda - nothing to substitute. if (functionArgument !is IrBlock) return super.visitCall(expression) - val dispatchDescriptor = dispatchReceiver.descriptor // Check if this functional parameter has "noinline" tag + val dispatchDescriptor = dispatchReceiver.descriptor // Check if this functional parameter has "noInline" tag if (dispatchDescriptor is ValueParameterDescriptor && dispatchDescriptor.isNoinline) return super.visitCall(expression) @@ -287,7 +289,7 @@ private class Inliner(val currentScope: ScopeWithIr, val context: Context) { ) } - parameterDescriptor.varargElementType != null -> { // + parameterDescriptor.varargElementType != null -> { val emptyArray = IrVarargImpl( startOffset = irCall.startOffset, endOffset = irCall.endOffset, @@ -328,18 +330,17 @@ private class Inliner(val currentScope: ScopeWithIr, val context: Context) { return@forEach } - val currentScope = currentScope!! - val varName = currentScope.scope.scopeOwner.name.toString() + "_inline" - val newVar = currentScope.scope.createTemporaryVariable( // Create new variable and init it with the parameter expression. - irExpression = argumentExpression, - nameHint = varName, + val newExpression = copyIrElement.copy(argumentExpression, null) as IrExpression + val newVariable = currentScope.scope.createTemporaryVariable( // Create new variable and init it with the parameter expression. + irExpression = newExpression, + nameHint = functionDeclaration.descriptor.name.toString(), isMutable = false) - evaluationStatements.add(newVar) // Add initialization of the new variable in statement list. + evaluationStatements.add(newVariable) // Add initialization of the new variable in statement list. val getVal = IrGetValueImpl( // Create new expression, representing access the new variable. startOffset = currentScope.irElement.startOffset, endOffset = currentScope.irElement.endOffset, - descriptor = newVar.descriptor + descriptor = newVariable.descriptor ) parameterToArgumentNew[parameterDescriptor] = getVal // Parameter will be replaced with the new variable. }