In IR compiler/plugin code, it’s possible to gener...
# compiler
d
In IR compiler/plugin code, it’s possible to generate a call to a function via
irCall
, like how data classes have generated calls to their properties’ hashCode functions. Is it possible to generate a call to an arbitrary function that you don’t have a direct reference to, like a
kotlin-stdlib-common
function?
t
Yes, it is possible. You can check the code below for an example of looking for the function. Search for
referenceClass
. Note, that
referenceClass
is a "FIR incompatible API" whatever that means at the moment. They might change it, but I guess a similar functionality will be added as it would be nigh impossible to write the compiler without it. I'm nowhere close to a JB official, so this information is just what I've gathered by reading other plugins and the compiler code. Take it with a bit of salt. As for the call itself, it is pretty simple, just search the plugin code for
irCall
or
IrCallImpl
. Pay attention to the dispatch receivers, those are really deep rabbit holes I've fallen into again and again. https://github.com/spxbhuhb/rui/blob/2f1204101c32f952dc7e833df7acbe355ab639c2/rui-[…]n/kotlin/hu/simplexion/rui/kotlin/plugin/ir/RuiPluginContext.kt
d
There are methods in plugin context which compatible with FIR already. They take ClassId/CallableId instead of FqName
t
Ah, good to know, I'll check that out, thanks.
d
Thanks, looks like it’s working!