So I was looking at <this slideshow> from KotlinCo...
# getting-started
s
So I was looking at this slideshow from KotlinConf'2018 about how to write Kotlin compiler plugins, and what surprised me is that a big part of the process is generating JVM bytecode / LLVM IR directly. I've always assumed that compiler plugins are somewhat like procedural macros with access to all data from the compiler, and that you can operate at multiple levels of abstractions (e.g. modify source code, or modify/generate the ASTs from the compiler frontend, or generate bytecode directly), but this is just a naive guess. Is this still the case? Or are there now higher level constructs (especially with KMP and K2)? Just curious about this.
y
I believe that slideshow was slightly inaccurate because there actually isn't an LLVM IR generation plugin at all! Instead, that plugin actually generates Kotlin's own IR, which is a multiplatform intermediate representation of Kotlin code before it gets compiled to specific platforms
👍 1
e
there are frontend IR plugins, backend IR plugins, and backend-specific ways to hook into the generation
none of them are procedural macros but some ways of using FIR could be considered close
see https://github.com/JetBrains/kotlin/blob/master/docs/fir/fir-plugins.md for some ways you can modify or add FIR, for example
👍 1
(that's new with K2)
s
Aha, that makes a lot more sense now, thanks for all the responses!