diff --git a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt index 2fe32ec71..2c16f608c 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt @@ -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") } @@ -92,10 +84,6 @@ internal class RpcIrContext( getRpcIrClassSymbol("RpcParameter", "descriptor") } - val rpcDeferredField by lazy { - getRpcIrClassSymbol("RpcDeferredField", "internal") - } - val rpcMethodClass by lazy { getRpcIrClassSymbol("RpcMethodClass", "internal") } @@ -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 { diff --git a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt index 3a74c81e9..61a8c07a5 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt @@ -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" } @@ -616,8 +615,6 @@ internal class RpcStubGenerator( generateGetCallableFunction() generateCreateInstanceFunction() - - generateGetFieldsFunction() } /** @@ -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> { - * return listOf( // or emptyList() if no fields - * service., - * ... - * service., - * ) as List> - * } - * ``` - * - * Where: - * - `` - 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() { diff --git a/compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RpcCompilerPlugin.kt b/compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RpcCompilerPlugin.kt index 441f6794a..d450e67a3 100644 --- a/compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RpcCompilerPlugin.kt +++ b/compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RpcCompilerPlugin.kt @@ -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, ) @@ -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") diff --git a/compiler-plugin/compiler-plugin-common/src/main/core/kotlinx/rpc/codegen/common/Names.kt b/compiler-plugin/compiler-plugin-common/src/main/core/kotlinx/rpc/codegen/common/Names.kt index 6f664dfd2..a60df0872 100644 --- a/compiler-plugin/compiler-plugin-common/src/main/core/kotlinx/rpc/codegen/common/Names.kt +++ b/compiler-plugin/compiler-plugin-common/src/main/core/kotlinx/rpc/codegen/common/Names.kt @@ -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 @@ -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") diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcAdditionalCheckers.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcAdditionalCheckers.kt index 2a8f38125..806540499 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcAdditionalCheckers.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcAdditionalCheckers.kt @@ -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 @@ -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) @@ -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) } diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt deleted file mode 100644 index 6f4b45ef3..000000000 --- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc.codegen - -import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption -import org.jetbrains.kotlin.compiler.plugin.CliOption -import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.config.CompilerConfigurationKey -import kotlin.text.lowercase - -enum class StrictMode { - NONE, WARNING, ERROR; - - companion object { - fun fromCli(value: String): StrictMode? { - return when (value.lowercase()) { - "none" -> NONE - "warning" -> WARNING - "error" -> ERROR - else -> null - } - } - } -} - -data class StrictModeAggregator( - val stateFlow: StrictMode, - val sharedFlow: StrictMode, - val nestedFlow: StrictMode, - val streamScopedFunctions: StrictMode, - val suspendingServerStreaming: StrictMode, - val notTopLevelServerFlow: StrictMode, - val fields: StrictMode, -) - -object StrictModeConfigurationKeys { - val STATE_FLOW = CompilerConfigurationKey.create("state flow rpc mode") - val SHARED_FLOW = CompilerConfigurationKey.create("shared flow rpc mode") - val NESTED_FLOW = CompilerConfigurationKey.create("nested flow rpc mode") - val STREAM_SCOPED_FUNCTIONS = CompilerConfigurationKey.create("stream scoped rpc mode") - val SUSPENDING_SERVER_STREAMING = CompilerConfigurationKey.create( - "suspending server streaming rpc mode" - ) - val NOT_TOP_LEVEL_SERVER_FLOW = CompilerConfigurationKey.create("not top level server flow rpc mode") - val FIELDS = CompilerConfigurationKey.create("fields rpc mode") -} - -fun CompilerConfiguration.strictModeAggregator(): StrictModeAggregator { - return StrictModeAggregator( - stateFlow = get(StrictModeConfigurationKeys.STATE_FLOW, StrictMode.ERROR), - sharedFlow = get(StrictModeConfigurationKeys.SHARED_FLOW, StrictMode.ERROR), - nestedFlow = get(StrictModeConfigurationKeys.NESTED_FLOW, StrictMode.ERROR), - streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.ERROR), - suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.ERROR), - notTopLevelServerFlow = get(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, StrictMode.ERROR), - fields = get(StrictModeConfigurationKeys.FIELDS, StrictMode.ERROR), - ) -} - -object StrictModeCliOptions { - val STATE_FLOW = CliOption( - optionName = "strict-stateFlow", - valueDescription = VALUE_DESCRIPTION, - description = description("StateFlow"), - required = false, - allowMultipleOccurrences = false, - ) - - val SHARED_FLOW = CliOption( - optionName = "strict-sharedFlow", - valueDescription = VALUE_DESCRIPTION, - description = description("SharedFlow"), - required = false, - allowMultipleOccurrences = false, - ) - - val NESTED_FLOW = CliOption( - optionName = "strict-nested-flow", - valueDescription = VALUE_DESCRIPTION, - description = description("Nested flows"), - required = false, - allowMultipleOccurrences = false, - ) - - val STREAM_SCOPED_FUNCTIONS = CliOption( - optionName = "strict-stream-scope", - valueDescription = VALUE_DESCRIPTION, - description = description("Stream Scopes"), - required = false, - allowMultipleOccurrences = false, - ) - - val SUSPENDING_SERVER_STREAMING = CliOption( - optionName = "strict-suspending-server-streaming", - valueDescription = VALUE_DESCRIPTION, - description = description("suspending server streaming methods"), - required = false, - allowMultipleOccurrences = false, - ) - - val NOT_TOP_LEVEL_SERVER_FLOW = CliOption( - optionName = "strict-not-top-level-server-flow", - valueDescription = VALUE_DESCRIPTION, - description = description("not top-level server streaming declarations"), - required = false, - allowMultipleOccurrences = false, - ) - - val FIELDS = CliOption( - optionName = "strict-fields", - valueDescription = VALUE_DESCRIPTION, - description = description("fields", deprecated = true), - required = false, - allowMultipleOccurrences = false, - ) - - const val VALUE_DESCRIPTION = "none, warning or error" - - fun description(entity: String, deprecated: Boolean = false): String { - return "Diagnostic level for $entity in @Rpc services." + if (deprecated) " Deprecated." else "" - } - - val configurationMapper = mapOf( - STATE_FLOW to StrictModeConfigurationKeys.STATE_FLOW, - SHARED_FLOW to StrictModeConfigurationKeys.SHARED_FLOW, - NESTED_FLOW to StrictModeConfigurationKeys.NESTED_FLOW, - STREAM_SCOPED_FUNCTIONS to StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, - SUSPENDING_SERVER_STREAMING to StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, - NOT_TOP_LEVEL_SERVER_FLOW to StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, - FIELDS to StrictModeConfigurationKeys.FIELDS, - ) -} - -fun AbstractCliOption.processAsStrictModeOption(value: String, configuration: CompilerConfiguration): Boolean { - val key = StrictModeCliOptions.configurationMapper[this] ?: return false - val mode = StrictMode.fromCli(value) ?: return false - - configuration.put(key, mode) - return true -} diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/FirRpcCheckers.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/FirRpcCheckers.kt index c29af0220..a31a73cff 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/FirRpcCheckers.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/FirRpcCheckers.kt @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirFunctionCallChec class FirRpcDeclarationCheckers(ctx: FirCheckersContext) : DeclarationCheckers() { override val regularClassCheckers: Set = setOfNotNull( FirRpcAnnotationCheckerVS(ctx), - if (ctx.serializationIsPresent) FirRpcStrictModeClassCheckerVS(ctx) else null, + if (ctx.serializationIsPresent) FirRpcStrictModeClassCheckerVS() else null, FirRpcServiceDeclarationCheckerVS(ctx), ) @@ -36,6 +36,5 @@ class FirRpcDeclarationCheckers(ctx: FirCheckersContext) : DeclarationCheckers() class FirRpcExpressionCheckers(ctx: FirCheckersContext) : ExpressionCheckers() { override val functionCallCheckers: Set = setOf( FirCheckedAnnotationFunctionCallCheckerVS(ctx), - FirRpcStrictModeExpressionCheckerVS(ctx), ) } diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/FirRpcStrictModeClassChecker.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/FirRpcStrictModeClassChecker.kt index 5f6eaf1c6..5b0ba1dfd 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/FirRpcStrictModeClassChecker.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/FirRpcStrictModeClassChecker.kt @@ -4,10 +4,8 @@ package kotlinx.rpc.codegen.checkers -import kotlinx.rpc.codegen.FirCheckersContext import kotlinx.rpc.codegen.FirRpcPredicates import kotlinx.rpc.codegen.checkers.diagnostics.FirRpcStrictModeDiagnostics -import kotlinx.rpc.codegen.common.RpcCallableId import kotlinx.rpc.codegen.common.RpcClassId import kotlinx.rpc.codegen.vsApi import org.jetbrains.kotlin.KtSourceElement @@ -19,9 +17,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.extractArgumentsTypeRefAndSour import org.jetbrains.kotlin.fir.analysis.checkers.toClassLikeSymbol import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.utils.isSuspend -import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.extensions.predicateBasedProvider -import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol import org.jetbrains.kotlin.fir.scopes.impl.toConeType import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol @@ -33,33 +29,8 @@ import org.jetbrains.kotlin.utils.memoryOptimizedPlus import org.jetbrains.kotlinx.serialization.compiler.fir.services.FirSerializablePropertiesProvider import org.jetbrains.kotlinx.serialization.compiler.fir.services.serializablePropertiesProvider -object FirRpcStrictModeExpressionChecker { - private val streamScopeFunctions = setOf( - RpcCallableId.StreamScope, - RpcCallableId.streamScoped, - RpcCallableId.withStreamScope, - RpcCallableId.invokeOnStreamScopeCompletion, - ) - - fun check( - ctx: FirCheckersContext, - expression: FirFunctionCall, - context: CheckerContext, - reporter: DiagnosticReporter, - ) { - expression.calleeReference.toResolvedCallableSymbol()?.let { symbol -> - if (symbol.callableId in streamScopeFunctions) { - ctx.strictModeDiagnostics.STREAM_SCOPE_FUNCTION_IN_RPC?.let { - reporter.reportOn(expression.calleeReference.source, it, context) - } - } - } - } -} - object FirRpcStrictModeClassChecker { fun check( - ctx: FirCheckersContext, declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter, @@ -72,13 +43,11 @@ object FirRpcStrictModeClassChecker { vsApi { declaration.declarationsVS(context.session) }.forEach { declaration -> when (declaration) { is FirPropertySymbol -> { - ctx.strictModeDiagnostics.FIELD_IN_RPC_SERVICE?.let { - reporter.reportOn(declaration.source, it, context) - } + reporter.reportOn(declaration.source, FirRpcStrictModeDiagnostics.FIELD_IN_RPC_SERVICE, context) } is FirNamedFunctionSymbol -> { - checkFunction(ctx, declaration, context, reporter, serializablePropertiesProvider) + checkFunction(declaration, context, reporter, serializablePropertiesProvider) } else -> {} @@ -87,14 +56,13 @@ object FirRpcStrictModeClassChecker { } private fun checkFunction( - ctx: FirCheckersContext, function: FirNamedFunctionSymbol, context: CheckerContext, reporter: DiagnosticReporter, serializablePropertiesProvider: FirSerializablePropertiesProvider, ) { fun reportOn(element: KtSourceElement?, checker: FirRpcStrictModeDiagnostics.() -> KtDiagnosticFactory0?) { - reporter.reportOn(element, ctx.strictModeDiagnostics.checker() ?: return, context) + reporter.reportOn(element, FirRpcStrictModeDiagnostics.checker() ?: return, context) } val returnClassSymbol = vsApi { diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/FirRpcDiagnostics.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/FirRpcDiagnostics.kt index fc566800e..48cbb9bbd 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/FirRpcDiagnostics.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/FirRpcDiagnostics.kt @@ -6,7 +6,6 @@ package kotlinx.rpc.codegen.checkers.diagnostics -import kotlinx.rpc.codegen.StrictModeAggregator import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies import org.jetbrains.kotlin.diagnostics.error0 import org.jetbrains.kotlin.diagnostics.error1 @@ -39,17 +38,15 @@ object FirRpcDiagnostics : RpcKtDiagnosticsContainer() { } } -@Suppress("PropertyName", "detekt.VariableNaming") -class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) : RpcKtDiagnosticsContainer() { - val STATE_FLOW_IN_RPC_SERVICE by modded0(modes.stateFlow) - val SHARED_FLOW_IN_RPC_SERVICE by modded0(modes.sharedFlow) - val NESTED_STREAMING_IN_RPC_SERVICE by modded0(modes.nestedFlow) - val STREAM_SCOPE_FUNCTION_IN_RPC by modded0(modes.streamScopedFunctions) - val SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE by modded0(modes.suspendingServerStreaming) - val NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE by modded0(modes.notTopLevelServerFlow) - val FIELD_IN_RPC_SERVICE by modded0(modes.fields) +object FirRpcStrictModeDiagnostics : RpcKtDiagnosticsContainer() { + val STATE_FLOW_IN_RPC_SERVICE by error0() + val SHARED_FLOW_IN_RPC_SERVICE by error0() + val NESTED_STREAMING_IN_RPC_SERVICE by error0() + val SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE by error0() + val NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE by error0() + val FIELD_IN_RPC_SERVICE by error0() override fun getRendererFactoryVs(): BaseDiagnosticRendererFactory { - return RpcStrictModeDiagnosticRendererFactory(this) + return RpcStrictModeDiagnosticRendererFactory } } diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt index 0a1b8d9fb..56f83a855 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt @@ -4,8 +4,6 @@ package kotlinx.rpc.codegen.checkers.diagnostics -import kotlinx.rpc.codegen.StrictMode -import kotlinx.rpc.codegen.StrictModeAggregator import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory import org.jetbrains.kotlin.diagnostics.rendering.Renderer import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers @@ -71,68 +69,41 @@ private fun Int.indexPositionSpelled(): String { return "$padded$suffix" } -class RpcStrictModeDiagnosticRendererFactory( - private val diagnostics: FirRpcStrictModeDiagnostics, -) : BaseDiagnosticRendererFactory() { +object RpcStrictModeDiagnosticRendererFactory : BaseDiagnosticRendererFactory() { override val MAP by RpcKtDiagnosticFactoryToRendererMap("RpcStrictMode") { map -> - diagnostics.STATE_FLOW_IN_RPC_SERVICE?.let { - map.put( - factory = it, - message = message("StateFlow") { stateFlow }, - ) - } - - diagnostics.SHARED_FLOW_IN_RPC_SERVICE?.let { - map.put( - factory = it, - message = message("SharedFlow") { sharedFlow }, - ) - } - - diagnostics.NESTED_STREAMING_IN_RPC_SERVICE?.let { - map.put( - factory = it, - message = message("Nested streaming") { nestedFlow }, - ) - } - - diagnostics.STREAM_SCOPE_FUNCTION_IN_RPC?.let { - map.put( - factory = it, - message = message("Stream scope usage") { streamScopedFunctions }, - ) - } - - diagnostics.SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE?.let { - map.put( - factory = it, - message = message("Suspend function declaration with server streaming") { suspendingServerStreaming }, - ) - } - - diagnostics.NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE?.let { - map.put( - factory = it, - message = message("Not top-level server-side streaming") { sharedFlow }, - ) - } - - diagnostics.FIELD_IN_RPC_SERVICE?.let { - map.put( - factory = it, - message = message("Field declaration") { fields }, - ) - } - } + map.put( + factory = FirRpcStrictModeDiagnostics.STATE_FLOW_IN_RPC_SERVICE, + message = message("StateFlow") + ) + + map.put( + factory = FirRpcStrictModeDiagnostics.SHARED_FLOW_IN_RPC_SERVICE, + message = message("SharedFlow"), + ) + + map.put( + factory = FirRpcStrictModeDiagnostics.NESTED_STREAMING_IN_RPC_SERVICE, + message = message("Nested streaming"), + ) - private fun message(entityName: String, selector: StrictModeAggregator.() -> StrictMode): String { - val actionWord = when (diagnostics.modes.selector()) { - StrictMode.NONE -> "" - StrictMode.WARNING -> "deprecated" - StrictMode.ERROR -> "prohibited" - } + map.put( + factory = FirRpcStrictModeDiagnostics.SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE, + message = message("Suspend function declaration with server streaming"), + ) + + map.put( + factory = FirRpcStrictModeDiagnostics.NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE, + message = message("Not top-level server-side streaming"), + ) + + map.put( + factory = FirRpcStrictModeDiagnostics.FIELD_IN_RPC_SERVICE, + message = message("Field declaration"), + ) + } - return "$entityName is $actionWord in @Rpc services in strict mode. " + + private fun message(entityName: String): String { + return "$entityName is prohibited in @Rpc services in strict mode. " + "Support will be removed completely in the 0.8.0 release." } } diff --git a/compiler-plugin/compiler-plugin-k2/src/main/latest/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt b/compiler-plugin/compiler-plugin-k2/src/main/latest/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt index ca76f64c2..f6fcdbcad 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/latest/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/latest/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt @@ -65,16 +65,8 @@ class FirRpcServiceDeclarationCheckerVS( } } -class FirRpcStrictModeExpressionCheckerVS( - private val ctx: FirCheckersContext, -) : FirFunctionCallChecker(MppCheckerKind.Common) { - override fun check(expression: FirFunctionCall, context: CheckerContext, reporter: DiagnosticReporter) { - FirRpcStrictModeExpressionChecker.check(ctx, expression, context, reporter) - } -} - -class FirRpcStrictModeClassCheckerVS(private val ctx: FirCheckersContext) : FirRegularClassChecker(MppCheckerKind.Common) { +class FirRpcStrictModeClassCheckerVS : FirRegularClassChecker(MppCheckerKind.Common) { override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) { - FirRpcStrictModeClassChecker.check(ctx, declaration, context, reporter) + FirRpcStrictModeClassChecker.check(declaration, context, reporter) } } diff --git a/compiler-plugin/compiler-plugin-k2/src/main/latest/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt b/compiler-plugin/compiler-plugin-k2/src/main/latest/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt deleted file mode 100644 index 6f7b2e0e1..000000000 --- a/compiler-plugin/compiler-plugin-k2/src/main/latest/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -@file:Suppress("unused") - -package kotlinx.rpc.codegen.checkers.diagnostics - -import kotlinx.rpc.codegen.StrictMode -import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0 -import org.jetbrains.kotlin.diagnostics.Severity -import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies -import org.jetbrains.kotlin.utils.DummyDelegate -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KClass -import kotlin.reflect.KProperty - -inline fun modded0(mode: StrictMode): DiagnosticFactory0DelegateProviderOnNull { - return DiagnosticFactory0DelegateProviderOnNull(mode, T::class) -} - -class DiagnosticFactory0DelegateProviderOnNull( - private val mode: StrictMode, - private val psiType: KClass<*>, -) { - operator fun provideDelegate( - @Suppress("unused") - thisRef: Any?, - prop: KProperty<*>, - ): ReadOnlyProperty { - val severity = when (mode) { - StrictMode.ERROR -> Severity.ERROR - StrictMode.WARNING -> Severity.WARNING - StrictMode.NONE -> null - } ?: return DummyDelegate(null) - - return DummyDelegate( - KtDiagnosticFactory0( - name = prop.name, - severity = severity, - defaultPositioningStrategy = SourceElementPositioningStrategies.DEFAULT, - psiType = psiType, - ), - ) - } -} diff --git a/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_10/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt b/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_10/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt index ca76f64c2..5f09908b1 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_10/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_10/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt @@ -65,14 +65,6 @@ class FirRpcServiceDeclarationCheckerVS( } } -class FirRpcStrictModeExpressionCheckerVS( - private val ctx: FirCheckersContext, -) : FirFunctionCallChecker(MppCheckerKind.Common) { - override fun check(expression: FirFunctionCall, context: CheckerContext, reporter: DiagnosticReporter) { - FirRpcStrictModeExpressionChecker.check(ctx, expression, context, reporter) - } -} - class FirRpcStrictModeClassCheckerVS(private val ctx: FirCheckersContext) : FirRegularClassChecker(MppCheckerKind.Common) { override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) { FirRpcStrictModeClassChecker.check(ctx, declaration, context, reporter) diff --git a/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_10/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt b/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_10/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt deleted file mode 100644 index 6f7b2e0e1..000000000 --- a/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_10/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -@file:Suppress("unused") - -package kotlinx.rpc.codegen.checkers.diagnostics - -import kotlinx.rpc.codegen.StrictMode -import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0 -import org.jetbrains.kotlin.diagnostics.Severity -import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies -import org.jetbrains.kotlin.utils.DummyDelegate -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KClass -import kotlin.reflect.KProperty - -inline fun modded0(mode: StrictMode): DiagnosticFactory0DelegateProviderOnNull { - return DiagnosticFactory0DelegateProviderOnNull(mode, T::class) -} - -class DiagnosticFactory0DelegateProviderOnNull( - private val mode: StrictMode, - private val psiType: KClass<*>, -) { - operator fun provideDelegate( - @Suppress("unused") - thisRef: Any?, - prop: KProperty<*>, - ): ReadOnlyProperty { - val severity = when (mode) { - StrictMode.ERROR -> Severity.ERROR - StrictMode.WARNING -> Severity.WARNING - StrictMode.NONE -> null - } ?: return DummyDelegate(null) - - return DummyDelegate( - KtDiagnosticFactory0( - name = prop.name, - severity = severity, - defaultPositioningStrategy = SourceElementPositioningStrategies.DEFAULT, - psiType = psiType, - ), - ) - } -} diff --git a/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_21/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt b/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_21/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt index ca76f64c2..5f09908b1 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_21/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_21/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt @@ -65,14 +65,6 @@ class FirRpcServiceDeclarationCheckerVS( } } -class FirRpcStrictModeExpressionCheckerVS( - private val ctx: FirCheckersContext, -) : FirFunctionCallChecker(MppCheckerKind.Common) { - override fun check(expression: FirFunctionCall, context: CheckerContext, reporter: DiagnosticReporter) { - FirRpcStrictModeExpressionChecker.check(ctx, expression, context, reporter) - } -} - class FirRpcStrictModeClassCheckerVS(private val ctx: FirCheckersContext) : FirRegularClassChecker(MppCheckerKind.Common) { override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) { FirRpcStrictModeClassChecker.check(ctx, declaration, context, reporter) diff --git a/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_21/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt b/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_21/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt deleted file mode 100644 index 6f7b2e0e1..000000000 --- a/compiler-plugin/compiler-plugin-k2/src/main/pre_2_0_21/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -@file:Suppress("unused") - -package kotlinx.rpc.codegen.checkers.diagnostics - -import kotlinx.rpc.codegen.StrictMode -import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0 -import org.jetbrains.kotlin.diagnostics.Severity -import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies -import org.jetbrains.kotlin.utils.DummyDelegate -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KClass -import kotlin.reflect.KProperty - -inline fun modded0(mode: StrictMode): DiagnosticFactory0DelegateProviderOnNull { - return DiagnosticFactory0DelegateProviderOnNull(mode, T::class) -} - -class DiagnosticFactory0DelegateProviderOnNull( - private val mode: StrictMode, - private val psiType: KClass<*>, -) { - operator fun provideDelegate( - @Suppress("unused") - thisRef: Any?, - prop: KProperty<*>, - ): ReadOnlyProperty { - val severity = when (mode) { - StrictMode.ERROR -> Severity.ERROR - StrictMode.WARNING -> Severity.WARNING - StrictMode.NONE -> null - } ?: return DummyDelegate(null) - - return DummyDelegate( - KtDiagnosticFactory0( - name = prop.name, - severity = severity, - defaultPositioningStrategy = SourceElementPositioningStrategies.DEFAULT, - psiType = psiType, - ), - ) - } -} diff --git a/compiler-plugin/compiler-plugin-k2/src/main/v_2_2/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt b/compiler-plugin/compiler-plugin-k2/src/main/v_2_2/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt index 684070a55..a741232a9 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/v_2_2/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/v_2_2/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt @@ -71,15 +71,6 @@ class FirRpcServiceDeclarationCheckerVS( } } -class FirRpcStrictModeExpressionCheckerVS( - private val ctx: FirCheckersContext, -) : FirFunctionCallChecker(MppCheckerKind.Common) { - context(context: CheckerContext, reporter: DiagnosticReporter) - override fun check(expression: FirFunctionCall) { - FirRpcStrictModeExpressionChecker.check(ctx, expression, context, reporter) - } -} - class FirRpcStrictModeClassCheckerVS(private val ctx: FirCheckersContext) : FirRegularClassChecker(MppCheckerKind.Common) { context(context: CheckerContext, reporter: DiagnosticReporter) override fun check(declaration: FirRegularClass) { diff --git a/compiler-plugin/compiler-plugin-k2/src/main/v_2_2/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt b/compiler-plugin/compiler-plugin-k2/src/main/v_2_2/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt deleted file mode 100644 index 6f7b2e0e1..000000000 --- a/compiler-plugin/compiler-plugin-k2/src/main/v_2_2/kotlinx/rpc/codegen/checkers/diagnostics/DiagnosticFactories.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -@file:Suppress("unused") - -package kotlinx.rpc.codegen.checkers.diagnostics - -import kotlinx.rpc.codegen.StrictMode -import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0 -import org.jetbrains.kotlin.diagnostics.Severity -import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies -import org.jetbrains.kotlin.utils.DummyDelegate -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KClass -import kotlin.reflect.KProperty - -inline fun modded0(mode: StrictMode): DiagnosticFactory0DelegateProviderOnNull { - return DiagnosticFactory0DelegateProviderOnNull(mode, T::class) -} - -class DiagnosticFactory0DelegateProviderOnNull( - private val mode: StrictMode, - private val psiType: KClass<*>, -) { - operator fun provideDelegate( - @Suppress("unused") - thisRef: Any?, - prop: KProperty<*>, - ): ReadOnlyProperty { - val severity = when (mode) { - StrictMode.ERROR -> Severity.ERROR - StrictMode.WARNING -> Severity.WARNING - StrictMode.NONE -> null - } ?: return DummyDelegate(null) - - return DummyDelegate( - KtDiagnosticFactory0( - name = prop.name, - severity = severity, - defaultPositioningStrategy = SourceElementPositioningStrategies.DEFAULT, - psiType = psiType, - ), - ) - } -} diff --git a/compiler-plugin/compiler-plugin-k2/src/main/v_2_2_2/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt b/compiler-plugin/compiler-plugin-k2/src/main/v_2_2_2/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt index 684070a55..a741232a9 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/v_2_2_2/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/v_2_2_2/kotlinx/rpc/codegen/checkers/FirRpcCheckersVS.kt @@ -71,15 +71,6 @@ class FirRpcServiceDeclarationCheckerVS( } } -class FirRpcStrictModeExpressionCheckerVS( - private val ctx: FirCheckersContext, -) : FirFunctionCallChecker(MppCheckerKind.Common) { - context(context: CheckerContext, reporter: DiagnosticReporter) - override fun check(expression: FirFunctionCall) { - FirRpcStrictModeExpressionChecker.check(ctx, expression, context, reporter) - } -} - class FirRpcStrictModeClassCheckerVS(private val ctx: FirCheckersContext) : FirRegularClassChecker(MppCheckerKind.Common) { context(context: CheckerContext, reporter: DiagnosticReporter) override fun check(declaration: FirRegularClass) { diff --git a/core/api/core.api b/core/api/core.api index 29a9fc7d1..4830d8914 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -1,14 +1,3 @@ -public final class kotlinx/rpc/AwaitFieldInitializationKt { - public static final fun awaitFieldInitialization (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun awaitFieldInitialization (Ljava/lang/Object;Lkotlin/reflect/KClass;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class kotlinx/rpc/RegisterFieldKt { - public static final fun registerPlainFlowField (Lkotlinx/rpc/RpcClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/rpc/descriptor/RpcServiceDescriptor;Ljava/lang/String;J)Lkotlinx/coroutines/flow/Flow; - public static final fun registerSharedFlowField (Lkotlinx/rpc/RpcClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/rpc/descriptor/RpcServiceDescriptor;Ljava/lang/String;J)Lkotlinx/coroutines/flow/SharedFlow; - public static final fun registerStateFlowField (Lkotlinx/rpc/RpcClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/rpc/descriptor/RpcServiceDescriptor;Ljava/lang/String;J)Lkotlinx/coroutines/flow/StateFlow; -} - public abstract interface class kotlinx/rpc/RemoteService { } @@ -34,19 +23,11 @@ public abstract interface class kotlinx/rpc/RpcClient { public abstract fun callServerStreaming (Lkotlinx/rpc/RpcCall;)Lkotlinx/coroutines/flow/Flow; } -public abstract interface annotation class kotlinx/rpc/RpcEagerField : java/lang/annotation/Annotation { -} - public abstract interface class kotlinx/rpc/RpcServer { public abstract fun deregisterService (Lkotlin/reflect/KClass;)V public abstract fun registerService (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function0;)V } -public final class kotlinx/rpc/UninitializedRpcFieldException : java/lang/Exception { - public fun (Ljava/lang/String;Lkotlin/reflect/KProperty;)V - public fun getMessage ()Ljava/lang/String; -} - public final class kotlinx/rpc/WithServiceKt { public static final fun withService (Lkotlinx/rpc/RpcClient;Lkotlin/reflect/KClass;)Ljava/lang/Object; public static final fun withService (Lkotlinx/rpc/RpcClient;Lkotlin/reflect/KType;)Ljava/lang/Object; @@ -71,10 +52,6 @@ public final class kotlinx/rpc/descriptor/RpcCallable { public abstract interface class kotlinx/rpc/descriptor/RpcInvokator { } -public abstract interface class kotlinx/rpc/descriptor/RpcInvokator$Field : kotlinx/rpc/descriptor/RpcInvokator { - public abstract fun call (Ljava/lang/Object;)Ljava/lang/Object; -} - public abstract interface class kotlinx/rpc/descriptor/RpcInvokator$Method : kotlinx/rpc/descriptor/RpcInvokator { public abstract fun call (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/RpcCall.kt b/core/src/commonMain/kotlin/kotlinx/rpc/RpcCall.kt index 6c123fd34..87b617f37 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/RpcCall.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/RpcCall.kt @@ -6,9 +6,6 @@ package kotlinx.rpc import kotlinx.rpc.descriptor.RpcServiceDescriptor -@Deprecated("Use RpcCall instead", ReplaceWith("RpcCall"), level = DeprecationLevel.ERROR) -public typealias RPCCall = RpcCall - /** * Represents a method or field call of an RPC service. * diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/RpcClient.kt b/core/src/commonMain/kotlin/kotlinx/rpc/RpcClient.kt index 666ba7951..45685d418 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/RpcClient.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/RpcClient.kt @@ -7,9 +7,6 @@ package kotlinx.rpc import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow -@Deprecated("Use RpcClient instead", ReplaceWith("RpcClient"), level = DeprecationLevel.ERROR) -public typealias RPCClient = RpcClient - /** * [RpcClient] represents an abstraction of an RPC client, that can handle requests from several RPC services, * transform them, send to the server and handle responses and errors. diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/RpcEagerField.kt b/core/src/commonMain/kotlin/kotlinx/rpc/RpcEagerField.kt deleted file mode 100644 index 2709b21ad..000000000 --- a/core/src/commonMain/kotlin/kotlinx/rpc/RpcEagerField.kt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc - -/** - * The field marked with this annotation will be initialized with the service creation. - */ -@Target(AnnotationTarget.PROPERTY) -@Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.ERROR, -) -public annotation class RpcEagerField - diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/RpcServer.kt b/core/src/commonMain/kotlin/kotlinx/rpc/RpcServer.kt index b48910dbd..d0ad7f77f 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/RpcServer.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/RpcServer.kt @@ -7,9 +7,6 @@ package kotlinx.rpc import kotlinx.rpc.annotations.Rpc import kotlin.reflect.KClass -@Deprecated("Use RpcServer instead", ReplaceWith("RpcServer"), level = DeprecationLevel.ERROR) -public typealias RPCServer = RpcServer - /** * RpcServer is used to accept RPC messages, route them to a specific service, and process given responses. * Server may contain multiple services. diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRpcFieldException.kt b/core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRpcFieldException.kt deleted file mode 100644 index 927c1cc48..000000000 --- a/core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRpcFieldException.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc - -import kotlin.reflect.KProperty - -@Deprecated( - "Use UninitializedRpcFieldException instead", - ReplaceWith("UninitializedRpcFieldException"), - level = DeprecationLevel.ERROR, -) -public typealias UninitializedRPCFieldException = UninitializedRpcFieldException - -/** - * Thrown when an uninitialized field of an RPC service is accessed. - * - * Use [awaitFieldInitialization] to await for the field initialization - */ -@Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.WARNING, -) -public class UninitializedRpcFieldException(serviceName: String, property: KProperty<*>) : Exception() { - override val message: String = "${property.name} field of RPC service \"$serviceName\" in not initialized" -} diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/awaitFieldInitialization.kt b/core/src/commonMain/kotlin/kotlinx/rpc/awaitFieldInitialization.kt deleted file mode 100644 index 9e5931822..000000000 --- a/core/src/commonMain/kotlin/kotlinx/rpc/awaitFieldInitialization.kt +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc - -import kotlinx.rpc.annotations.Rpc -import kotlinx.rpc.descriptor.serviceDescriptorOf -import kotlinx.rpc.internal.RpcDeferredField -import kotlin.reflect.KClass - -/** - * Waits for the initialization of an RPC field in the generated client: - * - * ```kotlin - * @Rpc - * interface MyService : RemoteService { - * val stateFlow: StateFlow - * } - * - * val service = rpcClient.withService() - * val currentValue = service.awaitFieldInitialization { stateFlow }.value - * ``` - * - * @param T service type - * @param R field type - * @param getter function that returns the field of the context service to wait for. - * @return service filed after it was initialized. - */ -@Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.ERROR, -) -public suspend fun <@Rpc T : Any, R> T.awaitFieldInitialization(getter: T.() -> R): R { - val field = getter() - - if (field is RpcDeferredField<*>) { - @Suppress("UNCHECKED_CAST") - return (field as RpcDeferredField).await() - } - - error("Please choose required field for a valid RPC client generated by RpcClient.withService method") -} - -/** - * Waits for the initialization of all RPC fields in the generated client: - * - * ```kotlin - * @Rpc - * interface MyService : RemoteService { - * val stateFlow1: StateFlow - * val stateFlow2: StateFlow - * } - * - * val service = rpcClient.withService() - * val currentValue = service.awaitFieldInitialization() - * // fields `stateFlow1` and `stateFlow2` are initialized - * ``` - * - * @param T service type - * @return specified service, after all of it's field were initialized. - */ -@Suppress("RedundantSuspendModifier") -@Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.ERROR, -) -public suspend inline fun <@Rpc reified T : Any> T.awaitFieldInitialization(): T { - error("Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html") -} - -/** - * Waits for the initialization of all RPC fields in the generated client: - * - * ```kotlin - * @Rpc - * interface MyService : RemoteService { - * val stateFlow1: StateFlow - * val stateFlow2: StateFlow - * } - * - * val service = rpcClient.withService() - * val currentValue = service.awaitFieldInitialization(MyService::class) - * // fields `stateFlow1` and `stateFlow2` are initialized - * ``` - * - * @param T service type - * @param kClass [KClass] of the [T] type. - * @return specified service, after all of it's field were initialized. - */ -@Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.ERROR, -) -public suspend fun <@Rpc T : Any> T.awaitFieldInitialization(kClass: KClass): T { - serviceDescriptorOf(kClass) - .getFields(this) - .forEach { field -> - field.await() - } - - return this -} diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt b/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt index 3ace7facc..4873b9193 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt @@ -8,7 +8,6 @@ import kotlinx.rpc.RpcClient import kotlinx.rpc.annotations.Rpc import kotlinx.rpc.internal.* import kotlinx.rpc.internal.utils.ExperimentalRpcApi -import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.KClass import kotlin.reflect.KType @@ -43,13 +42,6 @@ public fun <@Rpc T : Any> serviceDescriptorOf(kClass: KClass): RpcServiceDesc public interface RpcServiceDescriptor<@Rpc T : Any> { public val fqName: String - @InternalRpcApi - @Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.WARNING, - ) - public fun getFields(service: T): List> - public fun getCallable(name: String): RpcCallable? public fun createInstance(serviceId: Long, client: RpcClient): T @@ -71,15 +63,6 @@ public sealed interface RpcInvokator<@Rpc T : Any> { public fun interface Method<@Rpc T : Any> : RpcInvokator { public suspend fun call(service: T, data: Any?): Any? } - - @ExperimentalRpcApi - @Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.WARNING, - ) - public fun interface Field<@Rpc T : Any> : RpcInvokator { - public fun call(service: T): Any? - } } @ExperimentalRpcApi diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/FieldDataObject.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/FieldDataObject.kt deleted file mode 100644 index 64007f9df..000000000 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/FieldDataObject.kt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc.internal - -import kotlinx.rpc.internal.utils.InternalRpcApi -import kotlinx.serialization.Serializable - -/** - * Used for field initialization call - */ -@Serializable -@InternalRpcApi -public object FieldDataObject diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcDeferredField.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcDeferredField.kt deleted file mode 100644 index ff1651336..000000000 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcDeferredField.kt +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc.internal - -import kotlinx.rpc.internal.utils.InternalRpcApi - -@InternalRpcApi -public interface RpcDeferredField { - public suspend fun await(): Self -} diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFieldProvider.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFieldProvider.kt deleted file mode 100644 index 2b58f865b..000000000 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFieldProvider.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc.internal - -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.rpc.UninitializedRpcFieldException -import kotlin.reflect.KProperty - -internal class RpcFieldProvider( - private val serviceName: String, - private val deferred: Deferred = CompletableDeferred(), - val getter: T.() -> R, -) { - @OptIn(ExperimentalCoroutinesApi::class) - operator fun getValue(ref: Any?, property: KProperty<*>): R { - if (deferred.isCompleted) { - return deferred.getCompleted().getter() - } - - throw UninitializedRpcFieldException(serviceName, property) - } -} - -@Suppress("unused") -internal fun RpcFieldProvider( - serviceName: String, - deferred: CompletableDeferred = CompletableDeferred() -): RpcFieldProvider { - return RpcFieldProvider(serviceName, deferred) { this } -} diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFlow.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFlow.kt deleted file mode 100644 index a074d0226..000000000 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFlow.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc.internal - -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.FlowCollector -import kotlinx.coroutines.flow.SharedFlow -import kotlinx.coroutines.flow.StateFlow - -internal sealed class RpcFlow>( - private val serviceName: String, - protected val deferred: Deferred, -) : RpcDeferredField { - override suspend fun await(): FlowT { - return deferred.await() - } - - internal class Plain( - serviceName: String, - deferred: Deferred>, - ) : RpcFlow>(serviceName, deferred), Flow { - override suspend fun collect(collector: FlowCollector) { - deferred.await().collect(collector) - } - } - - internal class Shared( - serviceName: String, - deferred: Deferred>, - ) : RpcFlow>(serviceName, deferred), SharedFlow { - override val replayCache: List by rpcProperty { replayCache } - - override suspend fun collect(collector: FlowCollector): Nothing { - deferred.await().collect(collector) - } - } - - internal class State( - serviceName: String, - deferred: Deferred>, - ) : RpcFlow>(serviceName, deferred), StateFlow { - override val value: T by rpcProperty { value } - - override val replayCache: List by rpcProperty { replayCache } - - override suspend fun collect(collector: FlowCollector): Nothing { - deferred.await().collect(collector) - } - } - - protected fun rpcProperty(getter: FlowT.() -> R): RpcFieldProvider { - return RpcFieldProvider(serviceName, deferred, getter) - } -} diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/registerField.kt b/core/src/commonMain/kotlin/kotlinx/rpc/registerField.kt deleted file mode 100644 index e4e6aeaa7..000000000 --- a/core/src/commonMain/kotlin/kotlinx/rpc/registerField.kt +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.SharedFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.rpc.descriptor.RpcServiceDescriptor -import kotlinx.rpc.internal.RpcFlow - -/** - * Registers Flow field of the interface. Sends initialization request, subscribes to emitted values - * and returns the instance of the flow to be consumed - * - * @param T type parameter for Flow - * @param serviceScope Service's coroutine scope - * @param descriptor descriptor of the service, that made the call - * that is used to be mapped to the corresponding field on a server. - * @param fieldName the name of the field. - * @param serviceId id of the service, that made the call - * @return Flow instance to be consumed. - */ -@Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.ERROR, -) -public fun RpcClient.registerPlainFlowField( - serviceScope: CoroutineScope, - descriptor: RpcServiceDescriptor<*>, - fieldName: String, - serviceId: Long, -): Flow { - return RpcFlow.Plain(descriptor.fqName, initializeFlowField(serviceScope, descriptor, fieldName, serviceId)) -} - -/** - * Registers SharedFlow field of the interface. Sends initialization request, subscribes to emitted values - * and returns the instance of the flow to be consumed - * - * @param T type parameter for SharedFlow - * @param serviceScope Service's coroutine scope - * @param descriptor descriptor of the service, that made the call - * that is used to be mapped to the corresponding field on a server. - * @param fieldName the name of the field. - * @param serviceId id of the service, that made the call - * @return SharedFlow instance to be consumed. - */ -@Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.ERROR, -) -public fun RpcClient.registerSharedFlowField( - serviceScope: CoroutineScope, - descriptor: RpcServiceDescriptor<*>, - fieldName: String, - serviceId: Long, -): SharedFlow { - return RpcFlow.Shared(descriptor.fqName, initializeFlowField(serviceScope, descriptor, fieldName, serviceId)) -} - -/** - * Registers StateFlow field of the interface. Sends initialization request, subscribes to emitted values - * and returns the instance of the flow to be consumed - * - * @param T type parameter for StateFlow - * @param serviceScope Service's coroutine scope - * @param descriptor descriptor of the service, that made the call - * that is used to be mapped to the corresponding field on a server. - * @param fieldName the name of the field. - * @param serviceId id of the service, that made the call - * @return StateFlow instance to be consumed. - */ -@Deprecated( - "Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html", - level = DeprecationLevel.ERROR, -) -public fun RpcClient.registerStateFlowField( - serviceScope: CoroutineScope, - descriptor: RpcServiceDescriptor<*>, - fieldName: String, - serviceId: Long, -): StateFlow { - return RpcFlow.State(descriptor.fqName, initializeFlowField(serviceScope, descriptor, fieldName, serviceId)) -} - -@Suppress("unused", "UnusedReceiverParameter") -private fun > RpcClient.initializeFlowField( - serviceScope: CoroutineScope, - descriptor: RpcServiceDescriptor<*>, - fieldName: String, - serviceId: Long, -): Deferred { - error("Fields are deprecated, see https://kotlin.github.io/kotlinx-rpc/0-5-0.html") -} diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/withService.kt b/core/src/commonMain/kotlin/kotlinx/rpc/withService.kt index 73df9f149..2b8a881ef 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/withService.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/withService.kt @@ -14,8 +14,6 @@ import kotlin.reflect.KType /** * Creates instance of the generated service [T], that is able to communicate with server using [RpcClient]. * - * [awaitFieldInitialization] method can be used on that instance. - * * @param T the exact type of the service to be created. * @return instance of the generated service. */ @@ -26,8 +24,6 @@ public inline fun <@Rpc reified T : Any> RpcClient.withService(): T { /** * Creates instance of the generated service [T], that is able to communicate with server using [RpcClient]. * - * [awaitFieldInitialization] method can be used on that instance. - * * @param T the exact type of the service to be created. * @param serviceKType [KType] of the service to be created. * @return instance of the generated service. @@ -45,8 +41,6 @@ private val SERVICE_ID = atomic(0L) /** * Creates instance of the generated service [T], that is able to communicate with server using [RpcClient]. * - * [awaitFieldInitialization] method can be used on that instance. - * * @param T the exact type of the service to be created. * @param serviceKClass [KClass] of the service to be created. * @return instance of the generated service. diff --git a/gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt b/gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt index b03cf0fd6..6f71a2318 100644 --- a/gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt +++ b/gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt @@ -31,8 +31,8 @@ open class RpcExtension @Inject constructor(objects: ObjectFactory) { /** * Strict mode settings. - * Allows configuring the reporting state of deprecated features. */ + @Deprecated("Strict mode enabled irreversibly. This option can't change it.", level = DeprecationLevel.ERROR) fun strict(configure: Action) { configure.execute(strict) } diff --git a/gradle-plugin/src/main/kotlin/kotlinx/rpc/compilerPlugins.kt b/gradle-plugin/src/main/kotlin/kotlinx/rpc/compilerPlugins.kt index d75dc0a5d..c70a82e61 100644 --- a/gradle-plugin/src/main/kotlin/kotlinx/rpc/compilerPlugins.kt +++ b/gradle-plugin/src/main/kotlin/kotlinx/rpc/compilerPlugins.kt @@ -29,20 +29,8 @@ class CompilerPluginCli : KotlinCompilerPluginSupportPlugin by compilerPlugin({ val extension = it.target.project.extensions.findByType() ?: RpcExtension(it.target.project.objects) - val strict = extension.strict - it.target.project.provider { listOf( - SubpluginOption("strict-stateFlow", strict.stateFlow.get().toCompilerArg()), - SubpluginOption("strict-sharedFlow", strict.sharedFlow.get().toCompilerArg()), - SubpluginOption("strict-nested-flow", strict.nestedFlow.get().toCompilerArg()), - SubpluginOption("strict-stream-scope", strict.streamScopedFunctions.get().toCompilerArg()), - SubpluginOption( - "strict-suspending-server-streaming", - strict.suspendingServerStreaming.get().toCompilerArg() - ), - SubpluginOption("strict-not-top-level-server-flow", strict.notTopLevelServerFlow.get().toCompilerArg()), - SubpluginOption("strict-fields", strict.fields.get().toCompilerArg()), @OptIn(RpcDangerousApi::class) SubpluginOption("annotation-type-safety", extension.annotationTypeSafetyEnabled.get().toString()), ) diff --git a/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt b/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt index e9b768b32..70d9bbe4a 100644 --- a/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt +++ b/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt @@ -36,9 +36,6 @@ import kotlin.concurrent.Volatile import kotlin.coroutines.cancellation.CancellationException import kotlin.properties.Delegates -@Deprecated("Use KrpcClient instead", ReplaceWith("KrpcClient"), level = DeprecationLevel.ERROR) -public typealias KRPCClient = KrpcClient - /** * Default implementation of [RpcClient]. * Takes care of tracking requests and responses, @@ -476,7 +473,6 @@ public abstract class KrpcClient : RpcClient, KrpcEndpoint { private fun RpcCallable<*>.toMessageCallType(): KrpcCallMessage.CallType { return when (invokator) { is RpcInvokator.Method -> KrpcCallMessage.CallType.Method - is RpcInvokator.Field -> KrpcCallMessage.CallType.Field } } } diff --git a/krpc/krpc-core/build.gradle.kts b/krpc/krpc-core/build.gradle.kts index dd7ff2a67..fe19a6840 100644 --- a/krpc/krpc-core/build.gradle.kts +++ b/krpc/krpc-core/build.gradle.kts @@ -14,6 +14,8 @@ plugins { applyAtomicfuPlugin() kotlin { + compilerOptions.freeCompilerArgs.add("-Xexpect-actual-classes") + sourceSets { commonMain { dependencies { diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcConfig.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcConfig.kt index db789b1c8..5a6f04b6a 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcConfig.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcConfig.kt @@ -9,13 +9,10 @@ import kotlinx.rpc.krpc.serialization.KrpcSerialFormat import kotlinx.rpc.krpc.serialization.KrpcSerialFormatBuilder import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration -@Deprecated("Use KrpcConfigBuilder instead", ReplaceWith("KrpcConfigBuilder"), level = DeprecationLevel.ERROR) -public typealias RPCConfigBuilder = KrpcConfigBuilder - /** * Builder for [KrpcConfig]. Provides DSL to configure parameters for KrpcClient and/or KrpcServer. */ -public sealed class KrpcConfigBuilder private constructor() { +public sealed class KrpcConfigBuilder protected constructor() { private var serialFormatInitializer: KrpcSerialFormatBuilder<*, *>? = null private val configuration = object : KrpcSerialFormatConfiguration { @@ -87,9 +84,6 @@ public sealed class KrpcConfigBuilder private constructor() { } } -@Deprecated("Use KrpcConfig instead", ReplaceWith("KrpcConfig"), level = DeprecationLevel.ERROR) -public typealias RPCConfig = KrpcConfig - /** * Configuration class that is used by kRPC protocol's client and server (KrpcClient and KrpcServer). */ diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcTransport.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcTransport.kt index 6e07719e6..3ffc6485d 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcTransport.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcTransport.kt @@ -6,9 +6,6 @@ package kotlinx.rpc.krpc import kotlinx.coroutines.CoroutineScope -@Deprecated("Use KrpcTransportMessage instead", ReplaceWith("KrpcTransportMessage"), level = DeprecationLevel.ERROR) -public typealias RPCTransportMessage = KrpcTransportMessage - /** * A single message that can be transferred from one RPC endpoint to another. * Can be either of string or binary type. @@ -19,9 +16,6 @@ public sealed interface KrpcTransportMessage { public class BinaryMessage(public val value: ByteArray) : KrpcTransportMessage } -@Deprecated("Use KrpcTransport instead", ReplaceWith("KrpcTransport"), level = DeprecationLevel.ERROR) -public typealias RPCTransport = KrpcTransport - /** * An abstraction of transport capabilities for KrpcClient and KrpcServer. * diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcMessage.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcMessage.kt index 63ba30f37..64b678038 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcMessage.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcMessage.kt @@ -115,7 +115,9 @@ public sealed interface KrpcCallMessage : KrpcMessage { @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.CallType") public enum class CallType { - Method, Field, + Method, + @Deprecated("Fields are not supported anymore. Use Method instead.") + Field, } @InternalRpcApi diff --git a/krpc/krpc-ktor/krpc-ktor-client/api/krpc-ktor-client.api b/krpc/krpc-ktor/krpc-ktor-client/api/krpc-ktor-client.api index ddff8bb1e..199d0fbbe 100644 --- a/krpc/krpc-ktor/krpc-ktor-client/api/krpc-ktor-client.api +++ b/krpc/krpc-ktor/krpc-ktor-client/api/krpc-ktor-client.api @@ -1,10 +1,7 @@ public final class kotlinx/rpc/krpc/ktor/client/KrpcKt { public static final fun getKrpc ()Lio/ktor/client/plugins/api/ClientPlugin; - public static final fun getRPC ()Lio/ktor/client/plugins/api/ClientPlugin; public static final fun installKrpc (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;)V public static synthetic fun installKrpc$default (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V - public static final fun installRPC (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;)V - public static synthetic fun installRPC$default (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V } public final class kotlinx/rpc/krpc/ktor/client/KtorClientDslKt { diff --git a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/Krpc.kt b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/Krpc.kt index aef216e9f..867a180ec 100644 --- a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/Krpc.kt +++ b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/Krpc.kt @@ -12,9 +12,6 @@ import kotlinx.rpc.krpc.KrpcConfigBuilder internal val KrpcClientPluginAttributesKey = AttributeKey("KrpcClientPluginAttributesKey") -@Deprecated("Use Krpc instead", ReplaceWith("Krpc"), level = DeprecationLevel.ERROR) -public val RPC: ClientPlugin get() = Krpc - /** * Ktor client plugin that allows to configure RPC globally for all instances obtained via [rpc] functions. */ @@ -22,11 +19,6 @@ public val Krpc: ClientPlugin = createClientPlugin("Kr client.attributes.put(KrpcClientPluginAttributesKey, pluginConfig) } -@Deprecated("Use installKrpc instead", ReplaceWith("installKrpc"), level = DeprecationLevel.ERROR) -public fun HttpClientConfig<*>.installRPC(configure: KrpcConfigBuilder.Client.() -> Unit = {}) { - installKrpc(configure) -} - /** * Installs [WebSockets] and [Krpc] client plugins */ diff --git a/krpc/krpc-ktor/krpc-ktor-server/api/krpc-ktor-server.api b/krpc/krpc-ktor/krpc-ktor-server/api/krpc-ktor-server.api index cea1ea828..feb0180fb 100644 --- a/krpc/krpc-ktor/krpc-ktor-server/api/krpc-ktor-server.api +++ b/krpc/krpc-ktor/krpc-ktor-server/api/krpc-ktor-server.api @@ -1,6 +1,5 @@ public final class kotlinx/rpc/krpc/ktor/server/KrpcKt { public static final fun getKrpc ()Lio/ktor/server/application/ApplicationPlugin; - public static final fun getRPC ()Lio/ktor/server/application/ApplicationPlugin; } public final class kotlinx/rpc/krpc/ktor/server/KrpcRoute : io/ktor/server/websocket/DefaultWebSocketServerSession { diff --git a/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt b/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt index 41ac1076c..f14dc06a7 100644 --- a/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt +++ b/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt @@ -11,9 +11,6 @@ import kotlinx.rpc.krpc.KrpcConfigBuilder internal val KrpcServerPluginAttributesKey = AttributeKey("KrpcServerPluginAttributesKey") -@Deprecated("Use Krpc instead", ReplaceWith("Krpc"), level = DeprecationLevel.ERROR) -public val RPC: ApplicationPlugin get() = Krpc - /** * Ktor server plugin that allows to configure RPC globally for all mounted servers. */ diff --git a/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt b/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt index 857df76f1..800bac856 100644 --- a/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt +++ b/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt @@ -10,9 +10,6 @@ import kotlinx.rpc.annotations.Rpc import kotlinx.rpc.krpc.KrpcConfigBuilder import kotlin.reflect.KClass -@Deprecated("Use KrpcRoute instead", ReplaceWith("KrpcRoute"), level = DeprecationLevel.ERROR) -public typealias RPCRoute = KrpcRoute - /** * RpcRoute class represents an RPC server that is mounted in Ktor routing. * This class provides API to register services and optionally setup configuration. diff --git a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormat.kt b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormat.kt index 3f1f129a7..5e8c060d7 100644 --- a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormat.kt +++ b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormat.kt @@ -10,9 +10,6 @@ import kotlinx.serialization.SerialFormat import kotlinx.serialization.StringFormat import kotlinx.serialization.modules.SerializersModule -@Deprecated("Use KrpcSerialFormat instead", ReplaceWith("KrpcSerialFormat"), level = DeprecationLevel.ERROR) -public typealias RPCSerialFormat = KrpcSerialFormat - /** * [KrpcSerialFormat] interface defines an object which helps kRPC protocol to work with various serialization formats * @@ -35,13 +32,6 @@ public interface KrpcSerialFormat { public fun FormatBuilder.applySerializersModule(serializersModule: SerializersModule) } -@Deprecated( - "Use KrpcSerialFormatBuilder instead", - ReplaceWith("KrpcSerialFormatBuilder"), - level = DeprecationLevel.ERROR, -) -public typealias RPCSerialFormatBuilder = KrpcSerialFormatBuilder - /** * Special wrapper class that is used to register serialization format in [KrpcSerialFormatConfiguration] * Comes in two instances: [KrpcSerialFormatBuilder.Binary] and [KrpcSerialFormatBuilder.String] diff --git a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration.kt b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration.kt index 3e777102b..fa764ddc6 100644 --- a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration.kt +++ b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration.kt @@ -4,13 +4,6 @@ package kotlinx.rpc.krpc.serialization -@Deprecated( - "Use KrpcSerialFormatConfiguration instead", - ReplaceWith("KrpcSerialFormatConfiguration"), - level = DeprecationLevel.ERROR, -) -public typealias RPCSerialFormatConfiguration = KrpcSerialFormatConfiguration - /** * Special interface to configure serialization for a kRPC protocol in KrpcConfig * ```kotlin diff --git a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt index a4cad98a2..ded0c3715 100644 --- a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt +++ b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt @@ -20,9 +20,6 @@ import kotlinx.rpc.krpc.server.internal.KrpcServerService import kotlin.concurrent.Volatile import kotlin.reflect.KClass -@Deprecated("Use KrpcServer instead", ReplaceWith("KrpcServer"), level = DeprecationLevel.ERROR) -public typealias KRPCServer = KrpcServer - /** * Default implementation of [RpcServer]. * Takes care of tracking requests and responses, diff --git a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt index 9ab5afba7..5f4a10cb4 100644 --- a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt +++ b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt @@ -110,6 +110,14 @@ internal class KrpcServerService<@Rpc T : Any>( .endsWith("\$method") // compatibility with beta-4.2 clients } + if (!isMethod) { + error( + "Service ${descriptor.fqName} doesn't support fields calls, " + + "but got a field call: ${callData.callableName} with callId $callId. " + + "Please, update the client version or change the call type to method." + ) + } + val callableName = callData.callableName .substringBefore('$') // compatibility with beta-4.2 clients @@ -150,10 +158,6 @@ internal class KrpcServerService<@Rpc T : Any>( is RpcInvokator.Method -> { invokator.call(service, data) } - - is RpcInvokator.Field -> { - invokator.call(service) - } }.let { interceptedValue -> // KRPC-173 if (!callable.isNonSuspendFunction && callable.returnType.kType == typeOf()) { diff --git a/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationTest.kt b/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationTest.kt index 10c9d9dc8..17d15d787 100644 --- a/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationTest.kt +++ b/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationTest.kt @@ -122,7 +122,7 @@ class CancellationTest { } @Test - fun testStreamScopeOutgoing() = runCancellationTest { + fun testStreamOutgoing() = runCancellationTest { service.outgoingStream( flow { repeat(2) { @@ -142,7 +142,7 @@ class CancellationTest { } @Test - fun testStreamScopeIncoming() = runCancellationTest { + fun testStreamIncoming() = runCancellationTest { var first: Int = -1 val flow = service.incomingStream() diff --git a/tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt b/tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt index 9b86738f1..228579de0 100644 --- a/tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt +++ b/tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt @@ -5,8 +5,6 @@ package kotlinx.rpc.codegen.test.services import kotlinx.rpc.codegen.RpcFirConfigurationKeys -import kotlinx.rpc.codegen.StrictMode -import kotlinx.rpc.codegen.StrictModeConfigurationKeys import kotlinx.rpc.codegen.registerRpcExtensions import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar import org.jetbrains.kotlin.config.CompilerConfiguration @@ -25,18 +23,6 @@ class ExtensionRegistrarConfigurator(testServices: TestServices) : EnvironmentCo module: TestModule, configuration: CompilerConfiguration, ) { - val strictMode = module.directives[RpcDirectives.RPC_STRICT_MODE] - if (strictMode.isNotEmpty()) { - val mode = StrictMode.fromCli(strictMode.single()) ?: StrictMode.ERROR - configuration.put(StrictModeConfigurationKeys.STATE_FLOW, mode) - configuration.put(StrictModeConfigurationKeys.SHARED_FLOW, mode) - configuration.put(StrictModeConfigurationKeys.NESTED_FLOW, mode) - configuration.put(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, mode) - configuration.put(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, mode) - configuration.put(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, mode) - configuration.put(StrictModeConfigurationKeys.FIELDS, mode) - } - val annotationTypeSafety = module.directives[RpcDirectives.ANNOTATION_TYPE_SAFETY] if (annotationTypeSafety.isNotEmpty()) { configuration.put( @@ -53,6 +39,5 @@ class ExtensionRegistrarConfigurator(testServices: TestServices) : EnvironmentCo } object RpcDirectives : SimpleDirectivesContainer() { - val RPC_STRICT_MODE by stringDirective("none, warning or error", DirectiveApplicability.Module) val ANNOTATION_TYPE_SAFETY by stringDirective("true or false", DirectiveApplicability.Module) } diff --git a/tests/compiler-plugin-tests/src/testData/box/customParameterTypes.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/customParameterTypes.fir.ir.txt index f3c05f89a..aaa43832f 100644 --- a/tests/compiler-plugin-tests/src/testData/box/customParameterTypes.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/customParameterTypes.fir.ir.txt @@ -511,16 +511,6 @@ FILE fqName: fileName:/customParameterTypes.kt $this: CALL 'private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY $this: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null - FUN name:getFields visibility:public modality:OPEN <> ($this:.BoxService.$rpcServiceStub.Companion, service:.BoxService) returnType:kotlin.collections.List> - overridden: - public abstract fun getFields (service: T of kotlinx.rpc.descriptor.RpcServiceDescriptor): kotlin.collections.List> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor - $this: VALUE_PARAMETER name: type:.BoxService.$rpcServiceStub.Companion - VALUE_PARAMETER name:service index:0 type:.BoxService - BLOCK_BODY - RETURN type=kotlin.Nothing from='public open fun getFields (service: .BoxService): kotlin.collections.List> declared in .BoxService.$rpcServiceStub.Companion' - TYPE_OP type=kotlin.collections.List> origin=CAST typeOperand=kotlin.collections.List> - CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null - : kotlin.Any? CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] CLASS name:test1$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = ) diff --git a/tests/compiler-plugin-tests/src/testData/box/flowParameter.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/flowParameter.fir.ir.txt index c71311998..7caead7bc 100644 --- a/tests/compiler-plugin-tests/src/testData/box/flowParameter.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/flowParameter.fir.ir.txt @@ -148,16 +148,6 @@ FILE fqName: fileName:/flowParameter.kt $this: CALL 'private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY $this: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null - FUN name:getFields visibility:public modality:OPEN <> ($this:.BoxService.$rpcServiceStub.Companion, service:.BoxService) returnType:kotlin.collections.List> - overridden: - public abstract fun getFields (service: T of kotlinx.rpc.descriptor.RpcServiceDescriptor): kotlin.collections.List> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor - $this: VALUE_PARAMETER name: type:.BoxService.$rpcServiceStub.Companion - VALUE_PARAMETER name:service index:0 type:.BoxService - BLOCK_BODY - RETURN type=kotlin.Nothing from='public open fun getFields (service: .BoxService): kotlin.collections.List> declared in .BoxService.$rpcServiceStub.Companion' - TYPE_OP type=kotlin.collections.List> origin=CAST typeOperand=kotlin.collections.List> - CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null - : kotlin.Any? CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] CLASS name:stream$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = ) diff --git a/tests/compiler-plugin-tests/src/testData/box/multiModule.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/multiModule.fir.ir.txt index 6efbbd234..2dc4375cf 100644 --- a/tests/compiler-plugin-tests/src/testData/box/multiModule.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/multiModule.fir.ir.txt @@ -141,16 +141,6 @@ FILE fqName: fileName:/module_lib_multiModule.kt $this: CALL 'private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY $this: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null - FUN name:getFields visibility:public modality:OPEN <> ($this:.BoxService.$rpcServiceStub.Companion, service:.BoxService) returnType:kotlin.collections.List> - overridden: - public abstract fun getFields (service: T of kotlinx.rpc.descriptor.RpcServiceDescriptor): kotlin.collections.List> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor - $this: VALUE_PARAMETER name: type:.BoxService.$rpcServiceStub.Companion - VALUE_PARAMETER name:service index:0 type:.BoxService - BLOCK_BODY - RETURN type=kotlin.Nothing from='public open fun getFields (service: .BoxService): kotlin.collections.List> declared in .BoxService.$rpcServiceStub.Companion' - TYPE_OP type=kotlin.collections.List> origin=CAST typeOperand=kotlin.collections.List> - CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null - : kotlin.Any? CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = ) diff --git a/tests/compiler-plugin-tests/src/testData/box/simple.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/simple.fir.ir.txt index 8433002ff..15de1bff3 100644 --- a/tests/compiler-plugin-tests/src/testData/box/simple.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/simple.fir.ir.txt @@ -140,16 +140,6 @@ FILE fqName: fileName:/simple.kt $this: CALL 'private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY $this: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null - FUN name:getFields visibility:public modality:OPEN <> ($this:.BoxService.$rpcServiceStub.Companion, service:.BoxService) returnType:kotlin.collections.List> - overridden: - public abstract fun getFields (service: T of kotlinx.rpc.descriptor.RpcServiceDescriptor): kotlin.collections.List> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor - $this: VALUE_PARAMETER name: type:.BoxService.$rpcServiceStub.Companion - VALUE_PARAMETER name:service index:0 type:.BoxService - BLOCK_BODY - RETURN type=kotlin.Nothing from='public open fun getFields (service: .BoxService): kotlin.collections.List> declared in .BoxService.$rpcServiceStub.Companion' - TYPE_OP type=kotlin.collections.List> origin=CAST typeOperand=kotlin.collections.List> - CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null - : kotlin.Any? CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = ) diff --git a/tests/compiler-plugin-tests/src/testData/diagnostics/rpcChecked.fir.txt b/tests/compiler-plugin-tests/src/testData/diagnostics/rpcChecked.fir.txt index 9129dc8fe..9c77a3020 100644 --- a/tests/compiler-plugin-tests/src/testData/diagnostics/rpcChecked.fir.txt +++ b/tests/compiler-plugin-tests/src/testData/diagnostics/rpcChecked.fir.txt @@ -31,16 +31,6 @@ FILE: rpcChecked.kt ^ R|/impl| } ) - R|/myServiceImpl|.R|kotlinx/rpc/awaitFieldInitialization|() - R|/myServiceImpl|.R|kotlinx/rpc/awaitFieldInitialization|( = awaitFieldInitialization@fun R|MyService|.(): R|kotlin/Int| { - ^ Int(1) - } - ) - R|/impl|.R|kotlinx/rpc/awaitFieldInitialization|() - R|/impl|.R|kotlinx/rpc/awaitFieldInitialization|( = awaitFieldInitialization@fun R|T|.(): R|kotlin/Int| { - ^ Int(1) - } - ) R|kotlinx/rpc/descriptor/serviceDescriptorOf|() R|kotlinx/rpc/descriptor/serviceDescriptorOf|() } @@ -60,21 +50,6 @@ FILE: rpcChecked.kt ^ R|/impl| } ) - R|/myServiceImpl|.R|kotlinx/rpc/awaitFieldInitialization|() - R|/myServiceImpl|.R|kotlinx/rpc/awaitFieldInitialization|( = awaitFieldInitialization@fun R|MyServiceImpl|.(): R|kotlin/Int| { - ^ Int(1) - } - ) - R|/notAServiceImpl|.R|kotlinx/rpc/awaitFieldInitialization|() - R|/notAServiceImpl|.R|kotlinx/rpc/awaitFieldInitialization|( = awaitFieldInitialization@fun R|NotAService|.(): R|kotlin/Int| { - ^ Int(1) - } - ) - R|/impl|.R|kotlinx/rpc/awaitFieldInitialization|() - R|/impl|.R|kotlinx/rpc/awaitFieldInitialization|( = awaitFieldInitialization@fun R|T|.(): R|kotlin/Int| { - ^ Int(1) - } - ) R|kotlinx/rpc/descriptor/serviceDescriptorOf|() R|kotlinx/rpc/descriptor/serviceDescriptorOf|() R|kotlinx/rpc/descriptor/serviceDescriptorOf|() diff --git a/tests/compiler-plugin-tests/src/testData/diagnostics/rpcChecked.kt b/tests/compiler-plugin-tests/src/testData/diagnostics/rpcChecked.kt index 999c6fc79..c0a9c9ddd 100644 --- a/tests/compiler-plugin-tests/src/testData/diagnostics/rpcChecked.kt +++ b/tests/compiler-plugin-tests/src/testData/diagnostics/rpcChecked.kt @@ -12,7 +12,6 @@ import kotlinx.rpc.RpcClient import kotlinx.rpc.RpcServer import kotlinx.rpc.registerService import kotlinx.rpc.descriptor.serviceDescriptorOf -import kotlinx.rpc.awaitFieldInitialization import kotlinx.rpc.internal.utils.ExperimentalRpcApi @Rpc @@ -29,12 +28,6 @@ inline suspend fun <@Rpc reified T : Any> ok(client: RpcClient, server: RpcServe server.registerService { MyServiceImpl() } server.registerService { impl } - myServiceImpl.awaitFieldInitialization() - myServiceImpl.awaitFieldInitialization { 1 } - - impl.awaitFieldInitialization() - impl.awaitFieldInitialization { 1 } - serviceDescriptorOf() serviceDescriptorOf() } @@ -48,15 +41,6 @@ inline suspend fun fail(client: RpcClient, server: RpcServer, server.registerService<NotAService> { NotAService() } server.registerService<T> { impl } - myServiceImpl.awaitFieldInitialization<MyServiceImpl>() - myServiceImpl.awaitFieldInitialization<MyServiceImpl, Int> { 1 } - - notAServiceImpl.awaitFieldInitialization<NotAService>() - notAServiceImpl.awaitFieldInitialization<NotAService, Int> { 1 } - - impl.awaitFieldInitialization<T>() - impl.awaitFieldInitialization<T, Int> { 1 } - serviceDescriptorOf<MyServiceImpl>() serviceDescriptorOf<NotAService>() serviceDescriptorOf<T>() diff --git a/tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.fir.txt b/tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.fir.txt index eeec73574..cf4fea132 100644 --- a/tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.fir.txt +++ b/tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.fir.txt @@ -1,49 +1,3 @@ -Module: none -FILE: a.kt - @R|kotlinx/rpc/annotations/Rpc|() public abstract interface MyServiceWithStateFlow : R|kotlin/Any| { - public abstract suspend fun hello(flow: R|kotlinx/coroutines/flow/StateFlow|): R|kotlin/Unit| - - public final class $rpcServiceStub : R|kotlin/Any| { - @R|kotlinx/serialization/Serializable|() public final class hello$rpcMethod : R|kotlin/Any| { - @R|kotlinx/serialization/Contextual|() public final val flow: R|kotlinx/coroutines/flow/StateFlow| - public get(): R|kotlinx/coroutines/flow/StateFlow| - - public constructor(flow: R|kotlinx/coroutines/flow/StateFlow|): R|MyServiceWithStateFlow.$rpcServiceStub.hello$rpcMethod| - - public final companion object Companion : R|kotlin/Any| { - public final fun serializer(): R|kotlinx/serialization/KSerializer| - - private constructor(): R|MyServiceWithStateFlow.$rpcServiceStub.hello$rpcMethod.Companion| { - super() - } - - } - - @R|kotlin/Deprecated|(message = String(This synthesized declaration should not be used directly), level = Q|kotlin/DeprecationLevel|.R|kotlin/DeprecationLevel.HIDDEN|) public final object $serializer : R|kotlinx/serialization/internal/GeneratedSerializer| { - public final override fun serialize(encoder: R|kotlinx/serialization/encoding/Encoder|, value: R|MyServiceWithStateFlow.$rpcServiceStub.hello$rpcMethod|): R|kotlin/Unit| - - public final override fun deserialize(decoder: R|kotlinx/serialization/encoding/Decoder|): R|MyServiceWithStateFlow.$rpcServiceStub.hello$rpcMethod| - - public final val descriptor: R|kotlinx/serialization/descriptors/SerialDescriptor| - public get(): R|kotlinx/serialization/descriptors/SerialDescriptor| - - public final override fun childSerializers(): R|kotlin/Array>| - - private constructor(): R|MyServiceWithStateFlow.$rpcServiceStub.hello$rpcMethod.$serializer| { - super() - } - - } - - } - - public final companion object Companion : R|kotlin/Any| { - } - - } - - } -Module: main FILE: b.kt @FILE:R|kotlin/OptIn|(markerClass = vararg((Q|kotlinx/rpc/internal/utils/ExperimentalRpcApi|))) @R|kotlinx/serialization/Serializable|() public final data class InnerFlow : R|kotlin/Any| { diff --git a/tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.kt b/tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.kt index ff19c70d0..4b747e00b 100644 --- a/tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.kt +++ b/tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.kt @@ -2,21 +2,7 @@ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ -// MODULE: none -// RPC_STRICT_MODE: none -// FILE: a.kt - -import kotlinx.coroutines.* -import kotlinx.coroutines.flow.* -import kotlinx.rpc.annotations.Rpc - -@Rpc -interface MyServiceWithStateFlow { - suspend fun hello(flow: StateFlow) -} - // MODULE: main -// RPC_STRICT_MODE: warning // FILE: b.kt @file:OptIn(ExperimentalRpcApi::class) diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalSupervisedCompletableDeferred.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalSupervisedCompletableDeferred.kt deleted file mode 100644 index 969cb2277..000000000 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalSupervisedCompletableDeferred.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc.internal.utils - -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.Job -import kotlinx.coroutines.currentCoroutineContext -import kotlinx.coroutines.job - -/** - * Cancels when parent is canceled, but not otherwise - */ -@InternalRpcApi -public class RpcInternalSupervisedCompletableDeferred( - parent: Job, -) : CompletableDeferred by CompletableDeferred() { - init { - val handle = parent.invokeOnCompletion { cause -> - if (cause != null) { - completeExceptionally(cause) - } - } - - invokeOnCompletion { - handle.dispose() - } - } -} - -@InternalRpcApi -public suspend fun RpcInternalSupervisedCompletableDeferred(): RpcInternalSupervisedCompletableDeferred { - return RpcInternalSupervisedCompletableDeferred(currentCoroutineContext().job) -}