Hi! I'm very new to compiler plugins. Before imple...
# compiler
c
Hi! I'm very new to compiler plugins. Before implementing anything, I would like to know if my goal is even possible. I would like to create a compiler plugin that finds all symbols of an interface
X
. By that I mean: • I want to find all top-level properties whose getter return a subtype of
X
• I want to find all top-level functions which return a subtype of
X
• I want to find all classes that implement
X
, including objects, enums,… Is this possible? If so, what would be a general outline of how to do this? (so I know where to look to get started)
1
👀 1
d
It could be done at IR level Just traverse the whole module and check required declarations
c
In that case, only symbols from the currently-compiled module will be found, right? Not in any dependencies? (not saying it's a bad thing, just trying to understand what compiler plugins can and can't do)
d
Yep, that's right There is no way to traverse dependencies
c
And ultimately I'd like to generate some code based on what I found, but I assume I can do that at the IR level too?
d
Yes, you can
Note that these generated declarations will be invisible for the code of the module where you will generate it. You can reference them in the plugin, but user won't be able to cal them (from the same module)
p
Not sure about your specific use-case, but please pay attention to KSP. It can be easier and significantly more robust way of doing what you want to do.
1
c
Let me give more context then blob smile The
X
interface has a method that provides some information that I'd like to collect throughout the entire module. Ideally, I'd want to generate a
main
function that calls that function on all top-level
X
instances throughout the module.
p
Well, ksp mostly intended to be done by annotations, but I think lookup-ing everything is also possible. Except this it's exactly what's it intended to be used for
c
Can KSP impact warnings? I want to automatically suppress
unused
for all symbols I have been able to collect
d
There are no
UNUSED_XXX
warnings during the compilation anymore
Also warnings are reported at the FIR level before the IR, and there is no mechanism to suppress warnings from plugins
c
That's a shame. Thanks!