diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/CallableMethod.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/CallableMethod.kt index b2d2f07024e..ec2ba11137a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/CallableMethod.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/CallableMethod.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.org.objectweb.asm.Opcodes import org.jetbrains.org.objectweb.asm.Opcodes.INVOKESPECIAL import org.jetbrains.org.objectweb.asm.Opcodes.INVOKESTATIC import org.jetbrains.org.objectweb.asm.Type @@ -23,15 +22,15 @@ class CallableMethod( private val defaultImplOwner: Type?, computeDefaultMethodDesc: () -> String, private val signature: JvmMethodSignature, - private val invokeOpcode: Int, + val invokeOpcode: Int, override val dispatchReceiverType: Type?, override val dispatchReceiverKotlinType: KotlinType?, override val extensionReceiverType: Type?, override val extensionReceiverKotlinType: KotlinType?, override val generateCalleeType: Type?, override val returnKotlinType: KotlinType?, - private val isInterfaceMethod: Boolean = Opcodes.INVOKEINTERFACE == invokeOpcode, - private val isDefaultMethodInInterface: Boolean = false + val isInterfaceMethod: Boolean, + private val isDefaultMethodInInterface: Boolean ) : Callable { private val defaultMethodDesc: String by lazy(LazyThreadSafetyMode.PUBLICATION, computeDefaultMethodDesc) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index bd57694c758..01fa3bb0cd1 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -412,9 +412,9 @@ class ExpressionCodegen( immaterialUnitValue expression.type.isUnit() -> // NewInference allows casting `() -> T` to `() -> Unit`. A CHECKCAST here will fail. - MaterialValue(this, callable.returnType, returnType).discard().coerce(expression.type) + MaterialValue(this, callable.asmMethod.returnType, returnType).discard().coerce(expression.type) else -> - MaterialValue(this, callable.returnType, returnType).coerce(expression.type) + MaterialValue(this, callable.asmMethod.returnType, returnType).coerce(expression.type) } } @@ -983,7 +983,7 @@ class ExpressionCodegen( return classReference.onStack } - private fun resolveToCallable(irCall: IrFunctionAccessExpression, isSuper: Boolean) = + private fun resolveToCallable(irCall: IrFunctionAccessExpression, isSuper: Boolean): IrCallableMethod = typeMapper.mapToCallableMethod(irCall.symbol.owner, isSuper) private fun getOrCreateCallGenerator(element: IrFunctionAccessExpression, data: BlockInfo): IrCallGenerator { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrCallGenerator.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrCallGenerator.kt index 9545ce6ee98..6cada16b62f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrCallGenerator.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrCallGenerator.kt @@ -16,20 +16,18 @@ package org.jetbrains.kotlin.backend.jvm.codegen -import org.jetbrains.kotlin.codegen.Callable -import org.jetbrains.kotlin.codegen.CallableMethod import org.jetbrains.kotlin.codegen.StackValue import org.jetbrains.kotlin.codegen.ValueKind import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression -import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.org.objectweb.asm.Type interface IrCallGenerator { - - fun genCall(callableMethod: Callable, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression) { - callableMethod.genInvokeInstruction(codegen.mv) + fun genCall(callableMethod: IrCallableMethod, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression) { + with(callableMethod) { + codegen.mv.visitMethodInsn(invokeOpcode, owner.internalName, asmMethod.name, asmMethod.descriptor, isInterfaceMethod) + } } fun beforeValueParametersStart() { @@ -51,4 +49,4 @@ interface IrCallGenerator { } object DefaultCallGenerator : IrCallGenerator -} \ No newline at end of file +} diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrCallableMethod.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrCallableMethod.kt new file mode 100644 index 00000000000..603769e4959 --- /dev/null +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrCallableMethod.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2019 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. + */ + +package org.jetbrains.kotlin.backend.jvm.codegen + +import org.jetbrains.org.objectweb.asm.Type +import org.jetbrains.org.objectweb.asm.commons.Method + +class IrCallableMethod( + val owner: Type, + val valueParameterTypes: List, + val invokeOpcode: Int, + val asmMethod: Method, + val dispatchReceiverType: Type?, + val extensionReceiverType: Type?, + val isInterfaceMethod: Boolean +) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt index 2425d348457..185402e4778 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt @@ -98,7 +98,7 @@ class IrInlineCodegen( } override fun genCall( - callableMethod: Callable, + callableMethod: IrCallableMethod, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression ) { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrTypeMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrTypeMapper.kt index 2769a60c7c6..ddb8855f0e8 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrTypeMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrTypeMapper.kt @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.load.kotlin.TypeMappingMode import org.jetbrains.kotlin.load.kotlin.computeExpandedTypeForInlineClass import org.jetbrains.kotlin.load.kotlin.mapBuiltInType import org.jetbrains.kotlin.name.SpecialNames -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature @@ -66,8 +65,12 @@ class IrTypeMapper(private val context: JvmBackendContext) { fun mapSignatureWithGeneric(f: IrFunction, kind: OwnerKind): JvmMethodGenericSignature = kotlinTypeMapper.mapSignatureWithGeneric(f.descriptor, kind) - fun mapToCallableMethod(f: IrFunction, superCall: Boolean, kind: OwnerKind? = null, resolvedCall: ResolvedCall<*>? = null) = - kotlinTypeMapper.mapToCallableMethod(f.descriptor, superCall, kind, resolvedCall) + fun mapToCallableMethod(f: IrFunction, superCall: Boolean): IrCallableMethod = + with(kotlinTypeMapper.mapToCallableMethod(f.descriptor, superCall)) { + IrCallableMethod( + owner, valueParameterTypes, invokeOpcode, getAsmMethod(), dispatchReceiverType, extensionReceiverType, isInterfaceMethod + ) + } fun writeFormalTypeParameters(irParameters: List, sw: JvmSignatureWriter) = kotlinTypeMapper.writeFormalTypeParameters(irParameters.map { it.descriptor }, sw)