From 78c043f15ff51660068f7f97da807e1d5ab2742b Mon Sep 17 00:00:00 2001 From: Konstantin Anisimov Date: Tue, 11 Apr 2017 18:16:55 +0700 Subject: [PATCH] All FunctionDescriptors on call sites must be copied --- .../common/DeepCopyIrTreeWithDescriptoros.kt | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 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 730f43d8e17..f63af8e0044 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 @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.backend.common import org.jetbrains.kotlin.backend.common.lower.SimpleMemberScope import org.jetbrains.kotlin.backend.konan.Context -import org.jetbrains.kotlin.backend.konan.descriptors.isFunctionInvoke import org.jetbrains.kotlin.backend.konan.ir.IrInlineFunctionBody import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.* @@ -75,33 +74,6 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, } } - private fun copyIrCallImpl(oldExpression: IrCallImpl): IrCallImpl { - val oldDescriptor = oldExpression.descriptor - val newDescriptor = descriptorSubstituteMap.getOrDefault(oldDescriptor.original, - oldDescriptor) as FunctionDescriptor - - val newSuperQualifier = oldExpression.superQualifier?.let { (descriptorSubstituteMap[it] ?: it) as ClassDescriptor } - - val newExpression = IrCallImpl( - startOffset = oldExpression.startOffset, - endOffset = oldExpression.endOffset, - type = substituteType(oldExpression.type)!!, - descriptor = newDescriptor, - typeArguments = substituteTypeArguments(oldExpression.typeArguments), - origin = oldExpression.origin, - superQualifier = newSuperQualifier - ).apply { - oldExpression.descriptor.valueParameters.forEach { - val valueArgument = oldExpression.getValueArgument(it) - putValueArgument(it.index, valueArgument) - } - extensionReceiver = oldExpression.extensionReceiver - dispatchReceiver = oldExpression.dispatchReceiver - } - - return newExpression - } - //-------------------------------------------------------------------------// inner class DescriptorCollector: IrElementVisitorVoidWithContext() { @@ -191,10 +163,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, override fun visitCall(expression: IrCall) { - val descriptor = expression.descriptor as FunctionDescriptor - if (descriptor.isFunctionInvoke) { - val oldDescriptor = descriptor as SimpleFunctionDescriptor - // Containing declaration for value parameter is not that important - other lowerings should not rely on it. + val oldDescriptor = expression.descriptor as FunctionDescriptor + if (oldDescriptor is SimpleFunctionDescriptor) { val containingDeclaration = (targetScope.scope.scopeOwner as? CallableDescriptor) ?: oldDescriptor val newReturnType = substituteType(oldDescriptor.returnType)!! val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, containingDeclaration) @@ -573,6 +543,35 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, //-------------------------------------------------------------------------// + private fun copyIrCallImpl(oldExpression: IrCallImpl): IrCallImpl { + val oldDescriptor = oldExpression.descriptor + val newDescriptor = descriptorSubstituteMap.getOrDefault(oldDescriptor.original, + oldDescriptor) as FunctionDescriptor + + val newSuperQualifier = oldExpression.superQualifier?.let { (descriptorSubstituteMap[it] ?: it) as ClassDescriptor } + + val newExpression = IrCallImpl( + startOffset = oldExpression.startOffset, + endOffset = oldExpression.endOffset, + type = substituteType(oldExpression.type)!!, + descriptor = newDescriptor, + typeArguments = substituteTypeArguments(oldExpression.typeArguments), + origin = oldExpression.origin, + superQualifier = newSuperQualifier + ).apply { + oldExpression.descriptor.valueParameters.forEach { + val valueArgument = oldExpression.getValueArgument(it) + putValueArgument(it.index, valueArgument) + } + extensionReceiver = oldExpression.extensionReceiver + dispatchReceiver = oldExpression.dispatchReceiver + } + + return newExpression + } + + //-------------------------------------------------------------------------// + private fun substituteType(oldType: KotlinType?): KotlinType? { if (typeSubstitutor == null) return oldType if (oldType == null) return oldType