I saw parcelize has a new <commit> of FIR. I still...
# compiler
c
I saw parcelize has a new commit of FIR. I still don’t quite understand the difference between FIR and IR. Who can solve my doubts? In addition, does the plugin implemented with Fir need to open
useFir
in Gradle before it can be used?
d
FIR -- is new compiler frontend (backend) IR -- are new compiler backends (stable for JVM, experimental for JS and Native) FIR version of parcelize is just proof of concept for FIR compiler API and it's not ready for production use (as FIR itslef). Also there is no way to register FIR plugin using compiler arguments yet, so you can not try it outside compiler tests
c
Thank you for your answer. In fact, I’m a little confused about the front end and back end in Kotlin compiler: does FIR belong to the IDE level, and the IR belongs to compile time (bytecode) level?
d
Frontend and backed are both parts of whole compiler and represents different parts of compiler pipeline. Frontend takes source code as input and performs full analysis over it (parsing, resolution of function calls, type inference, diagnostic reporting, etc) and then gives results of this analysis to backend, which generates platform (bytecode, js, native, klib) code For detailed explanation I recommend you to watch talk about compiler from recent kotlin event:

https://www.youtube.com/watch?v=db19VFLZqJM

And yes, frontend is reused by IDE to calculate all analysis results
c
I’m very interested in this! Inspired by serialization, I tried to write IR plugin myself, but it is separated from IDEA, which means I need to write IR (CodeGeneration) and PSI (Checker...) at the same time, if I am not mistaken, maybe there will be no such problem in FIR?
Yes, I watched this video, something to look forward to. Will it be public and allow people to develop Kotlin’s extensions based on it in the future?
d
I tried to write IR plugin myself, but it is separated from IDEA
If you want to access generated declarations right from the module which they are declared then you still need to implement it in frontend and backend. But in FIR API we improved this mechanism, so you will really generate declarations on frontend and then just fill their bodies in backend (IR). In current frontend you need to generate synthetic descriptors on frontend, generate independent declarations in IR and then update all references to those declarations in whole codebase, which is really annoying Also FIR plugin API is meant to be IDE friendly in work in IDE out of box without any additional work (you just enable compiler plugin in gradle, and IDE provide correct highlighting, completion and all other stuff on the fly. This part of FIR IDE plugin is under development right now and it's already shows very impressive results
Will it be public and allow people to develop Kotlin’s extensions based on it in the future?
Yes, of course. We plan to release preview version of FIR API alongside with FIR itself. We hope it will be released with Kotlin 1.7.0
🦠 8
c
In current frontend you need to generate synthetic descriptors on frontend, generate independent declarations in IR and then update all references to those declarations in whole codebase, which is really annoying
Totally agree!
Thank you for your detailed answers. This has solved many of my questions cheers, just want to wait for it to come, hahahaha.
👌 2