Skip to content

Commit 0700fb7

Browse files
authored
Serialization decoupling (#354)
1 parent df7b1ce commit 0700fb7

File tree

77 files changed

+1133
-3159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1133
-3159
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import org.jetbrains.kotlin.descriptors.SourceElement
1414
import org.jetbrains.kotlin.ir.builders.declarations.IrFieldBuilder
1515
import org.jetbrains.kotlin.ir.declarations.*
1616
import org.jetbrains.kotlin.ir.expressions.IrCall
17+
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
18+
import org.jetbrains.kotlin.ir.expressions.IrExpression
1719
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
1820
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
1921
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
@@ -53,6 +55,12 @@ interface VersionSpecificApi {
5355

5456
var IrConstructor.isPrimaryVS: Boolean
5557

58+
val IrConstructor.parametersVS: List<IrValueParameter>
59+
60+
val IrConstructorCall.argumentsVS: List<IrExpression?>
61+
62+
fun IrType.isNullableVS(): Boolean
63+
5664
val messageCollectorKey: CompilerConfigurationKey<MessageCollector>
5765

5866
companion object {

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

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
1111
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
1212
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
1313
import org.jetbrains.kotlin.ir.types.makeNullable
14+
import org.jetbrains.kotlin.ir.types.typeWith
1415
import org.jetbrains.kotlin.ir.util.functions
1516
import org.jetbrains.kotlin.ir.util.isVararg
1617
import org.jetbrains.kotlin.ir.util.nestedClasses
@@ -32,6 +33,14 @@ internal class RpcIrContext(
3233
irBuiltIns.arrayClass.typeWith(anyNullable, Variance.OUT_VARIANCE)
3334
}
3435

36+
val listOfAnnotations by lazy {
37+
irBuiltIns.listClass.typeWith(irBuiltIns.annotationType)
38+
}
39+
40+
val arrayOfAnnotations by lazy {
41+
irBuiltIns.arrayClass.typeWith(irBuiltIns.annotationType, Variance.OUT_VARIANCE)
42+
}
43+
3544
val kTypeClass by lazy {
3645
getIrClassSymbol("kotlin.reflect", "KType")
3746
}
@@ -68,10 +77,22 @@ internal class RpcIrContext(
6877
getRpcIrClassSymbol("RpcType", "descriptor")
6978
}
7079

80+
val rpcTypeDefault by lazy {
81+
getRpcIrClassSymbol("RpcTypeDefault", "descriptor")
82+
}
83+
84+
val rpcTypeKrpc by lazy {
85+
getRpcIrClassSymbol("RpcTypeKrpc", "descriptor")
86+
}
87+
7188
val rpcCallable by lazy {
7289
getRpcIrClassSymbol("RpcCallable", "descriptor")
7390
}
7491

92+
val rpcCallableDefault by lazy {
93+
getRpcIrClassSymbol("RpcCallableDefault", "descriptor")
94+
}
95+
7596
private val rpcInvokator by lazy {
7697
getRpcIrClassSymbol("RpcInvokator", "descriptor")
7798
}
@@ -84,8 +105,20 @@ internal class RpcIrContext(
84105
getRpcIrClassSymbol("RpcParameter", "descriptor")
85106
}
86107

87-
val rpcMethodClass by lazy {
88-
getRpcIrClassSymbol("RpcMethodClass", "internal")
108+
val rpcParameterDefault by lazy {
109+
getRpcIrClassSymbol("RpcParameterDefault", "descriptor")
110+
}
111+
112+
val kSerializer by lazy {
113+
getIrClassSymbol("kotlinx.serialization", "KSerializer")
114+
}
115+
116+
val kSerializerAnyNullable by lazy {
117+
kSerializer.typeWith(anyNullable)
118+
}
119+
120+
val kSerializerAnyNullableKClass by lazy {
121+
irBuiltIns.kClassClass.typeWith(kSerializerAnyNullable)
89122
}
90123

91124
fun isJsTarget(): Boolean {
@@ -103,10 +136,6 @@ internal class RpcIrContext(
103136
val functions = Functions()
104137

105138
inner class Functions {
106-
val dataCast by lazy {
107-
namedFunction("kotlinx.rpc.internal", "rpcInternalDataCast")
108-
}
109-
110139
val rpcClientCall by lazy {
111140
rpcClient.namedFunction("call")
112141
}
@@ -115,10 +144,6 @@ internal class RpcIrContext(
115144
rpcClient.namedFunction("callServerStreaming")
116145
}
117146

118-
val asArray by lazy {
119-
rpcMethodClass.namedFunction("asArray")
120-
}
121-
122147
val typeOf by lazy {
123148
namedFunction("kotlin.reflect", "typeOf")
124149
}
@@ -135,10 +160,26 @@ internal class RpcIrContext(
135160
}
136161
}
137162

163+
val emptyList by lazy {
164+
namedFunction("kotlin.collections", "emptyList")
165+
}
166+
167+
val listOf by lazy {
168+
namedFunction("kotlin.collections", "listOf") {
169+
vsApi {
170+
it.owner.valueParametersVS().singleOrNull()?.isVararg ?: false
171+
}
172+
}
173+
}
174+
138175
val mapGet by lazy {
139176
irBuiltIns.mapClass.namedFunction("get")
140177
}
141178

179+
val arrayGet by lazy {
180+
irBuiltIns.arrayClass.namedFunction("get")
181+
}
182+
142183
val emptyMap by lazy {
143184
namedFunction("kotlin.collections", "emptyMap")
144185
}

0 commit comments

Comments
 (0)