Skip to content

Cleanup of deprecated code and features #349

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

Merged
merged 1 commit into from
Jun 12, 2025
Merged
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 @@ -32,18 +32,10 @@ internal class RpcIrContext(
irBuiltIns.arrayClass.typeWith(anyNullable, Variance.OUT_VARIANCE)
}

val coroutineScope by lazy {
getIrClassSymbol("kotlinx.coroutines", "CoroutineScope")
}

val kTypeClass by lazy {
getIrClassSymbol("kotlin.reflect", "KType")
}

val suspendFunction0 by lazy {
getIrClassSymbol("kotlin.coroutines", "SuspendFunction0")
}

val suspendFunction2 by lazy {
getIrClassSymbol("kotlin.coroutines", "SuspendFunction2")
}
Expand Down Expand Up @@ -92,10 +84,6 @@ internal class RpcIrContext(
getRpcIrClassSymbol("RpcParameter", "descriptor")
}

val rpcDeferredField by lazy {
getRpcIrClassSymbol("RpcDeferredField", "internal")
}

val rpcMethodClass by lazy {
getRpcIrClassSymbol("RpcMethodClass", "internal")
}
Expand Down Expand Up @@ -139,10 +127,6 @@ internal class RpcIrContext(
namedFunction("kotlin", "emptyArray")
}

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

