JVM IR: minimize usages of some methods in MethodSignatureMapper
Also do not pass useless parameters such as OwnerKind which is always IMPLEMENTATION in the IR backend
This commit is contained in:
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.common.lower.loops.forLoopsPhase
|
||||
import org.jetbrains.kotlin.backend.common.phaser.*
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.*
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
@@ -75,7 +74,7 @@ private val propertiesPhase = makeIrFilePhase<JvmBackendContext>(
|
||||
val baseName =
|
||||
if (context.state.languageVersionSettings.supportsFeature(LanguageFeature.UseGetterNameForPropertyAnnotationsMethodOnJvm)) {
|
||||
property.getter?.let { getter ->
|
||||
context.methodSignatureMapper.mapFunctionName(getter, OwnerKind.IMPLEMENTATION)
|
||||
context.methodSignatureMapper.mapFunctionName(getter)
|
||||
} ?: JvmAbi.getterName(property.name.asString())
|
||||
} else {
|
||||
property.name.asString()
|
||||
|
||||
+4
-5
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.unboxInlineClass
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.*
|
||||
import org.jetbrains.kotlin.codegen.BaseExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.CallGenerator
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.codegen.coroutines.INVOKE_SUSPEND_METHOD_NAME
|
||||
import org.jetbrains.kotlin.codegen.extractReificationArgument
|
||||
@@ -98,6 +97,7 @@ class VariableInfo(val declaration: IrVariable, val index: Int, val type: Type,
|
||||
|
||||
class ExpressionCodegen(
|
||||
val irFunction: IrFunction,
|
||||
val signature: JvmMethodSignature,
|
||||
override val frameMap: IrFrameMap,
|
||||
val mv: InstructionAdapter,
|
||||
val classCodegen: ClassCodegen,
|
||||
@@ -179,7 +179,7 @@ class ExpressionCodegen(
|
||||
if (irFunction.origin != JvmLoweredDeclarationOrigin.CLASS_STATIC_INITIALIZER) {
|
||||
irFunction.markLineNumber(startOffset = irFunction is IrConstructor && irFunction.isPrimary)
|
||||
}
|
||||
val returnType = methodSignatureMapper.mapReturnType(irFunction)
|
||||
val returnType = signature.returnType
|
||||
val returnIrType = if (irFunction !is IrConstructor) irFunction.returnType else context.irBuiltIns.unitType
|
||||
result.coerce(returnType, returnIrType).materialize()
|
||||
mv.areturn(returnType)
|
||||
@@ -537,8 +537,7 @@ class ExpressionCodegen(
|
||||
?: error("Unsupported IrReturnTarget: $returnTarget")
|
||||
//TODO: should be owner != irFunction
|
||||
val isNonLocalReturn =
|
||||
methodSignatureMapper.mapFunctionName(owner, OwnerKind.IMPLEMENTATION) !=
|
||||
methodSignatureMapper.mapFunctionName(irFunction, OwnerKind.IMPLEMENTATION)
|
||||
methodSignatureMapper.mapFunctionName(owner) != methodSignatureMapper.mapFunctionName(irFunction)
|
||||
if (isNonLocalReturn && state.isInlineDisabled) {
|
||||
//TODO: state.diagnostics.report(Errors.NON_LOCAL_RETURN_IN_DISABLED_INLINE.on(expression))
|
||||
genThrow(
|
||||
@@ -548,7 +547,7 @@ class ExpressionCodegen(
|
||||
return immaterialUnitValue
|
||||
}
|
||||
|
||||
val returnType = methodSignatureMapper.mapReturnType(owner)
|
||||
val returnType = if (owner == irFunction) signature.returnType else methodSignatureMapper.mapReturnType(owner)
|
||||
val afterReturnLabel = Label()
|
||||
expression.value.accept(this, data).coerce(returnType, owner.returnType).materialize()
|
||||
generateFinallyBlocksIfNeeded(returnType, afterReturnLabel, data)
|
||||
|
||||
+2
-3
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.ClassBuilderMode
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
import org.jetbrains.kotlin.codegen.visitAnnotableParameterCount
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -44,7 +43,7 @@ open class FunctionCodegen(
|
||||
}
|
||||
|
||||
private fun doGenerate(): JvmMethodGenericSignature {
|
||||
val signature = classCodegen.methodSignatureMapper.mapSignatureWithGeneric(irFunction, OwnerKind.IMPLEMENTATION)
|
||||
val signature = classCodegen.methodSignatureMapper.mapSignatureWithGeneric(irFunction)
|
||||
|
||||
val flags = calculateMethodFlags(irFunction.isStatic)
|
||||
var methodVisitor = createMethod(flags, signature)
|
||||
@@ -90,7 +89,7 @@ open class FunctionCodegen(
|
||||
)
|
||||
else -> methodVisitor
|
||||
}
|
||||
ExpressionCodegen(irFunction, frameMap, InstructionAdapter(methodVisitor), classCodegen, isInlineLambda).generate()
|
||||
ExpressionCodegen(irFunction, signature, frameMap, InstructionAdapter(methodVisitor), classCodegen, isInlineLambda).generate()
|
||||
methodVisitor.visitMaxs(-1, -1)
|
||||
continuationClassBuilder?.done()
|
||||
}
|
||||
|
||||
+4
-4
@@ -57,11 +57,10 @@ class IrSourceCompilerForInline(
|
||||
override val inlineCallSiteInfo: InlineCallSiteInfo
|
||||
get() {
|
||||
//TODO: support nested inline calls
|
||||
val signature = codegen.methodSignatureMapper.mapSignatureSkipGeneric(codegen.irFunction)
|
||||
return InlineCallSiteInfo(
|
||||
codegen.classCodegen.type.internalName,
|
||||
signature.asmMethod.name,
|
||||
signature.asmMethod.descriptor,
|
||||
codegen.signature.asmMethod.name,
|
||||
codegen.signature.asmMethod.descriptor,
|
||||
//compilationContextFunctionDescriptor.isInlineOrInsideInline()
|
||||
false,
|
||||
compilationContextFunctionDescriptor.isSuspend
|
||||
@@ -132,7 +131,8 @@ class IrSourceCompilerForInline(
|
||||
|
||||
override fun createCodegenForExternalFinallyBlockGenerationOnNonLocalReturn(finallyNode: MethodNode, curFinallyDepth: Int) =
|
||||
ExpressionCodegen(
|
||||
codegen.irFunction, codegen.frameMap, InstructionAdapter(finallyNode), codegen.classCodegen, codegen.isInlineLambda
|
||||
codegen.irFunction, codegen.signature, codegen.frameMap, InstructionAdapter(finallyNode), codegen.classCodegen,
|
||||
codegen.isInlineLambda
|
||||
).also {
|
||||
it.finallyDepth = curFinallyDepth
|
||||
}
|
||||
|
||||
+6
-6
@@ -35,8 +35,8 @@ class MethodSignatureMapper(context: JvmBackendContext) {
|
||||
fun mapFieldSignature(irField: IrField): String? =
|
||||
kotlinTypeMapper.mapFieldSignature(irField.type.toKotlinType(), irField.descriptor)
|
||||
|
||||
fun mapFunctionName(irFunction: IrFunction, ownerKind: OwnerKind?): String =
|
||||
kotlinTypeMapper.mapFunctionName(irFunction.descriptor, ownerKind)
|
||||
fun mapFunctionName(irFunction: IrFunction): String =
|
||||
kotlinTypeMapper.mapFunctionName(irFunction.descriptor, OwnerKind.IMPLEMENTATION)
|
||||
|
||||
fun mapAnnotationParameterName(field: IrField): String =
|
||||
kotlinTypeMapper.mapAnnotationParameterName(field.descriptor)
|
||||
@@ -47,11 +47,11 @@ class MethodSignatureMapper(context: JvmBackendContext) {
|
||||
fun mapReturnType(irFunction: IrFunction): Type =
|
||||
kotlinTypeMapper.mapReturnType(irFunction.descriptor)
|
||||
|
||||
fun mapSignatureSkipGeneric(f: IrFunction, kind: OwnerKind = OwnerKind.IMPLEMENTATION): JvmMethodSignature =
|
||||
kotlinTypeMapper.mapSignatureSkipGeneric(f.descriptor, kind)
|
||||
fun mapSignatureSkipGeneric(f: IrFunction): JvmMethodSignature =
|
||||
kotlinTypeMapper.mapSignatureSkipGeneric(f.descriptor, OwnerKind.IMPLEMENTATION)
|
||||
|
||||
fun mapSignatureWithGeneric(f: IrFunction, kind: OwnerKind): JvmMethodGenericSignature =
|
||||
kotlinTypeMapper.mapSignatureWithGeneric(f.descriptor, kind)
|
||||
fun mapSignatureWithGeneric(f: IrFunction): JvmMethodGenericSignature =
|
||||
kotlinTypeMapper.mapSignatureWithGeneric(f.descriptor, OwnerKind.IMPLEMENTATION)
|
||||
|
||||
fun mapToCallableMethod(expression: IrFunctionAccessExpression): IrCallableMethod {
|
||||
val callee = expression.symbol.owner
|
||||
|
||||
+1
-2
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.backend.common.ir.*
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.MethodSignatureMapper
|
||||
import org.jetbrains.kotlin.builtins.CompanionObjectMapping.isMappedIntrinsicCompanionObject
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
@@ -135,7 +134,7 @@ class JvmDeclarationFactory(
|
||||
return defaultImplsMethods.getOrPut(interfaceFun) {
|
||||
val defaultImpls = getDefaultImplsClass(interfaceFun.parentAsClass)
|
||||
|
||||
val name = Name.identifier(methodSignatureMapper.mapFunctionName(interfaceFun, OwnerKind.IMPLEMENTATION))
|
||||
val name = Name.identifier(methodSignatureMapper.mapFunctionName(interfaceFun))
|
||||
createStaticFunctionWithReceivers(
|
||||
defaultImpls, name, interfaceFun,
|
||||
dispatchReceiverType = parent.defaultType,
|
||||
|
||||
+5
-10
@@ -19,10 +19,9 @@ package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.JAVA_STRING_TYPE
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
@@ -31,19 +30,15 @@ object IrEnumValueOf : IntrinsicMethod() {
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
): IrIntrinsicFunction {
|
||||
val enumType = context.typeMapper.mapType(expression.type)
|
||||
val newSignature = context.methodSignatureMapper.mapSignatureSkipGeneric(expression.symbol.owner, OwnerKind.IMPLEMENTATION)
|
||||
val stringType = AsmTypes.JAVA_STRING_TYPE
|
||||
|
||||
return object : IrIntrinsicFunction(expression, newSignature, context, listOf(stringType)) {
|
||||
): IrIntrinsicFunction =
|
||||
object : IrIntrinsicFunction(expression, signature, context, listOf(JAVA_STRING_TYPE)) {
|
||||
override fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo): StackValue {
|
||||
val enumType = context.typeMapper.mapType(expression.type)
|
||||
v.tconst(enumType)
|
||||
codegen.gen(expression.getValueArgument(0)!!, stringType, codegen.context.irBuiltIns.stringType, data)
|
||||
codegen.gen(expression.getValueArgument(0)!!, JAVA_STRING_TYPE, context.irBuiltIns.stringType, data)
|
||||
v.invokestatic("java/lang/Enum", "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;", false)
|
||||
v.checkcast(enumType)
|
||||
return StackValue.onStack(enumType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrTypeOperator
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
@@ -64,7 +63,7 @@ private class CompanionObjectJvmStaticLowering(val context: JvmBackendContext) :
|
||||
|
||||
companion?.declarations?.filter(::isJvmStaticFunction)?.forEach {
|
||||
val jvmStaticFunction = it as IrSimpleFunction
|
||||
val newName = Name.identifier(context.methodSignatureMapper.mapFunctionName(jvmStaticFunction, null))
|
||||
val newName = Name.identifier(context.methodSignatureMapper.mapFunctionName(jvmStaticFunction))
|
||||
if (!jvmStaticFunction.visibility.isPublicAPI) {
|
||||
// TODO: Synthetic accessor creation logic should be supported in SyntheticAccessorLowering in the future.
|
||||
val accessorName = Name.identifier("access\$$newName")
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.receiverAndArgs
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
@@ -416,7 +415,7 @@ private class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElem
|
||||
private var nameCounter = 0
|
||||
|
||||
private fun IrFunction.accessorName(): Name {
|
||||
val jvmName = context.methodSignatureMapper.mapFunctionName(this, OwnerKind.IMPLEMENTATION)
|
||||
val jvmName = context.methodSignatureMapper.mapFunctionName(this)
|
||||
return Name.identifier("access\$$jvmName\$${nameCounter++}")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user