Moved from typeMaps to typeArgument list in IrMemberAccessCommon serialization
to reflect changes in IR.
This commit is contained in:
committed by
alexander-gorshenev
parent
6415734881
commit
0a911ed5bb
+4
-9
@@ -70,14 +70,9 @@ message Coordinates {
|
|||||||
required int32 end_offset = 2;
|
required int32 end_offset = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TypeMap {
|
message TypeArguments {
|
||||||
message Pair {
|
repeated KotlinType type_argument = 1;
|
||||||
required KotlinDescriptor descriptor = 1;
|
|
||||||
required KotlinType type = 2;
|
|
||||||
}
|
|
||||||
repeated Pair pair = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------ IrExpressions --------------------------------------------- */
|
/* ------ IrExpressions --------------------------------------------- */
|
||||||
|
|
||||||
message IrBreak {
|
message IrBreak {
|
||||||
@@ -91,10 +86,10 @@ message IrBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message MemberAccessCommon {
|
message MemberAccessCommon {
|
||||||
required TypeMap type_map = 3;
|
|
||||||
optional IrExpression dispatch_receiver = 5;
|
optional IrExpression dispatch_receiver = 5;
|
||||||
optional IrExpression extension_receiver = 6;
|
optional IrExpression extension_receiver = 6;
|
||||||
repeated NullableIrExpression value_argument = 8;
|
repeated NullableIrExpression value_argument = 8;
|
||||||
|
required TypeArguments type_arguments = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrCall {
|
message IrCall {
|
||||||
@@ -112,7 +107,7 @@ message IrCall {
|
|||||||
|
|
||||||
message IrCallableReference {
|
message IrCallableReference {
|
||||||
required KotlinDescriptor descriptor = 1;
|
required KotlinDescriptor descriptor = 1;
|
||||||
required TypeMap type_map = 2;
|
required TypeArguments type_arguments = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+31
-41
@@ -96,29 +96,13 @@ internal class IrSerializer(val context: Context,
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun serializeTypeMap(typeArguments: Map<TypeParameterDescriptor, KotlinType>): KonanIr.TypeMap {
|
private fun serializeTypeArguments(call: IrMemberAccessExpression): KonanIr.TypeArguments {
|
||||||
val proto = KonanIr.TypeMap.newBuilder()
|
val proto = KonanIr.TypeArguments.newBuilder()
|
||||||
typeArguments.forEach { key, value ->
|
for (i in 0 until call.typeArgumentsCount) {
|
||||||
val pair = KonanIr.TypeMap.Pair.newBuilder()
|
proto.addTypeArgument(serializeKotlinType(call.getTypeArgument(i)!!))
|
||||||
.setDescriptor(serializeDescriptor(key))
|
|
||||||
.setType(serializeKotlinType(value))
|
|
||||||
.build()
|
|
||||||
proto.addPair(pair)
|
|
||||||
}
|
}
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun serializeTypeArguments(call: IrMemberAccessExpression): KonanIr.TypeMap {
|
|
||||||
|
|
||||||
val typeMap = mutableMapOf<TypeParameterDescriptor, KotlinType>()
|
|
||||||
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) {
|
if (call.dispatchReceiver != null) {
|
||||||
proto.dispatchReceiver = serializeExpression(call.dispatchReceiver!!)
|
proto.dispatchReceiver = serializeExpression(call.dispatchReceiver!!)
|
||||||
}
|
}
|
||||||
proto.typeMap = serializeTypeArguments(call)
|
proto.typeArguments = serializeTypeArguments(call)
|
||||||
|
|
||||||
call.descriptor.valueParameters.forEach {
|
call.descriptor.valueParameters.forEach {
|
||||||
val actual = call.getValueArgument(it.index)
|
val actual = call.getValueArgument(it.index)
|
||||||
@@ -229,7 +213,8 @@ internal class IrSerializer(val context: Context,
|
|||||||
private fun serializeCallableReference(callable: IrCallableReference): KonanIr.IrCallableReference {
|
private fun serializeCallableReference(callable: IrCallableReference): KonanIr.IrCallableReference {
|
||||||
val proto = KonanIr.IrCallableReference.newBuilder()
|
val proto = KonanIr.IrCallableReference.newBuilder()
|
||||||
.setDescriptor(serializeDescriptor(callable.descriptor))
|
.setDescriptor(serializeDescriptor(callable.descriptor))
|
||||||
.setTypeMap(serializeTypeArguments(callable))
|
.setTypeArguments(serializeTypeArguments(callable))
|
||||||
|
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,17 +719,15 @@ internal class IrDeserializer(val context: Context,
|
|||||||
private fun deserializeDescriptor(proto: KonanIr.KotlinDescriptor)
|
private fun deserializeDescriptor(proto: KonanIr.KotlinDescriptor)
|
||||||
= descriptorDeserializer.deserializeDescriptor(proto)
|
= descriptorDeserializer.deserializeDescriptor(proto)
|
||||||
|
|
||||||
private fun deserializeTypeMap(descriptor: CallableDescriptor, proto: KonanIr.TypeMap):
|
private fun deserializeTypeArguments(proto: KonanIr.TypeArguments): List<KotlinType> {
|
||||||
Map<TypeParameterDescriptor, KotlinType> {
|
context.log{"### deserializeTypeArguments"}
|
||||||
val typeMap = mutableMapOf<TypeParameterDescriptor, KotlinType>()
|
val result = mutableListOf<KotlinType>()
|
||||||
val pairProtos = proto.pairList
|
proto.typeArgumentList.forEachIndexed { index, type ->
|
||||||
pairProtos.forEachIndexed { index, pair ->
|
val kotlinType = deserializeKotlinType(type)
|
||||||
val typeParameter = descriptor.original.typeParameters[index]
|
result.add(kotlinType)
|
||||||
|
context.log{"$kotlinType"}
|
||||||
typeMap[typeParameter] = deserializeKotlinType(pair.type)
|
|
||||||
}
|
}
|
||||||
context.log{"### deserialized typeMap = $typeMap"}
|
return result
|
||||||
return typeMap
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeBlockBody(proto: KonanIr.IrBlockBody,
|
private fun deserializeBlockBody(proto: KonanIr.IrBlockBody,
|
||||||
@@ -820,6 +803,10 @@ internal class IrDeserializer(val context: Context,
|
|||||||
access.putValueArgument(i, exprOrNull)
|
access.putValueArgument(i, exprOrNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deserializeTypeArguments(proto.typeArguments).forEachIndexed { index, type ->
|
||||||
|
access.putTypeArgument(index, type)
|
||||||
|
}
|
||||||
|
|
||||||
if (proto.hasDispatchReceiver()) {
|
if (proto.hasDispatchReceiver()) {
|
||||||
access.dispatchReceiver = deserializeExpression(proto.dispatchReceiver)
|
access.dispatchReceiver = deserializeExpression(proto.dispatchReceiver)
|
||||||
}
|
}
|
||||||
@@ -842,11 +829,12 @@ internal class IrDeserializer(val context: Context,
|
|||||||
deserializeDescriptor(proto.`super`) as ClassDescriptor
|
deserializeDescriptor(proto.`super`) as ClassDescriptor
|
||||||
} else null
|
} else null
|
||||||
|
|
||||||
val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.getTypeMap())
|
val typeArgs = deserializeTypeArguments(proto.memberAccess.typeArguments)
|
||||||
|
|
||||||
val call: IrCall = when (proto.kind) {
|
val call: IrCall = when (proto.kind) {
|
||||||
KonanIr.IrCall.Primitive.NOT_PRIMITIVE ->
|
KonanIr.IrCall.Primitive.NOT_PRIMITIVE ->
|
||||||
// TODO: implement the last three args here.
|
// 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 ->
|
KonanIr.IrCall.Primitive.NULLARY ->
|
||||||
IrNullaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor))
|
IrNullaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor))
|
||||||
KonanIr.IrCall.Primitive.UNARY ->
|
KonanIr.IrCall.Primitive.UNARY ->
|
||||||
@@ -863,11 +851,15 @@ internal class IrDeserializer(val context: Context,
|
|||||||
start: Int, end: Int, type: KotlinType): IrCallableReference {
|
start: Int, end: Int, type: KotlinType): IrCallableReference {
|
||||||
|
|
||||||
val descriptor = deserializeDescriptor(proto.descriptor) as CallableDescriptor
|
val descriptor = deserializeDescriptor(proto.descriptor) as CallableDescriptor
|
||||||
val typeMap = deserializeTypeMap(descriptor, proto.typeMap)
|
val callable = when (descriptor) {
|
||||||
return when (descriptor) {
|
is FunctionDescriptor -> IrFunctionReferenceImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, proto.typeArguments.typeArgumentCount, null)
|
||||||
is FunctionDescriptor -> IrFunctionReferenceImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, typeMap, null)
|
|
||||||
else -> TODO()
|
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 {
|
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 {
|
private fun deserializeDelegatingConstructorCall(proto: KonanIr.IrDelegatingConstructorCall, start: Int, end: Int): IrDelegatingConstructorCall {
|
||||||
val descriptor = deserializeDescriptor(proto.descriptor) as ClassConstructorDescriptor
|
val descriptor = deserializeDescriptor(proto.descriptor) as ClassConstructorDescriptor
|
||||||
val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.typeMap)
|
val call = IrDelegatingConstructorCallImpl(start, end, IrConstructorSymbolImpl(descriptor.original), descriptor, proto.memberAccess.typeArguments.typeArgumentCount)
|
||||||
|
|
||||||
val call = IrDelegatingConstructorCallImpl(start, end, IrConstructorSymbolImpl(descriptor.original), descriptor, typeArgs)
|
|
||||||
|
|
||||||
deserializeMemberAccessCommon(call, proto.memberAccess)
|
deserializeMemberAccessCommon(call, proto.memberAccess)
|
||||||
return call
|
return call
|
||||||
|
|||||||
@@ -2343,6 +2343,11 @@ task serialized_default_args(type: LinkKonanTest) {
|
|||||||
goldValue = "SomeDataClass(first=17, second=666, third=23)\n"
|
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) {
|
task testing_annotations(type: RunStandaloneKonanTest) {
|
||||||
source = "testing/annotations.kt"
|
source = "testing/annotations.kt"
|
||||||
flags = ['-tr']
|
flags = ['-tr']
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import kotlinx.cinterop.*
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
memScoped {
|
||||||
|
val bufferLength = 100L
|
||||||
|
val buffer = allocArray<ByteVar>(bufferLength)
|
||||||
|
}
|
||||||
|
println("OK")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user