Skip to content

Commit a53708f

Browse files
committed
Updated descriptor to use RpcType instead of KType directly
1 parent a653cc1 commit a53708f

File tree

8 files changed

+64
-17
lines changed

8 files changed

+64
-17
lines changed

compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ internal class RpcIrContext(
105105
getRpcIrClassSymbol("RpcServiceDescriptor", "descriptor")
106106
}
107107

108+
val rpcType by lazy {
109+
getRpcIrClassSymbol("RpcType", "descriptor")
110+
}
111+
108112
val rpcCallable by lazy {
109113
getRpcIrClassSymbol("RpcCallable", "descriptor")
110114
}

compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,11 @@ internal class RpcStubGenerator(
976976
* Where:
977977
* - `<field-name>` - the name of the field
978978
*/
979+
@Suppress(
980+
"detekt.NestedBlockDepth",
981+
"detekt.LongMethod",
982+
"detekt.CyclomaticComplexMethod",
983+
)
979984
private fun IrClass.generateInvokator(i: Int, callable: ServiceDeclaration.Callable) {
980985
invokators[callable.name] = addProperty {
981986
name = Name.identifier("${callable.name}Invokator")
@@ -1205,13 +1210,13 @@ internal class RpcStubGenerator(
12051210
* ```kotlin
12061211
* RpcCallable<MyService>(
12071212
* name = "<callable-name>",
1208-
* dataType = typeOf<<callable-data-type>>(),
1209-
* returnType = typeOf<<callable-return-type>>(),
1213+
* dataType = RpcCall(typeOf<<callable-data-type>>()),
1214+
* returnType = RpcCall(typeOf<<callable-return-type>>()),
12101215
* invokator = <callable-invokator>,
12111216
* parameters = arrayOf( // or emptyArray()
12121217
* RpcParameter(
12131218
* "<method-parameter-name-1>",
1214-
* typeOf<<method-parameter-type-1>>(),
1219+
* RpcCall(typeOf<<method-parameter-type-1>>())
12151220
* ),
12161221
* ...
12171222
* ),
@@ -1247,14 +1252,14 @@ internal class RpcStubGenerator(
12471252
is ServiceDeclaration.FlowField -> ctx.fieldDataObject.defaultType
12481253
}
12491254

1250-
putValueArgument(1, irTypeOfCall(dataType))
1255+
putValueArgument(1, irRpcTypeCall(dataType))
12511256

12521257
val returnType = when (callable) {
12531258
is ServiceDeclaration.Method -> callable.function.returnType
12541259
is ServiceDeclaration.FlowField -> callable.property.getterOrFail.returnType
12551260
}
12561261

1257-
putValueArgument(2, irTypeOfCall(returnType))
1262+
putValueArgument(2, irRpcTypeCall(returnType))
12581263

12591264
val invokator = invokators[callable.name]
12601265
?: error("Expected invokator for ${callable.name} in ${declaration.service.name}")
@@ -1309,7 +1314,7 @@ internal class RpcStubGenerator(
13091314
)
13101315
}.apply {
13111316
putValueArgument(0, stringConst(parameter.value.name.asString()))
1312-
putValueArgument(1, irTypeOfCall(parameter.type))
1317+
putValueArgument(1, irRpcTypeCall(parameter.type))
13131318
}
13141319
},
13151320
)
@@ -1521,6 +1526,25 @@ internal class RpcStubGenerator(
15211526
}
15221527
}
15231528

1529+
/**
1530+
* IR call of the `RpcType(KType, Array<Annotation>)` function
1531+
*/
1532+
private fun irRpcTypeCall(type: IrType): IrConstructorCallImpl {
1533+
return vsApi {
1534+
IrConstructorCallImplVS(
1535+
startOffset = UNDEFINED_OFFSET,
1536+
endOffset = UNDEFINED_OFFSET,
1537+
type = ctx.rpcType.defaultType,
1538+
symbol = ctx.rpcType.constructors.single(),
1539+
typeArgumentsCount = 0,
1540+
valueArgumentsCount = 1,
1541+
constructorTypeArgumentsCount = 0,
1542+
)
1543+
}.apply {
1544+
putValueArgument(0, irTypeOfCall(type))
1545+
}
1546+
}
1547+
15241548
/**
15251549
* IR call of the `typeOf<...>()` function
15261550
*/

core/api/core.api

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public abstract interface annotation class kotlinx/rpc/annotations/Rpc : java/la
5656
}
5757

5858
public final class kotlinx/rpc/descriptor/RpcCallable {
59-
public fun <init> (Ljava/lang/String;Lkotlin/reflect/KType;Lkotlin/reflect/KType;Lkotlinx/rpc/descriptor/RpcInvokator;[Lkotlinx/rpc/descriptor/RpcParameter;)V
60-
public final fun getDataType ()Lkotlin/reflect/KType;
59+
public fun <init> (Ljava/lang/String;Lkotlinx/rpc/descriptor/RpcType;Lkotlinx/rpc/descriptor/RpcType;Lkotlinx/rpc/descriptor/RpcInvokator;[Lkotlinx/rpc/descriptor/RpcParameter;)V
60+
public final fun getDataType ()Lkotlinx/rpc/descriptor/RpcType;
6161
public final fun getInvokator ()Lkotlinx/rpc/descriptor/RpcInvokator;
6262
public final fun getName ()Ljava/lang/String;
6363
public final fun getParameters ()[Lkotlinx/rpc/descriptor/RpcParameter;
64-
public final fun getReturnType ()Lkotlin/reflect/KType;
64+
public final fun getReturnType ()Lkotlinx/rpc/descriptor/RpcType;
6565
}
6666

6767
public abstract interface class kotlinx/rpc/descriptor/RpcInvokator {
@@ -76,9 +76,9 @@ public abstract interface class kotlinx/rpc/descriptor/RpcInvokator$Method : kot
7676
}
7777

7878
public final class kotlinx/rpc/descriptor/RpcParameter {
79-
public fun <init> (Ljava/lang/String;Lkotlin/reflect/KType;)V
79+
public fun <init> (Ljava/lang/String;Lkotlinx/rpc/descriptor/RpcType;)V
8080
public final fun getName ()Ljava/lang/String;
81-
public final fun getType ()Lkotlin/reflect/KType;
81+
public final fun getType ()Lkotlinx/rpc/descriptor/RpcType;
8282
}
8383

8484
public abstract interface class kotlinx/rpc/descriptor/RpcServiceDescriptor {
@@ -92,3 +92,9 @@ public final class kotlinx/rpc/descriptor/RpcServiceDescriptorKt {
9292
public static final fun serviceDescriptorOf (Lkotlin/reflect/KType;)Lkotlinx/rpc/descriptor/RpcServiceDescriptor;
9393
}
9494

95+
public final class kotlinx/rpc/descriptor/RpcType {
96+
public fun <init> (Lkotlin/reflect/KType;)V
97+
public final fun getKType ()Lkotlin/reflect/KType;
98+
public fun toString ()Ljava/lang/String;
99+
}
100+

core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public interface RpcServiceDescriptor<T : RemoteService> {
5454
@ExperimentalRpcApi
5555
public class RpcCallable<T : RemoteService>(
5656
public val name: String,
57-
public val dataType: KType,
58-
public val returnType: KType,
57+
public val dataType: RpcType,
58+
public val returnType: RpcType,
5959
public val invokator: RpcInvokator<T>,
6060
public val parameters: Array<RpcParameter>,
6161
)
@@ -74,4 +74,11 @@ public sealed interface RpcInvokator<T : RemoteService> {
7474
}
7575

7676
@ExperimentalRpcApi
77-
public class RpcParameter(public val name: String, public val type: KType)
77+
public class RpcParameter(public val name: String, public val type: RpcType)
78+
79+
@ExperimentalRpcApi
80+
public class RpcType(public val kType: KType) {
81+
override fun toString(): String {
82+
return return kType.toString()
83+
}
84+
}

gradle-conventions/latest-only/src/main/kotlin/conventions-gradle-doctor.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ plugins {
99
doctor {
1010
enableTestCaching = false
1111
warnWhenNotUsingParallelGC = true
12-
disallowMultipleDaemons = true
12+
disallowMultipleDaemons = false
1313
GCFailThreshold = 0.5f
1414
}

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializationUtils.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package kotlinx.rpc.krpc.internal
77
import kotlinx.coroutines.flow.Flow
88
import kotlinx.coroutines.flow.SharedFlow
99
import kotlinx.coroutines.flow.StateFlow
10+
import kotlinx.rpc.descriptor.RpcType
1011
import kotlinx.rpc.internal.utils.InternalRpcApi
1112
import kotlinx.serialization.*
1213
import kotlinx.serialization.modules.SerializersModule
@@ -27,6 +28,11 @@ internal fun SerializersModule.buildContextual(type: KType): KSerializer<Any?> {
2728
return result as? KSerializer<Any?> ?: error("No serializer found for $type")
2829
}
2930

31+
@InternalRpcApi
32+
public fun SerializersModule.rpcSerializerForType(type: RpcType): KSerializer<Any?> {
33+
return rpcSerializerForType(type.kType)
34+
}
35+
3036
@InternalRpcApi
3137
public fun SerializersModule.rpcSerializerForType(type: KType): KSerializer<Any?> {
3238
return when (type.classifier) {
@@ -35,6 +41,7 @@ public fun SerializersModule.rpcSerializerForType(type: KType): KSerializer<Any?
3541
}
3642
}
3743

44+
3845
@InternalRpcApi
3946
public fun unsupportedSerialFormatError(serialFormat: SerialFormat): Nothing {
4047
error("Unsupported serial format ${serialFormat::class}, only StringFormat and BinaryFormats are supported")

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface KrpcTestService : RemoteService {
3535
suspend fun nonSerializableClass(localDate: @Contextual LocalDate): LocalDate
3636
suspend fun nonSerializableClassWithSerializer(
3737
localDateTime: @Serializable(LocalDateTimeSerializer::class) LocalDateTime,
38-
): @Serializable(LocalDateTimeSerializer::class) LocalDateTime
38+
): String
3939

4040
suspend fun incomingStreamSyncCollect(arg1: Flow<String>): Int
4141
suspend fun incomingStreamAsyncCollect(arg1: Flow<String>): Int

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTransportTestBase.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ abstract class KrpcTransportTestBase {
157157
}
158158

159159
@Test
160-
@Ignore // todo will fix in next PR
161160
fun nonSerializableParameter() {
162161
runBlocking {
163162
val localDate = LocalDate.of(2001, 8, 23)

0 commit comments

Comments
 (0)