Any FIR way to find all library methods that have ...
# compiler
y
Any FIR way to find all library methods that have a specific annotation?
FirPredicateBasedProvider
seems to only work for the files being compiled. Is there a simple way to loop over all imported library methods and filter them manually? Or would that be too costly? I can see how to find the FQNs for imported packages and methods, but then I'm not sure how to loop over their "visible" methods. I'm doing this for caching reasons, so if I accidentally get methods that aren't visible, that's still fine. In other words, I'm looking for the FIR equivalent of
module.getPackage(fqName).memberScope.getContributedDescriptors()
d
There isn't
FirPredicateBasedProvider
precaches all source declartions with annotations to provide high performance of all lookup method To support it for for declarations from dependencies it's needed to load all declarations from classpath which is too slow (deserialization of class files is one of most slow operations)
Also there is no such thing as "package" as a separate entity with scope in FIR
y
Thanks for the quick reply! That makes sense. Let's say instead I would like to ship with a compiled library a list of FqNames that represents all declarations in my library that have a specific annotation. Is there any standard way of packaging such information in a library and accessing it later in a compiler plugin used by a consumer of the library? E.g. I want to know the list of all functions annotated with
@X
so that in IR I want to replace a call to
getXByType<T>()
with a function annotated with
X
that returns
T
(so very basic DI). How can I add that list to my binary somehow so that in IR I can loop over that list of FQNs and find my desired function?
d
There is no standard way, but it's very reasonable request Can you please a YT ticket for it?
As a workaround I think it's fine to add some annotation to some declaration in library which contains all information you want (e.g. serialized with protobuf)
y
Great I'll make a YT ticket. I was thinking yeah that I can make a synthetic IR declaration with a specific FQN that has an annotation with the info in it. I don't wanna mention the dreaded subject of Incremental Compilation, but how does FirPredicateBasedProvider deal with it? Will it still have all the declarations in the module with my annotation? Or will it only give me the declarations that are being compiled right now and skip all the ones that don't need to be compiled again?
d
Unfortunately, it looks only for declaration which are actually being compiled We plan to fix it in future, but not in the nearest one Until K2 release we are focused only on thing which are needed to this release, so all fix in plugin API will be for fixing bugs with official plugins
I'll be happy to make K2 plugin stable with release of K2 itself, but it's impossible because of lack of resources in compiler team
y
Would the previously-generated synthetic IR declaration-with-annotation be accessible during IC? Because if so, then a workaround is to store that info as discussed above and then access it during IC
d
They should be available as regular binary dependencies
y
Filed! KT-54850