https://kotlinlang.org logo
#compose
Title
# compose
j

Justin Tullgren

10/10/2023, 9:42 PM
Hi, is there any way to get the new compose generated name for a composable function in ir? The compose lowering turns my composable fun into a live literal call that I can’t find using
pluginContext
. Any thoughts on how to get a reference to that function to insert it in some places in code?
s

shikasd

10/11/2023, 1:05 AM
Is your composable a lambda? We don't change names for regular composables.
j

Justin Tullgren

10/11/2023, 3:32 PM
no its a function declaration.
@Composable fun MyFun(arg: String, arg1: String): String
if I declared it as
val MyFun = @Composable { arg:String, arg1:String -> arg }
that wouldn’t change?
s

shikasd

10/11/2023, 4:04 PM
Hm, function declaration names are not changed by live literals
j

Justin Tullgren

10/11/2023, 4:07 PM
I’m getting no static method found for MyFun(arg: String, arg1: String) when i provide the method reference found from
pluginContext.referenceFunctions
. The minute I remove the
@Composable
annotation its found. I know the lowering adds the composer and dirty flags and when I look at the transformations I see a different method name. Its okay, I may have a workaround. I wanted it to be be a composable so i could use LaunchedEffect but I have another idea to remove composables entirely
s

shikasd

10/11/2023, 4:23 PM
you should be able to find it with
MyFun(arg: String, arg1: String, $composer: Composer, $changed: Int)
I think
referenceFunctions
uses fqName, so it should find it
j

Justin Tullgren

10/11/2023, 4:24 PM
thats what I was looking for but I am not sure how to find it. I am only familiar with pluginContext.referenceFunctions and its returning the signature with two args, not the one with 4 args
s

shikasd

10/11/2023, 4:26 PM
ah, if it is a different module, you should get your original function
j

Justin Tullgren

10/11/2023, 4:27 PM
Sorry I am very ignorant on what modules are. I send the same module through all of my extension visitors.
s

shikasd

10/11/2023, 4:52 PM
Usually Gradle compilation unit, (or compiler
IrModuleFragment
) You can check if the function in the same module by checking its origin, if it has
DECLARATION_STUB
, it means that what you see is a deserialized stub, which doesn't account for IR transforms.
j

Justin Tullgren

10/11/2023, 5:01 PM
ok. I pass them all through the IrGenerationExtension
Copy code
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {

        InteractionAdapter(configuration, pluginContext, logger).adapt(moduleFragment)

        CaptureAdapter(configuration, pluginContext, logger).adapt(moduleFragment)
    }
I have a working solution though so its no big but its good to know that DECLARATION_STUB information
s

shikasd

10/11/2023, 5:02 PM
it is more about how Kotlin finds them, rather than how you transform the fragment, as the function you are looking for might be in another fragment 🙂
j

Justin Tullgren

10/11/2023, 5:03 PM
okay I see what you mean. Well I have a work around. Thanks for trying!