diff --git a/compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/IrUtils.kt b/compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/IrUtils.kt index 5f3800ee7..7ab1364db 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/IrUtils.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/IrUtils.kt @@ -11,7 +11,9 @@ import org.jetbrains.kotlin.ir.builders.declarations.buildField import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrExpressionBody +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol +import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrTypeArgument import org.jetbrains.kotlin.ir.types.IrTypeProjection @@ -19,8 +21,8 @@ import org.jetbrains.kotlin.ir.types.SimpleTypeNullability import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.util.dump +import org.jetbrains.kotlin.ir.util.properties import org.jetbrains.kotlin.types.Variance -import java.util.* fun IrClassifierSymbol.typeWith(type: IrType, variance: Variance): IrType { return IrSimpleTypeImpl( @@ -31,9 +33,10 @@ fun IrClassifierSymbol.typeWith(type: IrType, variance: Variance): IrType { ) } -val IrProperty.getterOrFail: IrSimpleFunction get () { - return getter ?: error("'getter' should be present, but was null: ${dump()}") -} +val IrProperty.getterOrFail: IrSimpleFunction + get() { + return getter ?: error("'getter' should be present, but was null: ${dump()}") + } fun IrProperty.addDefaultGetter( parentClass: IrClass, @@ -95,3 +98,6 @@ fun List.compactIfPossible(): List = @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // TODO(KTIJ-26314): Remove this suppression fun IrFactory.createExpressionBody(expression: IrExpression): IrExpressionBody = createExpressionBody(expression.startOffset, expression.endOffset, expression) + +fun IrClassSymbol.findPropertyByName(name: String): IrPropertySymbol? = + owner.properties.singleOrNull { it.name.asString() == name }?.symbol \ No newline at end of file diff --git a/compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt b/compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt index 11ef4eb13..12b363b3c 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt @@ -13,16 +13,64 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET -import org.jetbrains.kotlin.ir.builders.* -import org.jetbrains.kotlin.ir.builders.declarations.* -import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.builders.IrBlockBodyBuilder +import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope +import org.jetbrains.kotlin.ir.builders.declarations.addConstructor +import org.jetbrains.kotlin.ir.builders.declarations.addFunction +import org.jetbrains.kotlin.ir.builders.declarations.addProperty +import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter +import org.jetbrains.kotlin.ir.builders.declarations.buildFun +import org.jetbrains.kotlin.ir.builders.irAs +import org.jetbrains.kotlin.ir.builders.irBlockBody +import org.jetbrains.kotlin.ir.builders.irCall +import org.jetbrains.kotlin.ir.builders.irCallConstructor +import org.jetbrains.kotlin.ir.builders.irDelegatingConstructorCall +import org.jetbrains.kotlin.ir.builders.irGet +import org.jetbrains.kotlin.ir.builders.irReturn +import org.jetbrains.kotlin.ir.builders.irVararg +import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer +import org.jetbrains.kotlin.ir.declarations.IrClass +import org.jetbrains.kotlin.ir.declarations.IrConstructor +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrFunction +import org.jetbrains.kotlin.ir.declarations.IrProperty +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.declarations.IrValueParameter +import org.jetbrains.kotlin.ir.expressions.IrCall +import org.jetbrains.kotlin.ir.expressions.IrClassReference +import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.expressions.IrTypeOperator +import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrClassReferenceImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionExpressionImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl +import org.jetbrains.kotlin.ir.expressions.putConstructorTypeArgument import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.symbols.IrValueSymbol -import org.jetbrains.kotlin.ir.types.* -import org.jetbrains.kotlin.ir.util.* +import org.jetbrains.kotlin.ir.types.IrSimpleType +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.classOrNull +import org.jetbrains.kotlin.ir.types.createType +import org.jetbrains.kotlin.ir.types.defaultType +import org.jetbrains.kotlin.ir.types.typeWith +import org.jetbrains.kotlin.ir.util.classId +import org.jetbrains.kotlin.ir.util.companionObject +import org.jetbrains.kotlin.ir.util.constructors +import org.jetbrains.kotlin.ir.util.defaultType +import org.jetbrains.kotlin.ir.util.dumpKotlinLike +import org.jetbrains.kotlin.ir.util.functions +import org.jetbrains.kotlin.ir.util.getPropertyGetter +import org.jetbrains.kotlin.ir.util.isObject +import org.jetbrains.kotlin.ir.util.primaryConstructor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.types.Variance @@ -35,7 +83,7 @@ private object Stub { } private object Descriptor { - const val CALLABLE_MAP = "callableMap" + const val CALLABLES = "callables" const val FQ_NAME = "fqName" const val GET_CALLABLE = "getCallable" const val CREATE_INSTANCE = "createInstance" @@ -476,7 +524,7 @@ internal class RpcStubGenerator( generateInvokators() - generateCallableMapProperty() + generateCallablesProperty() generateGetCallableFunction() @@ -650,32 +698,37 @@ internal class RpcStubGenerator( } } - private var callableMap: IrProperty by Delegates.notNull() + private var callables: IrProperty by Delegates.notNull() /** * Callable names map. * A map that holds an RpcCallable that describes it. * * ```kotlin - * private val callableMap: Map> = mapOf( + * override val callables: Map> = mapOf( * Pair("", RpcCallable(...)), * ... * Pair("", RpcCallable(...)), * ) * * // when n=0: - * private val callableMap: Map> = emptyMap() + * private val callables: Map> = emptyMap() * ``` * * Where: * - `` - the name of the k-th callable in the service */ - private fun IrClass.generateCallableMapProperty() { - callableMap = addProperty { - name = Name.identifier(Descriptor.CALLABLE_MAP) + private fun IrClass.generateCallablesProperty() { + val interfaceProperty = ctx.rpcServiceDescriptor.findPropertyByName(Descriptor.CALLABLES) + ?: error("Expected RpcServiceDescriptor.callables property to exist") + + callables = addProperty { + name = Name.identifier(Descriptor.CALLABLES) visibility = DescriptorVisibilities.PRIVATE modality = Modality.FINAL }.apply { + overriddenSymbols = listOf(interfaceProperty) + val rpcCallableType = ctx.rpcCallable.typeWith(declaration.serviceType) val mapType = ctx.irBuiltIns.mapClass.typeWith(ctx.irBuiltIns.stringType, rpcCallableType) @@ -698,8 +751,10 @@ internal class RpcStubGenerator( ) } - addDefaultGetter(this@generateCallableMapProperty, ctx.irBuiltIns) { - visibility = DescriptorVisibilities.PRIVATE + addDefaultGetter(this@generateCallablesProperty, ctx.irBuiltIns) { + visibility = + DescriptorVisibilities.PUBLIC + overriddenSymbols = listOf(ctx.rpcServiceDescriptor.getPropertyGetter(Descriptor.CALLABLES)!!) } } } @@ -887,11 +942,11 @@ internal class RpcStubGenerator( } /** - * Accessor function for the `callableMap` property + * Accessor function for the `callables` property * Defined in `RpcServiceDescriptor` * * ```kotlin - * final override fun getCallable(name: String): RpcCallable? = callableMap[name] + * final override fun getCallable(name: String): RpcCallable? = callables[name] * ``` */ private fun IrClass.generateGetCallableFunction() { @@ -926,7 +981,7 @@ internal class RpcStubGenerator( arguments { dispatchReceiver = irCallProperty( clazz = this@generateGetCallableFunction, - property = callableMap, + property = callables, symbol = functionThisReceiver.symbol, ) diff --git a/core/api/core.api b/core/api/core.api index f9064281a..41e0be7c3 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -55,6 +55,7 @@ public abstract interface class kotlinx/rpc/descriptor/RpcParameter { public abstract interface class kotlinx/rpc/descriptor/RpcServiceDescriptor { public abstract fun createInstance (JLkotlinx/rpc/RpcClient;)Ljava/lang/Object; public abstract fun getCallable (Ljava/lang/String;)Lkotlinx/rpc/descriptor/RpcCallable; + public abstract fun getCallableMap ()Ljava/util/Map; public abstract fun getFqName ()Ljava/lang/String; } diff --git a/core/api/core.klib.api b/core/api/core.klib.api index 4af66af8d..f553e289b 100644 --- a/core/api/core.klib.api +++ b/core/api/core.klib.api @@ -28,6 +28,8 @@ abstract interface <#A: kotlin/Any> kotlinx.rpc.descriptor/RpcCallable { // kotl } abstract interface <#A: kotlin/Any> kotlinx.rpc.descriptor/RpcServiceDescriptor { // kotlinx.rpc.descriptor/RpcServiceDescriptor|null[0] + abstract val callableMap // kotlinx.rpc.descriptor/RpcServiceDescriptor.callableMap|{}callableMap[0] + abstract fun (): kotlin.collections/Map> // kotlinx.rpc.descriptor/RpcServiceDescriptor.callableMap.|(){}[0] abstract val fqName // kotlinx.rpc.descriptor/RpcServiceDescriptor.fqName|{}fqName[0] abstract fun (): kotlin/String // kotlinx.rpc.descriptor/RpcServiceDescriptor.fqName.|(){}[0] diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt b/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt index 508fcb777..77dbe83f7 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt @@ -44,6 +44,8 @@ public interface RpcServiceDescriptor<@Rpc T : Any> { public fun getCallable(name: String): RpcCallable? + public val callables: Map> + public fun createInstance(serviceId: Long, client: RpcClient): T } diff --git a/tests/compiler-plugin-tests/build.gradle.kts b/tests/compiler-plugin-tests/build.gradle.kts index e60bc07d6..3f4ae80f2 100644 --- a/tests/compiler-plugin-tests/build.gradle.kts +++ b/tests/compiler-plugin-tests/build.gradle.kts @@ -2,7 +2,7 @@ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ -import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode +import org.jetbrains.kotlin.gradle.dsl.* import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -110,6 +110,12 @@ tasks.test { dependsOn(project(":core").tasks.getByName("jvmJar")) dependsOn(project(":utils").tasks.getByName("jvmJar")) dependsOn(project(":krpc:krpc-core").tasks.getByName("jvmJar")) + dependsOn("generateTests") + + inputs.dir("src/testData") + .ignoreEmptyDirectories() + .normalizeLineEndings() + .withPathSensitivity(PathSensitivity.RELATIVE) useJUnitPlatform() diff --git a/tests/compiler-plugin-tests/src/test-gen/kotlinx/rpc/codegen/test/runners/BoxTestGenerated.java b/tests/compiler-plugin-tests/src/test-gen/kotlinx/rpc/codegen/test/runners/BoxTestGenerated.java index b204c706c..fb2806788 100644 --- a/tests/compiler-plugin-tests/src/test-gen/kotlinx/rpc/codegen/test/runners/BoxTestGenerated.java +++ b/tests/compiler-plugin-tests/src/test-gen/kotlinx/rpc/codegen/test/runners/BoxTestGenerated.java @@ -39,6 +39,12 @@ public void testMultiModule() { runTest("src/testData/box/multiModule.kt"); } + @Test + @TestMetadata("serviceDescriptor.kt") + public void testServiceDescriptor() { + runTest("src/testData/box/serviceDescriptor.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() { 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 0338820c5..ac9a406a7 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 @@ -179,8 +179,10 @@ FILE fqName: fileName:/customParameterTypes.kt RETURN type=kotlin.Nothing from='private final fun (): kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> declared in .BoxService.$rpcServiceStub.Companion' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test2Invokator type:kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> visibility:private [final]' type=kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> origin=null receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null - PROPERTY name:callableMap visibility:private modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:callableMap type:kotlin.collections.Map.BoxService>> visibility:private [final] + PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract callables: kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final] EXPRESSION_BODY CALL 'public final fun mapOf (vararg pairs: kotlin.Pair): kotlin.collections.Map declared in kotlin.collections' type=kotlin.collections.Map.BoxService>> origin=null TYPE_ARG K: kotlin.String @@ -242,13 +244,15 @@ FILE fqName: fileName:/customParameterTypes.kt ARG annotations: CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null TYPE_ARG T: ARG isNonSuspendFunction: CONST Boolean type=kotlin.Boolean value=false - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL returnType:kotlin.collections.Map.BoxService>> + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL returnType:kotlin.collections.Map.BoxService>> VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion - correspondingProperty: PROPERTY name:callableMap visibility:private modality:FINAL [val] + correspondingProperty: PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract fun (): kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor BLOCK_BODY - RETURN type=kotlin.Nothing from='private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callableMap type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null - receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null CONSTRUCTOR visibility:private returnType:.BoxService.$rpcServiceStub.Companion [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' @@ -285,7 +289,7 @@ FILE fqName: fileName:/customParameterTypes.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun getCallable (name: kotlin.String): kotlinx.rpc.descriptor.RpcCallable? declared in .BoxService.$rpcServiceStub.Companion' CALL 'public abstract fun get (key: K of kotlin.collections.Map): V of kotlin.collections.Map? declared in kotlin.collections.Map' type=kotlinx.rpc.descriptor.RpcCallable? origin=GET_ARRAY_ELEMENT - ARG : CALL 'private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY + ARG : CALL 'public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY ARG : GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null ARG key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null CONSTRUCTOR visibility:public returnType:.BoxService.$rpcServiceStub [primary] 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 dddf10549..2b321702c 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 @@ -67,8 +67,10 @@ FILE fqName: fileName:/flowParameter.kt RETURN type=kotlin.Nothing from='private final fun (): kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> declared in .BoxService.$rpcServiceStub.Companion' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:streamInvokator type:kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> visibility:private [final]' type=kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> origin=null receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null - PROPERTY name:callableMap visibility:private modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:callableMap type:kotlin.collections.Map.BoxService>> visibility:private [final] + PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract callables: kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final] EXPRESSION_BODY CALL 'public final fun mapOf (vararg pairs: kotlin.Pair): kotlin.collections.Map declared in kotlin.collections' type=kotlin.collections.Map.BoxService>> origin=null TYPE_ARG K: kotlin.String @@ -102,13 +104,15 @@ FILE fqName: fileName:/flowParameter.kt ARG annotations: CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null TYPE_ARG T: ARG isNonSuspendFunction: CONST Boolean type=kotlin.Boolean value=false - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL returnType:kotlin.collections.Map.BoxService>> + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL returnType:kotlin.collections.Map.BoxService>> VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion - correspondingProperty: PROPERTY name:callableMap visibility:private modality:FINAL [val] + correspondingProperty: PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract fun (): kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor BLOCK_BODY - RETURN type=kotlin.Nothing from='private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callableMap type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null - receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null CONSTRUCTOR visibility:private returnType:.BoxService.$rpcServiceStub.Companion [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' @@ -145,7 +149,7 @@ FILE fqName: fileName:/flowParameter.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun getCallable (name: kotlin.String): kotlinx.rpc.descriptor.RpcCallable? declared in .BoxService.$rpcServiceStub.Companion' CALL 'public abstract fun get (key: K of kotlin.collections.Map): V of kotlin.collections.Map? declared in kotlin.collections.Map' type=kotlinx.rpc.descriptor.RpcCallable? origin=GET_ARRAY_ELEMENT - ARG : CALL 'private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY + ARG : CALL 'public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY ARG : GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null ARG key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null CONSTRUCTOR visibility:public returnType:.BoxService.$rpcServiceStub [primary] 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 ec1d44f3a..7c7ceb064 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 @@ -64,8 +64,10 @@ FILE fqName: fileName:/module_lib_multiModule.kt RETURN type=kotlin.Nothing from='private final fun (): kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> declared in .BoxService.$rpcServiceStub.Companion' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:simpleInvokator type:kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> visibility:private [final]' type=kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> origin=null receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null - PROPERTY name:callableMap visibility:private modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:callableMap type:kotlin.collections.Map.BoxService>> visibility:private [final] + PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract callables: kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final] EXPRESSION_BODY CALL 'public final fun mapOf (vararg pairs: kotlin.Pair): kotlin.collections.Map declared in kotlin.collections' type=kotlin.collections.Map.BoxService>> origin=null TYPE_ARG K: kotlin.String @@ -88,13 +90,15 @@ FILE fqName: fileName:/module_lib_multiModule.kt ARG parameters: CALL 'public final fun emptyArray (): kotlin.Array declared in kotlin' type=kotlin.Array origin=null TYPE_ARG T: kotlinx.rpc.descriptor.RpcParameter ARG isNonSuspendFunction: CONST Boolean type=kotlin.Boolean value=false - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL returnType:kotlin.collections.Map.BoxService>> + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL returnType:kotlin.collections.Map.BoxService>> VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion - correspondingProperty: PROPERTY name:callableMap visibility:private modality:FINAL [val] + correspondingProperty: PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract fun (): kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor BLOCK_BODY - RETURN type=kotlin.Nothing from='private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callableMap type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null - receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null CONSTRUCTOR visibility:private returnType:.BoxService.$rpcServiceStub.Companion [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' @@ -131,7 +135,7 @@ FILE fqName: fileName:/module_lib_multiModule.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun getCallable (name: kotlin.String): kotlinx.rpc.descriptor.RpcCallable? declared in .BoxService.$rpcServiceStub.Companion' CALL 'public abstract fun get (key: K of kotlin.collections.Map): V of kotlin.collections.Map? declared in kotlin.collections.Map' type=kotlinx.rpc.descriptor.RpcCallable? origin=GET_ARRAY_ELEMENT - ARG : CALL 'private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY + ARG : CALL 'public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY ARG : GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null ARG key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null CONSTRUCTOR visibility:public returnType:.BoxService.$rpcServiceStub [primary] diff --git a/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.fir.ir.txt new file mode 100644 index 000000000..5034d93e6 --- /dev/null +++ b/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.fir.ir.txt @@ -0,0 +1,234 @@ +FILE fqName: fileName:/serviceDescriptor.kt + CLASS INTERFACE name:BoxService modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + annotations: + Rpc + thisReceiver: VALUE_PARAMETER INSTANCE_RECEIVER kind:DispatchReceiver name: type:.BoxService + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[.BoxService] + thisReceiver: VALUE_PARAMETER INSTANCE_RECEIVER kind:DispatchReceiver name: type:.BoxService.$rpcServiceStub + PROPERTY name:__rpc_stub_id visibility:private modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:__rpc_stub_id type:kotlin.Long visibility:private [final] + EXPRESSION_BODY + GET_VAR '__rpc_stub_id: kotlin.Long declared in .BoxService.$rpcServiceStub.' type=kotlin.Long origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL returnType:kotlin.Long + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub + correspondingProperty: PROPERTY name:__rpc_stub_id visibility:private modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun (): kotlin.Long declared in .BoxService.$rpcServiceStub' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:__rpc_stub_id type:kotlin.Long visibility:private [final]' type=kotlin.Long origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub declared in .BoxService.$rpcServiceStub.' type=.BoxService.$rpcServiceStub origin=null + PROPERTY name:__rpc_client visibility:private modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:__rpc_client type:kotlinx.rpc.RpcClient visibility:private [final] + EXPRESSION_BODY + GET_VAR '__rpc_client: kotlinx.rpc.RpcClient declared in .BoxService.$rpcServiceStub.' type=kotlinx.rpc.RpcClient origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL returnType:kotlinx.rpc.RpcClient + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub + correspondingProperty: PROPERTY name:__rpc_client visibility:private modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun (): kotlinx.rpc.RpcClient declared in .BoxService.$rpcServiceStub' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:__rpc_client type:kotlinx.rpc.RpcClient visibility:private [final]' type=kotlinx.rpc.RpcClient origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub declared in .BoxService.$rpcServiceStub.' type=.BoxService.$rpcServiceStub origin=null + CLASS GENERATED[kotlinx.rpc.codegen.FirRpcServiceStubCompanionObject] OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlinx.rpc.descriptor.RpcServiceDescriptor<.BoxService>] + thisReceiver: VALUE_PARAMETER INSTANCE_RECEIVER kind:DispatchReceiver name: type:.BoxService.$rpcServiceStub.Companion + PROPERTY name:fqName visibility:public modality:FINAL [val] + overridden: + public abstract fqName: kotlin.String declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FIELD PROPERTY_BACKING_FIELD name:fqName type:kotlin.String visibility:private [final] + EXPRESSION_BODY + CONST String type=kotlin.String value="BoxService" + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL returnType:kotlin.String + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion + correspondingProperty: PROPERTY name:fqName visibility:public modality:FINAL [val] + overridden: + public abstract fun (): kotlin.String declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .BoxService.$rpcServiceStub.Companion' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:fqName type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null + PROPERTY name:simpleInvokator visibility:private modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:simpleInvokator type:kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> visibility:private [final] + EXPRESSION_BODY + TYPE_OP type=kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> origin=SAM_CONVERSION typeOperand=kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> + FUN_EXPR type=kotlin.coroutines.SuspendFunction2<.BoxService, kotlin.Any?, kotlin.Any?> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.Any? [suspend] + VALUE_PARAMETER kind:Regular name:service index:0 type:.BoxService + VALUE_PARAMETER kind:Regular name:parameters index:1 type:kotlin.Array + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (service: .BoxService, parameters: kotlin.Array): kotlin.Any? declared in .BoxService.$rpcServiceStub.Companion.simpleInvokator' + CALL 'public abstract fun simple (): kotlin.String declared in .BoxService' type=kotlin.String origin=null + ARG : GET_VAR 'service: .BoxService declared in .BoxService.$rpcServiceStub.Companion.simpleInvokator.' type=.BoxService origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL returnType:kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion + correspondingProperty: PROPERTY name:simpleInvokator visibility:private modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun (): kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> declared in .BoxService.$rpcServiceStub.Companion' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:simpleInvokator type:kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> visibility:private [final]' type=kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null + PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract callables: kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final] + EXPRESSION_BODY + CALL 'public final fun mapOf (vararg pairs: kotlin.Pair): kotlin.collections.Map declared in kotlin.collections' type=kotlin.collections.Map.BoxService>> origin=null + TYPE_ARG K: kotlin.String + TYPE_ARG V: kotlinx.rpc.descriptor.RpcCallable<.BoxService> + ARG pairs: VARARG type=kotlin.Array.BoxService>>> varargElementType=kotlin.Pair.BoxService>> + CALL 'public final fun to (: A of kotlin.to, that: B of kotlin.to): kotlin.Pair declared in kotlin' type=kotlin.Pair.BoxService>> origin=null + TYPE_ARG A: kotlin.String + TYPE_ARG B: kotlinx.rpc.descriptor.RpcCallable<.BoxService> + ARG : CONST String type=kotlin.String value="simple" + ARG that: CONSTRUCTOR_CALL 'public constructor (name: kotlin.String, returnType: kotlinx.rpc.descriptor.RpcType, invokator: kotlinx.rpc.descriptor.RpcInvokator, parameters: kotlin.Array, isNonSuspendFunction: kotlin.Boolean) declared in kotlinx.rpc.descriptor.RpcCallableDefault' type=kotlinx.rpc.descriptor.RpcCallable<.BoxService> origin=null + TYPE_ARG T: .BoxService + ARG name: CONST String type=kotlin.String value="simple" + ARG returnType: CONSTRUCTOR_CALL 'public constructor (kType: kotlin.reflect.KType, annotations: kotlin.collections.List) declared in kotlinx.rpc.descriptor.RpcTypeDefault' type=kotlinx.rpc.descriptor.RpcType origin=null + ARG kType: CALL 'public final fun typeOf (): kotlin.reflect.KType declared in kotlin.reflect' type=kotlin.reflect.KType origin=null + TYPE_ARG T: kotlin.String + ARG annotations: CALL 'public final fun emptyList (): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null + TYPE_ARG T: + ARG invokator: CALL 'private final fun (): kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> declared in .BoxService.$rpcServiceStub.Companion' type=kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> origin=GET_PROPERTY + ARG : GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion' type=.BoxService.$rpcServiceStub.Companion origin=null + ARG parameters: CALL 'public final fun emptyArray (): kotlin.Array declared in kotlin' type=kotlin.Array origin=null + TYPE_ARG T: kotlinx.rpc.descriptor.RpcParameter + ARG isNonSuspendFunction: CONST Boolean type=kotlin.Boolean value=false + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL returnType:kotlin.collections.Map.BoxService>> + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion + correspondingProperty: PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract fun (): kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null + CONSTRUCTOR visibility:private returnType:.BoxService.$rpcServiceStub.Companion [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.FirRpcServiceStubCompanionObject] OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlinx.rpc.descriptor.RpcServiceDescriptor<.BoxService>]' type=kotlin.Unit + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN returnType:kotlin.Boolean [fake_override,operator] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + VALUE_PARAMETER kind:Regular name:other index:1 type:kotlin.Any? + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN returnType:kotlin.Int [fake_override] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + overridden: + public open fun hashCode (): kotlin.Int declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN returnType:kotlin.String [fake_override] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + overridden: + public open fun toString (): kotlin.String declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FUN name:createInstance visibility:public modality:OPEN returnType:.BoxService + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion + VALUE_PARAMETER kind:Regular name:serviceId index:1 type:kotlin.Long + VALUE_PARAMETER kind:Regular name:client index:2 type:kotlinx.rpc.RpcClient + overridden: + public abstract fun createInstance (serviceId: kotlin.Long, client: kotlinx.rpc.RpcClient): T of kotlinx.rpc.descriptor.RpcServiceDescriptor declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun createInstance (serviceId: kotlin.Long, client: kotlinx.rpc.RpcClient): .BoxService declared in .BoxService.$rpcServiceStub.Companion' + CONSTRUCTOR_CALL 'public constructor (__rpc_stub_id: kotlin.Long, __rpc_client: kotlinx.rpc.RpcClient) declared in .BoxService.$rpcServiceStub' type=.BoxService.$rpcServiceStub origin=null + ARG __rpc_stub_id: GET_VAR 'serviceId: kotlin.Long declared in .BoxService.$rpcServiceStub.Companion.createInstance' type=kotlin.Long origin=null + ARG __rpc_client: GET_VAR 'client: kotlinx.rpc.RpcClient declared in .BoxService.$rpcServiceStub.Companion.createInstance' type=kotlinx.rpc.RpcClient origin=null + FUN name:getCallable visibility:public modality:OPEN returnType:kotlinx.rpc.descriptor.RpcCallable? + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion + VALUE_PARAMETER kind:Regular name:name index:1 type:kotlin.String + overridden: + public abstract fun getCallable (name: kotlin.String): kotlinx.rpc.descriptor.RpcCallable? declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun getCallable (name: kotlin.String): kotlinx.rpc.descriptor.RpcCallable? declared in .BoxService.$rpcServiceStub.Companion' + CALL 'public abstract fun get (key: K of kotlin.collections.Map): V of kotlin.collections.Map? declared in kotlin.collections.Map' type=kotlinx.rpc.descriptor.RpcCallable? origin=GET_ARRAY_ELEMENT + ARG : CALL 'public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY + ARG : GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null + ARG key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null + CONSTRUCTOR visibility:public returnType:.BoxService.$rpcServiceStub [primary] + VALUE_PARAMETER kind:Regular name:__rpc_stub_id index:0 type:kotlin.Long + VALUE_PARAMETER kind:Regular name:__rpc_client index:1 type:kotlinx.rpc.RpcClient + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[.BoxService]' type=kotlin.Unit + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN returnType:kotlin.Boolean [fake_override,operator] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + VALUE_PARAMETER kind:Regular name:other index:1 type:kotlin.Any? + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .BoxService + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN returnType:kotlin.Int [fake_override] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + overridden: + public open fun hashCode (): kotlin.Int declared in .BoxService + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN returnType:kotlin.String [fake_override] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + overridden: + public open fun toString (): kotlin.String declared in .BoxService + FUN name:simple visibility:public modality:OPEN returnType:kotlin.String [suspend] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub + overridden: + public abstract fun simple (): kotlin.String declared in .BoxService + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun simple (): kotlin.String declared in .BoxService.$rpcServiceStub' + CALL 'public abstract fun call (call: kotlinx.rpc.RpcCall): T of kotlinx.rpc.RpcClient.call declared in kotlinx.rpc.RpcClient' type=kotlin.String origin=null + TYPE_ARG T: kotlin.String + ARG : CALL 'private final fun (): kotlinx.rpc.RpcClient declared in .BoxService.$rpcServiceStub' type=kotlinx.rpc.RpcClient origin=GET_PROPERTY + ARG : GET_VAR ': .BoxService.$rpcServiceStub declared in .BoxService.$rpcServiceStub.simple' type=.BoxService.$rpcServiceStub origin=null + ARG call: CONSTRUCTOR_CALL 'public constructor (descriptor: kotlinx.rpc.descriptor.RpcServiceDescriptor<*>, callableName: kotlin.String, parameters: kotlin.Array, serviceId: kotlin.Long) declared in kotlinx.rpc.RpcCall' type=kotlinx.rpc.RpcCall origin=null + ARG descriptor: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.FirRpcServiceStubCompanionObject] OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlinx.rpc.descriptor.RpcServiceDescriptor<.BoxService>]' type=.BoxService.$rpcServiceStub.Companion + ARG callableName: CONST String type=kotlin.String value="simple" + ARG parameters: CALL 'public final fun emptyArray (): kotlin.Array declared in kotlin' type=kotlin.Array origin=null + TYPE_ARG T: kotlin.Any? + ARG serviceId: CALL 'private final fun (): kotlin.Long declared in .BoxService.$rpcServiceStub' type=kotlin.Long origin=GET_PROPERTY + ARG : GET_VAR ': .BoxService.$rpcServiceStub declared in .BoxService.$rpcServiceStub.simple' type=.BoxService.$rpcServiceStub origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN returnType:kotlin.Boolean [fake_override,operator] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + VALUE_PARAMETER kind:Regular name:other index:1 type:kotlin.Any? + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN returnType:kotlin.Int [fake_override] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN returnType:kotlin.String [fake_override] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:kotlin.Any + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + FUN name:simple visibility:public modality:ABSTRACT returnType:kotlin.String [suspend] + VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService + FUN name:box visibility:public modality:FINAL returnType:kotlin.String + annotations: + OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalRpcApi modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass] type=kotlin.Array> varargElementType=kotlin.reflect.KClass) + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CALL 'public final fun runBlocking (context: kotlin.coroutines.CoroutineContext, block: @[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1): T of kotlinx.coroutines.runBlocking declared in kotlinx.coroutines' type=kotlin.String origin=null + TYPE_ARG T: kotlin.String + ARG block: FUN_EXPR type=@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL returnType:kotlin.String [suspend] + VALUE_PARAMETER kind:ExtensionReceiver name:$this$runBlocking index:0 type:kotlinx.coroutines.CoroutineScope + BLOCK_BODY + VAR name:descriptor type:kotlinx.rpc.descriptor.RpcServiceDescriptor<.BoxService> [val] + CALL 'public final fun serviceDescriptorOf (): kotlinx.rpc.descriptor.RpcServiceDescriptor declared in kotlinx.rpc.descriptor' type=kotlinx.rpc.descriptor.RpcServiceDescriptor<.BoxService> origin=null + TYPE_ARG T: .BoxService + VAR name:result type:kotlin.String? [val] + BLOCK type=kotlin.String? origin=SAFE_CALL + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlinx.rpc.descriptor.RpcCallable<.BoxService>? [val] + CALL 'public abstract fun get (key: K of kotlin.collections.Map): V of kotlin.collections.Map? declared in kotlin.collections.Map' type=kotlinx.rpc.descriptor.RpcCallable<.BoxService>? origin=GET_ARRAY_ELEMENT + ARG : CALL 'public abstract fun (): kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY + ARG : GET_VAR 'val descriptor: kotlinx.rpc.descriptor.RpcServiceDescriptor<.BoxService> declared in .box.' type=kotlinx.rpc.descriptor.RpcServiceDescriptor<.BoxService> origin=null + ARG key: CONST String type=kotlin.String value="simple" + WHEN type=kotlin.String? origin=null + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + ARG arg0: GET_VAR 'val tmp_0: kotlinx.rpc.descriptor.RpcCallable<.BoxService>? declared in .box.' type=kotlinx.rpc.descriptor.RpcCallable<.BoxService>? origin=null + ARG arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Null type=kotlin.Nothing? value=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public abstract fun (): kotlin.String declared in kotlinx.rpc.descriptor.RpcCallable' type=kotlin.String origin=GET_PROPERTY + ARG : TYPE_OP type=kotlinx.rpc.descriptor.RpcCallable<.BoxService> origin=IMPLICIT_CAST typeOperand=kotlinx.rpc.descriptor.RpcCallable<.BoxService> + GET_VAR 'val tmp_0: kotlinx.rpc.descriptor.RpcCallable<.BoxService>? declared in .box.' type=kotlinx.rpc.descriptor.RpcCallable<.BoxService>? origin=null + RETURN type=kotlin.Nothing from='local final fun ($this$runBlocking: kotlinx.coroutines.CoroutineScope): kotlin.String declared in .box' + WHEN type=kotlin.String origin=IF + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + ARG arg0: GET_VAR 'val result: kotlin.String? declared in .box.' type=kotlin.String? origin=null + ARG arg1: CONST String type=kotlin.String value="simple" + then: CONST String type=kotlin.String value="OK" + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value="Fail: " + GET_VAR 'val result: kotlin.String? declared in .box.' type=kotlin.String? origin=null diff --git a/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.fir.txt b/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.fir.txt new file mode 100644 index 000000000..397e57a6e --- /dev/null +++ b/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.fir.txt @@ -0,0 +1,27 @@ +FILE: serviceDescriptor.kt + @R|kotlinx/rpc/annotations/Rpc|() public abstract interface BoxService : R|kotlin/Any| { + public abstract suspend fun simple(): R|kotlin/String| + + public final class $rpcServiceStub : R|kotlin/Any| { + public final companion object Companion : R|kotlin/Any| { + } + + } + + } + @R|kotlin/OptIn|(markerClass = vararg((Q|kotlinx/rpc/internal/utils/ExperimentalRpcApi|))) public final fun box(): R|kotlin/String| { + ^box R|kotlinx/coroutines/runBlocking|( = runBlocking@fun R|kotlinx/coroutines/CoroutineScope|.(): R|kotlin/String| { + lval descriptor: R|kotlinx/rpc/descriptor/RpcServiceDescriptor| = R|kotlinx/rpc/descriptor/serviceDescriptorOf|() + lval result: R|kotlin/String?| = R|/descriptor|.R|SubstitutionOverride>|>|.R|SubstitutionOverride?|>|(String(simple))?.{ $subj$.R|SubstitutionOverride| } + ^ when () { + ==(R|/result|, String(simple)) -> { + String(OK) + } + else -> { + (String(Fail: ), R|/result|) + } + } + + } + ) + } diff --git a/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.kt b/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.kt new file mode 100644 index 000000000..dd968d47e --- /dev/null +++ b/tests/compiler-plugin-tests/src/testData/box/serviceDescriptor.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +// RUN_PIPELINE_TILL: BACKEND + +import kotlinx.coroutines.runBlocking +import kotlinx.rpc.descriptor.serviceDescriptorOf +import kotlinx.rpc.annotations.Rpc +import kotlinx.rpc.codegen.test.TestRpcClient +import kotlinx.rpc.internal.utils.ExperimentalRpcApi + +@Rpc +interface BoxService { + suspend fun simple(): String +} + +@OptIn(ExperimentalRpcApi::class) +fun box(): String = runBlocking { + val descriptor = serviceDescriptorOf() + val result = descriptor.callables["simple"]?.name + + if (result == "simple") "OK" else "Fail: $result" +} + +/* GENERATED_FIR_TAGS: functionDeclaration, interfaceDeclaration, suspend */ 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 51f86a21b..e055f3192 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 @@ -63,8 +63,10 @@ FILE fqName: fileName:/simple.kt RETURN type=kotlin.Nothing from='private final fun (): kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> declared in .BoxService.$rpcServiceStub.Companion' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:simpleInvokator type:kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> visibility:private [final]' type=kotlinx.rpc.descriptor.RpcInvokator.Method<.BoxService> origin=null receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null - PROPERTY name:callableMap visibility:private modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:callableMap type:kotlin.collections.Map.BoxService>> visibility:private [final] + PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract callables: kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor + FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final] EXPRESSION_BODY CALL 'public final fun mapOf (vararg pairs: kotlin.Pair): kotlin.collections.Map declared in kotlin.collections' type=kotlin.collections.Map.BoxService>> origin=null TYPE_ARG K: kotlin.String @@ -87,13 +89,15 @@ FILE fqName: fileName:/simple.kt ARG parameters: CALL 'public final fun emptyArray (): kotlin.Array declared in kotlin' type=kotlin.Array origin=null TYPE_ARG T: kotlinx.rpc.descriptor.RpcParameter ARG isNonSuspendFunction: CONST Boolean type=kotlin.Boolean value=false - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL returnType:kotlin.collections.Map.BoxService>> + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL returnType:kotlin.collections.Map.BoxService>> VALUE_PARAMETER kind:DispatchReceiver name: index:0 type:.BoxService.$rpcServiceStub.Companion - correspondingProperty: PROPERTY name:callableMap visibility:private modality:FINAL [val] + correspondingProperty: PROPERTY name:callables visibility:private modality:FINAL [val] + overridden: + public abstract fun (): kotlin.collections.Map> declared in kotlinx.rpc.descriptor.RpcServiceDescriptor BLOCK_BODY - RETURN type=kotlin.Nothing from='private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callableMap type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null - receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:callables type:kotlin.collections.Map.BoxService>> visibility:private [final]' type=kotlin.collections.Map.BoxService>> origin=null + receiver: GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.' type=.BoxService.$rpcServiceStub.Companion origin=null CONSTRUCTOR visibility:private returnType:.BoxService.$rpcServiceStub.Companion [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' @@ -130,7 +134,7 @@ FILE fqName: fileName:/simple.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun getCallable (name: kotlin.String): kotlinx.rpc.descriptor.RpcCallable? declared in .BoxService.$rpcServiceStub.Companion' CALL 'public abstract fun get (key: K of kotlin.collections.Map): V of kotlin.collections.Map? declared in kotlin.collections.Map' type=kotlinx.rpc.descriptor.RpcCallable? origin=GET_ARRAY_ELEMENT - ARG : CALL 'private final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY + ARG : CALL 'public final fun (): kotlin.collections.Map.BoxService>> declared in .BoxService.$rpcServiceStub.Companion' type=kotlin.collections.Map.BoxService>> origin=GET_PROPERTY ARG : GET_VAR ': .BoxService.$rpcServiceStub.Companion declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=.BoxService.$rpcServiceStub.Companion origin=null ARG key: GET_VAR 'name: kotlin.String declared in .BoxService.$rpcServiceStub.Companion.getCallable' type=kotlin.String origin=null CONSTRUCTOR visibility:public returnType:.BoxService.$rpcServiceStub [primary]