JVM IR: do not use JvmMethodParameterKind

This commit is contained in:
Alexander Udalov
2022-02-04 15:48:16 +01:00
committed by Space Team
parent d9bc714992
commit 8ad38db2ad
5 changed files with 19 additions and 16 deletions
@@ -272,7 +272,7 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
) {
val iterator = irFunction.valueParameters.iterator()
val kotlinParameterTypes = jvmSignature.valueParameters
val syntheticParameterCount = kotlinParameterTypes.count { it.kind.isSkippedInGenericSignature }
val syntheticParameterCount = irFunction.valueParameters.count { it.isSkippedInGenericSignature }
visitAnnotableParameterCount(mv, kotlinParameterTypes.size - syntheticParameterCount)
@@ -283,7 +283,7 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
else
iterator.next()
if (!parameterSignature.kind.isSkippedInGenericSignature && !annotated.isSyntheticMarkerParameter()) {
if (i >= syntheticParameterCount && !annotated.isSyntheticMarkerParameter()) {
object : AnnotationCodegen(classCodegen, skipNullabilityAnnotations) {
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
return mv.visitParameterAnnotation(
@@ -551,3 +551,7 @@ fun IrClass.findEnumValuesFunction(context: JvmBackendContext): IrSimpleFunction
&& it.returnType.isBoxedArray
&& it.returnType.getArrayElementType(context.irBuiltIns).classOrNull == this.symbol
}
val IrValueParameter.isSkippedInGenericSignature: Boolean
get() = origin == JvmLoweredDeclarationOrigin.FIELD_FOR_OUTER_THIS ||
origin == JvmLoweredDeclarationOrigin.ENUM_CONSTRUCTOR_SYNTHETIC_PARAMETER
@@ -254,26 +254,21 @@ class MethodSignatureMapper(private val context: JvmBackendContext, private val
for (i in 0 until function.contextReceiverParametersCount) {
val contextReceiver = function.valueParameters[i]
writeParameter(sw, JvmMethodParameterKind.VALUE, contextReceiver.type, function)
writeParameter(sw, false, contextReceiver.type, function)
}
val receiverParameter = function.extensionReceiverParameter
if (receiverParameter != null) {
writeParameter(sw, JvmMethodParameterKind.VALUE, receiverParameter.type, function)
writeParameter(sw, false, receiverParameter.type, function)
}
for (i in function.contextReceiverParametersCount until function.valueParameters.size) {
val parameter = function.valueParameters[i]
val kind = when (parameter.origin) {
JvmLoweredDeclarationOrigin.FIELD_FOR_OUTER_THIS -> JvmMethodParameterKind.OUTER
JvmLoweredDeclarationOrigin.ENUM_CONSTRUCTOR_SYNTHETIC_PARAMETER -> JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL
else -> JvmMethodParameterKind.VALUE
}
val type =
if (shouldBoxSingleValueParameterForSpecialCaseOfRemove(function))
parameter.type.makeNullable()
else parameter.type
writeParameter(sw, kind, type, function, materialized)
writeParameter(sw, parameter.isSkippedInGenericSignature, type, function, materialized)
}
sw.writeReturnType()
@@ -337,12 +332,12 @@ class MethodSignatureMapper(private val context: JvmBackendContext, private val
private fun writeParameter(
sw: JvmSignatureWriter,
kind: JvmMethodParameterKind,
isSkippedInGenericSignature: Boolean,
type: IrType,
function: IrFunction,
materialized: Boolean = true
) {
sw.writeParameterType(kind)
sw.writeParameterType(JvmMethodParameterKind.VALUE, isSkippedInGenericSignature)
writeParameterType(sw, type, function, materialized)
sw.writeParameterTypeEnd()
}