To generate a function, you generate the signature...
# compiler
m
To generate a function, you generate the signature in the FIR and the body in the IR, right? What about its annotations? Am I right to call
FirNamedFunction#replaceAnnotations
and supply annotations in
FirDeclarationGenerationExtension#generateFunctions
?
d
This is one way. The other way is to generate them at IR and then call
Copy code
irPluginContext
  .metadataDeclarationRegistrar
  .addMetadataVisibleAnnotationsToElement(
    irFunction,
    generatedIrAnnotations
)
Both are acceptable.
m
@dmitriy.novozhilov What are the pros and cons of each?
d
The annotations creation API in frontend is slightly simpler. Also it allows you to fully generate the declaration header and don't think of it no more. But on the backend you have access to the whole world resolved, so if your annotation have some non-trivial arguments, which depend on resolution results of some other declarations, it's possible to access it only there.
m
@dmitriy.novozhilov Thank you for the explanation. Doing it in the FIR until it’s necessary to do it in the IR seems to be the way to go, I’ll do that!
👍 1
h
It also does depend on the annotation, doesn't it? If you annotate your function that effects IR/code gen, like JvmStatic etc?
d
Nope, it doesn't. IIRC none of special compiler annotations affect fir2ir, their handling happens deeper in the backend. So it doesn't matter how you generated annotations originally, the backend will see them, because it executes after IR plugins.
🙏 1