JVM IR: introduce IrCallableMethod as a simpler replacement for CallableMethod
This commit is contained in:
@@ -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.JvmMethodParameterSignature
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
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.INVOKESPECIAL
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes.INVOKESTATIC
|
import org.jetbrains.org.objectweb.asm.Opcodes.INVOKESTATIC
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
@@ -23,15 +22,15 @@ class CallableMethod(
|
|||||||
private val defaultImplOwner: Type?,
|
private val defaultImplOwner: Type?,
|
||||||
computeDefaultMethodDesc: () -> String,
|
computeDefaultMethodDesc: () -> String,
|
||||||
private val signature: JvmMethodSignature,
|
private val signature: JvmMethodSignature,
|
||||||
private val invokeOpcode: Int,
|
val invokeOpcode: Int,
|
||||||
override val dispatchReceiverType: Type?,
|
override val dispatchReceiverType: Type?,
|
||||||
override val dispatchReceiverKotlinType: KotlinType?,
|
override val dispatchReceiverKotlinType: KotlinType?,
|
||||||
override val extensionReceiverType: Type?,
|
override val extensionReceiverType: Type?,
|
||||||
override val extensionReceiverKotlinType: KotlinType?,
|
override val extensionReceiverKotlinType: KotlinType?,
|
||||||
override val generateCalleeType: Type?,
|
override val generateCalleeType: Type?,
|
||||||
override val returnKotlinType: KotlinType?,
|
override val returnKotlinType: KotlinType?,
|
||||||
private val isInterfaceMethod: Boolean = Opcodes.INVOKEINTERFACE == invokeOpcode,
|
val isInterfaceMethod: Boolean,
|
||||||
private val isDefaultMethodInInterface: Boolean = false
|
private val isDefaultMethodInInterface: Boolean
|
||||||
) : Callable {
|
) : Callable {
|
||||||
private val defaultMethodDesc: String by lazy(LazyThreadSafetyMode.PUBLICATION, computeDefaultMethodDesc)
|
private val defaultMethodDesc: String by lazy(LazyThreadSafetyMode.PUBLICATION, computeDefaultMethodDesc)
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -412,9 +412,9 @@ class ExpressionCodegen(
|
|||||||
immaterialUnitValue
|
immaterialUnitValue
|
||||||
expression.type.isUnit() ->
|
expression.type.isUnit() ->
|
||||||
// NewInference allows casting `() -> T` to `() -> Unit`. A CHECKCAST here will fail.
|
// 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 ->
|
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
|
return classReference.onStack
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveToCallable(irCall: IrFunctionAccessExpression, isSuper: Boolean) =
|
private fun resolveToCallable(irCall: IrFunctionAccessExpression, isSuper: Boolean): IrCallableMethod =
|
||||||
typeMapper.mapToCallableMethod(irCall.symbol.owner, isSuper)
|
typeMapper.mapToCallableMethod(irCall.symbol.owner, isSuper)
|
||||||
|
|
||||||
private fun getOrCreateCallGenerator(element: IrFunctionAccessExpression, data: BlockInfo): IrCallGenerator {
|
private fun getOrCreateCallGenerator(element: IrFunctionAccessExpression, data: BlockInfo): IrCallGenerator {
|
||||||
|
|||||||
+4
-6
@@ -16,20 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.jvm.codegen
|
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.StackValue
|
||||||
import org.jetbrains.kotlin.codegen.ValueKind
|
import org.jetbrains.kotlin.codegen.ValueKind
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
|
||||||
interface IrCallGenerator {
|
interface IrCallGenerator {
|
||||||
|
fun genCall(callableMethod: IrCallableMethod, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression) {
|
||||||
fun genCall(callableMethod: Callable, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression) {
|
with(callableMethod) {
|
||||||
callableMethod.genInvokeInstruction(codegen.mv)
|
codegen.mv.visitMethodInsn(invokeOpcode, owner.internalName, asmMethod.name, asmMethod.descriptor, isInterfaceMethod)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun beforeValueParametersStart() {
|
fun beforeValueParametersStart() {
|
||||||
|
|||||||
+19
@@ -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<Type>,
|
||||||
|
val invokeOpcode: Int,
|
||||||
|
val asmMethod: Method,
|
||||||
|
val dispatchReceiverType: Type?,
|
||||||
|
val extensionReceiverType: Type?,
|
||||||
|
val isInterfaceMethod: Boolean
|
||||||
|
)
|
||||||
+1
-1
@@ -98,7 +98,7 @@ class IrInlineCodegen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun genCall(
|
override fun genCall(
|
||||||
callableMethod: Callable,
|
callableMethod: IrCallableMethod,
|
||||||
codegen: ExpressionCodegen,
|
codegen: ExpressionCodegen,
|
||||||
expression: IrFunctionAccessExpression
|
expression: IrFunctionAccessExpression
|
||||||
) {
|
) {
|
||||||
|
|||||||
+6
-3
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
|||||||
import org.jetbrains.kotlin.load.kotlin.computeExpandedTypeForInlineClass
|
import org.jetbrains.kotlin.load.kotlin.computeExpandedTypeForInlineClass
|
||||||
import org.jetbrains.kotlin.load.kotlin.mapBuiltInType
|
import org.jetbrains.kotlin.load.kotlin.mapBuiltInType
|
||||||
import org.jetbrains.kotlin.name.SpecialNames
|
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.AsmTypes
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
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 =
|
fun mapSignatureWithGeneric(f: IrFunction, kind: OwnerKind): JvmMethodGenericSignature =
|
||||||
kotlinTypeMapper.mapSignatureWithGeneric(f.descriptor, kind)
|
kotlinTypeMapper.mapSignatureWithGeneric(f.descriptor, kind)
|
||||||
|
|
||||||
fun mapToCallableMethod(f: IrFunction, superCall: Boolean, kind: OwnerKind? = null, resolvedCall: ResolvedCall<*>? = null) =
|
fun mapToCallableMethod(f: IrFunction, superCall: Boolean): IrCallableMethod =
|
||||||
kotlinTypeMapper.mapToCallableMethod(f.descriptor, superCall, kind, resolvedCall)
|
with(kotlinTypeMapper.mapToCallableMethod(f.descriptor, superCall)) {
|
||||||
|
IrCallableMethod(
|
||||||
|
owner, valueParameterTypes, invokeOpcode, getAsmMethod(), dispatchReceiverType, extensionReceiverType, isInterfaceMethod
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun writeFormalTypeParameters(irParameters: List<IrTypeParameter>, sw: JvmSignatureWriter) =
|
fun writeFormalTypeParameters(irParameters: List<IrTypeParameter>, sw: JvmSignatureWriter) =
|
||||||
kotlinTypeMapper.writeFormalTypeParameters(irParameters.map { it.descriptor }, sw)
|
kotlinTypeMapper.writeFormalTypeParameters(irParameters.map { it.descriptor }, sw)
|
||||||
|
|||||||
Reference in New Issue
Block a user