val mapOf by lazy {
namedFunction("kotlin.collections", "mapOf") {
vsApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ private object Stub {
private object Descriptor {
const val CALLABLE_MAP = "callableMap"
const val FQ_NAME = "fqName"
const val GET_FIELDS = "getFields"
const val GET_CALLABLE = "getCallable"
const val CREATE_INSTANCE = "createInstance"
}
Expand Down Expand Up @@ -616,8 +615,6 @@ internal class RpcStubGenerator(
generateGetCallableFunction()

generateCreateInstanceFunction()

generateGetFieldsFunction()
}

/**
Expand Down Expand Up @@ -1186,61 +1183,6 @@ internal class RpcStubGenerator(
}
}

/**
* Function for getting a list of all RPC fields in a given service as [RpcDeferredField<*>]
*
* ```kotlin
* final override fun getFields(service: MyService): List<RpcDeferredField<*>> {
* return listOf( // or emptyList() if no fields
* service.<field-1>,
* ...
* service.<field-n>,
* ) as List<RpcDeferredField<*>>
* }
* ```
*
* Where:
* - `<field-k>` - the k-th field of a given service
*/
private fun IrClass.generateGetFieldsFunction() {
val listType = ctx.irBuiltIns.listClass.typeWith(ctx.rpcDeferredField.starProjectedType)

addFunction {
name = Name.identifier(Descriptor.GET_FIELDS)
visibility = DescriptorVisibilities.PUBLIC
modality = Modality.OPEN

returnType = listType
}.apply {
overriddenSymbols = listOf(ctx.rpcServiceDescriptor.functionByName(Descriptor.GET_FIELDS))

vsApi {
dispatchReceiverParameterVS = stubCompanionObjectThisReceiver
.copyToVS(this@apply, origin = IrDeclarationOrigin.DEFINED)
}

addValueParameter {
name = Name.identifier("service")
type = declaration.serviceType
}

body = irBuilder(symbol).irBlockBody {
val anyListType = ctx.irBuiltIns.listClass.typeWith(ctx.anyNullable)

val listCall = irCall(
callee = ctx.functions.emptyList,
type = anyListType,
).apply listApply@{
arguments {
types { +ctx.anyNullable }
}
}

+irReturn(irAs(listCall, listType))
}
}
}

// Associated object annotation works on JS, WASM, and Native platforms.
// See https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/find-associated-object.html
private fun addAssociatedObjectAnnotationIfPossible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ class RpcCommandLineProcessor : CommandLineProcessor {
override val pluginId = "kotlinx-rpc"

override val pluginOptions = listOf(
StrictModeCliOptions.STATE_FLOW,
StrictModeCliOptions.SHARED_FLOW,
StrictModeCliOptions.NESTED_FLOW,
StrictModeCliOptions.STREAM_SCOPED_FUNCTIONS,
StrictModeCliOptions.SUSPENDING_SERVER_STREAMING,
StrictModeCliOptions.NOT_TOP_LEVEL_SERVER_FLOW,
StrictModeCliOptions.FIELDS,
RpcFirCliOptions.ANNOTATION_TYPE_SAFETY,
)

Expand All @@ -33,10 +26,6 @@ class RpcCommandLineProcessor : CommandLineProcessor {
value: String,
configuration: CompilerConfiguration,
) {
if (option.processAsStrictModeOption(value, configuration)) {
return
}

when (option) {
RpcFirCliOptions.ANNOTATION_TYPE_SAFETY -> {
@Suppress("NullableBooleanElvis")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package kotlinx.rpc.codegen.common

import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
Expand All @@ -21,16 +20,6 @@ object RpcClassId {
val stateFlow = ClassId(FqName("kotlinx.coroutines.flow"), Name.identifier("StateFlow"))
}

object RpcCallableId {
val streamScoped = CallableId(FqName("kotlinx.rpc.krpc"), Name.identifier("streamScoped"))
val withStreamScope = CallableId(FqName("kotlinx.rpc.krpc"), Name.identifier("withStreamScope"))
val StreamScope = CallableId(FqName("kotlinx.rpc.krpc"), Name.identifier("StreamScope"))
val invokeOnStreamScopeCompletion = CallableId(
FqName("kotlinx.rpc.krpc"),
Name.identifier("invokeOnStreamScopeCompletion"),
)
}

object RpcNames {
val SERVICE_STUB_NAME: Name = Name.identifier("\$rpcServiceStub")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package kotlinx.rpc.codegen
import kotlinx.rpc.codegen.checkers.FirCheckedAnnotationHelper
import kotlinx.rpc.codegen.checkers.FirRpcDeclarationCheckers
import kotlinx.rpc.codegen.checkers.FirRpcExpressionCheckers
import kotlinx.rpc.codegen.checkers.diagnostics.FirRpcStrictModeDiagnostics
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.DeclarationCheckers
Expand All @@ -32,7 +31,6 @@ class FirRpcAdditionalCheckers(
session = session,
serializationIsPresent = serializationIsPresent,
annotationTypeSafetyEnabled = configuration.get(RpcFirConfigurationKeys.ANNOTATION_TYPE_SAFETY, true),
modes = configuration.strictModeAggregator(),
)

override val declarationCheckers: DeclarationCheckers = FirRpcDeclarationCheckers(ctx)
Expand All @@ -43,10 +41,7 @@ class FirCheckersContext(
private val session: FirSession,
val serializationIsPresent: Boolean,
val annotationTypeSafetyEnabled: Boolean,
modes: StrictModeAggregator,
) {
val strictModeDiagnostics = FirRpcStrictModeDiagnostics(modes)

val typeParametersCache = session.firCachesFactory.createCache { typeParameter: FirTypeParameterSymbol ->
FirCheckedAnnotationHelper.checkedAnnotations(session, typeParameter)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirFunctionCallChec
class FirRpcDeclarationCheckers(ctx: FirCheckersContext) : DeclarationCheckers() {
override val regularClassCheckers: Set<FirRegularClassChecker> = setOfNotNull(
FirRpcAnnotationCheckerVS(ctx),
if (ctx.serializationIsPresent) FirRpcStrictModeClassCheckerVS(ctx) else null,
if (ctx.serializationIsPresent) FirRpcStrictModeClassCheckerVS() else null,
FirRpcServiceDeclarationCheckerVS(ctx),
)

Expand All @@ -36,6 +36,5 @@ class FirRpcDeclarationCheckers(ctx: FirCheckersContext) : DeclarationCheckers()
class FirRpcExpressionCheckers(ctx: FirCheckersContext) : ExpressionCheckers() {
override val functionCallCheckers: Set<FirFunctionCallChecker> = setOf(
FirCheckedAnnotationFunctionCallCheckerVS(ctx),
FirRpcStrictModeExpressionCheckerVS(ctx),
)
}
Loading