diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIr.proto b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIr.proto index 30e7c542c91..62cb2d934f7 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIr.proto +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIr.proto @@ -70,14 +70,9 @@ message Coordinates { required int32 end_offset = 2; } -message TypeMap { - message Pair { - required KotlinDescriptor descriptor = 1; - required KotlinType type = 2; - } - repeated Pair pair = 1; +message TypeArguments { + repeated KotlinType type_argument = 1; } - /* ------ IrExpressions --------------------------------------------- */ message IrBreak { @@ -91,10 +86,10 @@ message IrBlock { } message MemberAccessCommon { - required TypeMap type_map = 3; optional IrExpression dispatch_receiver = 5; optional IrExpression extension_receiver = 6; repeated NullableIrExpression value_argument = 8; + required TypeArguments type_arguments = 9; } message IrCall { @@ -112,7 +107,7 @@ message IrCall { message IrCallableReference { required KotlinDescriptor descriptor = 1; - required TypeMap type_map = 2; + required TypeArguments type_arguments = 2; } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/SerializeIr.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/SerializeIr.kt index a76f33b19d3..6bbf5e6ab8d 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/SerializeIr.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/SerializeIr.kt @@ -96,29 +96,13 @@ internal class IrSerializer(val context: Context, .build() } - private fun serializeTypeMap(typeArguments: Map): KonanIr.TypeMap { - val proto = KonanIr.TypeMap.newBuilder() - typeArguments.forEach { key, value -> - val pair = KonanIr.TypeMap.Pair.newBuilder() - .setDescriptor(serializeDescriptor(key)) - .setType(serializeKotlinType(value)) - .build() - proto.addPair(pair) + private fun serializeTypeArguments(call: IrMemberAccessExpression): KonanIr.TypeArguments { + val proto = KonanIr.TypeArguments.newBuilder() + for (i in 0 until call.typeArgumentsCount) { + proto.addTypeArgument(serializeKotlinType(call.getTypeArgument(i)!!)) } return proto.build() - } - - private fun serializeTypeArguments(call: IrMemberAccessExpression): KonanIr.TypeMap { - - val typeMap = mutableMapOf() - call.descriptor.original.typeParameters.forEach { - val type = call.getTypeArgument(it) - if (type != null) typeMap[it] = type - } - return serializeTypeMap(typeMap) - - } - + } /* -------------------------------------------------------------------------- */ @@ -194,7 +178,7 @@ internal class IrSerializer(val context: Context, if (call.dispatchReceiver != null) { proto.dispatchReceiver = serializeExpression(call.dispatchReceiver!!) } - proto.typeMap = serializeTypeArguments(call) + proto.typeArguments = serializeTypeArguments(call) call.descriptor.valueParameters.forEach { val actual = call.getValueArgument(it.index) @@ -229,7 +213,8 @@ internal class IrSerializer(val context: Context, private fun serializeCallableReference(callable: IrCallableReference): KonanIr.IrCallableReference { val proto = KonanIr.IrCallableReference.newBuilder() .setDescriptor(serializeDescriptor(callable.descriptor)) - .setTypeMap(serializeTypeArguments(callable)) + .setTypeArguments(serializeTypeArguments(callable)) + return proto.build() } @@ -734,17 +719,15 @@ internal class IrDeserializer(val context: Context, private fun deserializeDescriptor(proto: KonanIr.KotlinDescriptor) = descriptorDeserializer.deserializeDescriptor(proto) - private fun deserializeTypeMap(descriptor: CallableDescriptor, proto: KonanIr.TypeMap): - Map { - val typeMap = mutableMapOf() - val pairProtos = proto.pairList - pairProtos.forEachIndexed { index, pair -> - val typeParameter = descriptor.original.typeParameters[index] - - typeMap[typeParameter] = deserializeKotlinType(pair.type) + private fun deserializeTypeArguments(proto: KonanIr.TypeArguments): List { + context.log{"### deserializeTypeArguments"} + val result = mutableListOf() + proto.typeArgumentList.forEachIndexed { index, type -> + val kotlinType = deserializeKotlinType(type) + result.add(kotlinType) + context.log{"$kotlinType"} } - context.log{"### deserialized typeMap = $typeMap"} - return typeMap + return result } private fun deserializeBlockBody(proto: KonanIr.IrBlockBody, @@ -820,6 +803,10 @@ internal class IrDeserializer(val context: Context, access.putValueArgument(i, exprOrNull) } + deserializeTypeArguments(proto.typeArguments).forEachIndexed { index, type -> + access.putTypeArgument(index, type) + } + if (proto.hasDispatchReceiver()) { access.dispatchReceiver = deserializeExpression(proto.dispatchReceiver) } @@ -842,11 +829,12 @@ internal class IrDeserializer(val context: Context, deserializeDescriptor(proto.`super`) as ClassDescriptor } else null - val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.getTypeMap()) + val typeArgs = deserializeTypeArguments(proto.memberAccess.typeArguments) + val call: IrCall = when (proto.kind) { KonanIr.IrCall.Primitive.NOT_PRIMITIVE -> // TODO: implement the last three args here. - IrCallImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, typeArgs , null, createClassSymbolOrNull(superDescriptor)) + IrCallImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, proto.memberAccess.typeArguments.typeArgumentCount, null, createClassSymbolOrNull(superDescriptor)) KonanIr.IrCall.Primitive.NULLARY -> IrNullaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor)) KonanIr.IrCall.Primitive.UNARY -> @@ -863,11 +851,15 @@ internal class IrDeserializer(val context: Context, start: Int, end: Int, type: KotlinType): IrCallableReference { val descriptor = deserializeDescriptor(proto.descriptor) as CallableDescriptor - val typeMap = deserializeTypeMap(descriptor, proto.typeMap) - return when (descriptor) { - is FunctionDescriptor -> IrFunctionReferenceImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, typeMap, null) + val callable = when (descriptor) { + is FunctionDescriptor -> IrFunctionReferenceImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, proto.typeArguments.typeArgumentCount, null) else -> TODO() } + + deserializeTypeArguments(proto.typeArguments).forEachIndexed { index, type -> + callable.putTypeArgument(index, type) + } + return callable } private fun deserializeComposite(proto: KonanIr.IrComposite, start: Int, end: Int, type: KotlinType): IrComposite { @@ -881,9 +873,7 @@ internal class IrDeserializer(val context: Context, private fun deserializeDelegatingConstructorCall(proto: KonanIr.IrDelegatingConstructorCall, start: Int, end: Int): IrDelegatingConstructorCall { val descriptor = deserializeDescriptor(proto.descriptor) as ClassConstructorDescriptor - val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.typeMap) - - val call = IrDelegatingConstructorCallImpl(start, end, IrConstructorSymbolImpl(descriptor.original), descriptor, typeArgs) + val call = IrDelegatingConstructorCallImpl(start, end, IrConstructorSymbolImpl(descriptor.original), descriptor, proto.memberAccess.typeArguments.typeArgumentCount) deserializeMemberAccessCommon(call, proto.memberAccess) return call diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index f910f011398..63eea389f85 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -2343,6 +2343,11 @@ task serialized_default_args(type: LinkKonanTest) { goldValue = "SomeDataClass(first=17, second=666, third=23)\n" } +task serialized_no_typemap(type: RunStandaloneKonanTest) { + source = "serialization/regression/no_type_map.kt" + goldValue = "OK\n" +} + task testing_annotations(type: RunStandaloneKonanTest) { source = "testing/annotations.kt" flags = ['-tr'] diff --git a/backend.native/tests/serialization/regression/no_type_map.kt b/backend.native/tests/serialization/regression/no_type_map.kt new file mode 100644 index 00000000000..09e8526fdf4 --- /dev/null +++ b/backend.native/tests/serialization/regression/no_type_map.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* +fun main(args: Array) { + memScoped { + val bufferLength = 100L + val buffer = allocArray(bufferLength) + } + println("OK") +}