Just out of curioisty (I am a total compilers noob...
# python
a
Just out of curioisty (I am a total compilers noob) Is this Python Backend consuming Frontend IR?? also Is the FIR being passed through LLVM? Like other Kotlin/Native targets?? or is it own thing like the Kotlin/JS backend?
d
FIR is a frontend structure wich is independent from all backends. After frontend work is done FIR translates to backed IR which can be consumed by all backends More details here: https://kotlinlang.slack.com/archives/C7L3JB43G/p1622478266038500
👍 1
p
I also found this helpful (mostly because I prefer video form):

https://youtu.be/db19VFLZqJMâ–Ÿ

a
thank you @dmitriy.novozhilov and @Piotr KrzemiƄski However, my question was in relation to python. Sorry I forgot to point that out. Does the Kotlin/Py also use the FIR? How is the transpilation process?
p
Kotlin/Py is entirely implemented in the backend so far. In the future, to realize more advanced interop, we may want to add some frontend stuff, but it's further into the future. Our backend now works like this, really similar to what's done for JS. It's in fact a copy of JS-IR backend, with some adjustments: Kotlin code --> [processing by JS-IR frontend] --(entering Python backend)--> IR --(JS lowerings)--> lowered IR --> Python AST --> Python source code We're in the middle of cleaning up after piggy-backing on JS, e.g. we have lots of unneeded JS-specific lowerings that now make our lives harder. I'm not quite sure if this is the answer to your question, so please don't hesitate to dig deeper, I'm happy to share more 🙂 perhaps even on #python-contributors because it's more about internal stuff. This channel is meant more for people interested in just using Kotlin/Python.
now I saw your original question:
or is it own thing like the Kotlin/JS backend?
yes 🙂
a
You have fully answered my question @Piotr KrzemiƄski. Thank you so much
👍 1
d
BTW there is no such thing as "JS IR frontend". There are two common frontends (existing one and FIR) which can be used for code for all platforms and produce backend IR which can be consumed by and 3 IR based backend
🙏 3
p
What I meant is a frontend that emits IR as backend's input and is also used in JS. Does it make sense? I still don't have full grasp over data flow in practice
d
Check this nice diagram with full compiler pipeline It describes jvm compiler but you can replace asm part with js/llvm codegen for other targets https://kotlinlang.slack.com/archives/C7L3JB43G/p1617984049065300?thread_ts=1615394755.006000&cid=C7L3JB43G
p
Wow, awesome! I've been looking for exactly something like this :) thanks!
a
Thanks for the link as well, that was a good thread
l
With the new FIR, how is Java interop working? Does FIR has Java specific things inside, or is it fed Java symbols info from an "external" place relative to the new FIR?
d
Java interop in FIR works in similar way has it was in FE 1.0: java declarations are parsed from source code or .class files in some frontend-independent model, this model is converted to FIR for java declarations which is transformed to enhanced declarations, which contain types with correct nullability (flexible or not, depending of nullability annotations) and mapped java types to kotlin types (like
java.util.List
to
kotlin.collections.(Mutable)List
🙏 1
đŸ‘đŸŒ 1
l
I see, it looks like there's no barrier to having this work for the Python backend. For the "use Kotlin in Java code", I guess it works differently, can you tell how?
d
For the "use Kotlin in Java code", I guess it works differently, can you tell how?
Kotlin files are compiled before java and compiled .class files are passed to javac compile classpath However for IDE integration process is much complicated and we need to create so called "lightclasses" which represents kotlin declaration in separate java model which is used in IDEA