is there a way to share arbitrary information between FIR and IR? For example - say I want to compute some information in FIR that isn't purely representable in generated code but I want to avoid recomputing in IR later. Serializing it in between is fine too!
t
toadzky
12/12/2024, 4:55 PM
i've seen plugins do things like put custom annotations on things in the FIR layer and then use them in the IR layer. that might work for what you are doing
z
Zac Sweers
12/13/2024, 7:11 PM
yeah though that requires being able to serialize the data into an annotation, was hoping for something more flexible
b
bnorm
12/16/2024, 2:21 PM
While there isn't an "official" way to share information, it is possible to access some FIR elements from IR using the
metadata
property:
Copy code
val IrClass.firClass: FirClass? get() = (metadata as? FirMetadataSource.Class)?.fir
class CustomData(...)
object CustomDataAttribute : FirDeclarationDataKey()
var FirClass.customData: CustomData? by FirDeclarationDataRegistry.data(CustomDataAttribute)
val IrClass.customData: CustomData? get() = (metadata as? FirMetadataSource.Class)?.fir?.customData
🙌 1
h
hfhbd
01/02/2025, 9:29 PM
Are there any plans to add an official api for this use-case?
b
bnorm
01/13/2025, 12:32 AM
There are no plans to remove FIR-level declaration attributes nor the IR-level metadata property, so I suspect this will become the officially recommended way, but there hasn't been any discussion on the topic. Will this pattern not work for your particular use-case or are you just curious?
h
hfhbd
01/13/2025, 6:34 AM
I did test it yet, it is planned for this week, but I was just curious.