Newby question: why was kotlinx.serialization desi...
# getting-started
o
Newby question: why was kotlinx.serialization designed as a compiler plugin rather than an annotation processor?
d
Annotation processors are: • Limited to the JVM platform • Limited to only generating new classes instead of modifying existing ones
o
Are annotation processors really limited to the JVM even if you generate Kotlin code rather than Java code?
d
Yes. Annotation processors are a
javac
feature, not a
kotlinc
feature
kapt
(the thing that makes annotation processing work for Kotlin at all) is basically a giant hack.
It has to generate Java-stubs for all Kotlin classes so that
javac
can deal with them at all and run the annotation processors on them.
o
I see. And this hack somehow invokes javac?
Ah. Having to write bytecode+llvm emmiters seems a bit of a steep cost (which if I understood correctly you have to pau when writing a compiler plugin). Is there a reason why annotation processing isn't made first class in kotlinc? (multiplatform etc.)
d
Because the API is fundamentally tied to Java, emitting Java classes and/or Java bytecode.
But a true Kotlin compiler plugin API is apparently planned.
🙂 3
There is one already (which is what the serialization plugin uses), but it requires separate code for all targets and it's not documented at all
And not API-stable
o
Thanks for answering all my questions!
Actually one more: is there any forums where the design of the stable compiler plugin API is being discussed?
d
I haven't seen any public discussion about how it will look, no. Just "it will come".
r
I believe the #compose team is working closely with the Kotlin team on this, so you could try asking there.
r
You can also be interested in looking at https://github.com/Foso/MpApt project. It contains a lot of info about Kotlin compiler plugins.
c
You can also take a look at the work the Arrow folks have been working on to simplify writing compiler plugins with Arrow Meta https://github.com/arrow-kt/arrow-meta
o
Thank you all for these pointers!