Skip to content

Remove fields support #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.types.classOrNull
import org.jetbrains.kotlin.ir.util.dumpKotlinLike

/**
Expand Down Expand Up @@ -47,16 +46,10 @@ internal object RpcDeclarationScanner {
return@memoryOptimizedMap null
}

val symbol = declaration.getter!!.returnType.classOrNull

val flowType = when (symbol) {
ctx.flow -> ServiceDeclaration.FlowField.Kind.Plain
ctx.sharedFlow -> ServiceDeclaration.FlowField.Kind.Shared
ctx.stateFlow -> ServiceDeclaration.FlowField.Kind.State
else -> return@memoryOptimizedMap unsupportedDeclaration(service, declaration, logger)
}

ServiceDeclaration.FlowField(declaration, flowType)
error(
"Fields are not supported in @Rpc services, this error should be caught by frontend. " +
"Please report this issue to the kotlinx-rpc maintainers."
)
}

is IrClass -> {
Expand All @@ -80,8 +73,7 @@ internal object RpcDeclarationScanner {
return ServiceDeclaration(
service = service,
stubClass = stubClassNotNull,
methods = declarations.filterIsInstance<ServiceDeclaration.Method>(),
fields = declarations.filterIsInstance<ServiceDeclaration.FlowField>(),
methods = declarations.filterNotNull(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.classOrNull
import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.util.functions
import org.jetbrains.kotlin.ir.util.isVararg
Expand Down Expand Up @@ -45,18 +44,6 @@ internal class RpcIrContext(
getIrClassSymbol("kotlin.reflect", "KType")
}

val lazy by lazy {
getIrClassSymbol("kotlin", "Lazy")
}

val function0 by lazy {
getIrClassSymbol("kotlin", "Function0")
}

val function1 by lazy {
getIrClassSymbol("kotlin", "Function1")
}

val suspendFunction0 by lazy {
getIrClassSymbol("kotlin.coroutines", "SuspendFunction0")
}
Expand All @@ -77,10 +64,6 @@ internal class RpcIrContext(
getIrClassSymbol("kotlinx.coroutines.flow", "StateFlow")
}

val kProperty1 by lazy {
getIrClassSymbol("kotlin.reflect", "KProperty1")
}

val pair by lazy {
getIrClassSymbol("kotlin", "Pair")
}
Expand All @@ -97,10 +80,6 @@ internal class RpcIrContext(
getRpcIrClassSymbol("WithServiceDescriptor", "internal")
}

val rpcEagerFieldAnnotation by lazy {
getRpcIrClassSymbol("RpcEagerField")
}

val rpcServiceDescriptor by lazy {
getRpcIrClassSymbol("RpcServiceDescriptor", "descriptor")
}
Expand All @@ -121,10 +100,6 @@ internal class RpcIrContext(
rpcInvokator.subClass("Method")
}

val rpcInvokatorField by lazy {
rpcInvokator.subClass("Field")
}

val rpcParameter by lazy {
getRpcIrClassSymbol("RpcParameter", "descriptor")
}
Expand All @@ -133,10 +108,6 @@ internal class RpcIrContext(
getRpcIrClassSymbol("RpcDeferredField", "internal")
}

val fieldDataObject by lazy {
getRpcIrClassSymbol("FieldDataObject", "internal")
}

val rpcMethodClass by lazy {
getRpcIrClassSymbol("RpcMethodClass", "internal")
}
Expand All @@ -156,18 +127,6 @@ internal class RpcIrContext(
val functions = Functions()

inner class Functions {
val registerPlainFlowField by lazy {
namedFunction("kotlinx.rpc", "registerPlainFlowField")
}

val registerSharedFlowField by lazy {
namedFunction("kotlinx.rpc", "registerSharedFlowField")
}

val registerStateFlowField by lazy {
namedFunction("kotlinx.rpc", "registerStateFlowField")
}

val dataCast by lazy {
namedFunction("kotlinx.rpc.internal", "rpcInternalDataCast")
}
Expand Down Expand Up @@ -200,30 +159,6 @@ internal class RpcIrContext(
namedFunction("kotlinx.rpc.internal", "scopedClientCall")
}

val lazy by lazy {
namedFunction("kotlin", "lazy") {
vsApi {
it.owner.valueParametersVS().size == 1
}
}
}

val lazyGetValue by lazy {
namedFunction("kotlin", "getValue") {
vsApi {
it.owner.extensionReceiverParameterVS?.type?.classOrNull == [email protected]
}
}
}

val listOf by lazy {
namedFunction("kotlin.collections", "listOf") {
vsApi {
it.owner.valueParametersVS().singleOrNull()?.isVararg ?: false
}
}
}

val emptyList by lazy {
namedFunction("kotlin.collections", "emptyList")
}
Expand Down
Loading