here’s a topic for a brainstorm: what if the Kotli...
# compiler
p
here’s a topic for a brainstorm: what if the Kotlin compiler would work not only on the JVM, but also other targets like JS or WASM? would you find use cases for this in your projects? are there any blockers for this not being possible even in a simplified form? I’m thinking about starting a KEEP on this, and before that I want to gather initial feedback about this idea
d
1. It shouldn't be a KEEP, because KEEP is used for proposing language evolution ideas, not compiler itself 2. It would be quite hard/impossible to implement, because compiler is deeply depends on some jvm-specific libraries (like
intellij-core
)
👍 1
p
yeah, for sure it would be challenging. I just started wondering if it even makes sense to go into this direction - if business needs would justify the effort
m
The use case I can see is playground: write and run your code directly in your browser, without having a compilation server. But sounds quite complicated indeed
p
for me it’s also evaluating simple expressions or config-like code in the Web frontend
h
This question pops up very often and the answer are almost the same: there are very interesting use-cases, but it will take huge effort and time to replace all jvm libraries.
But maybe! it would be not impossible to replace some parts of the compiler to Kotlin common, eg IR backend or even FIR, so you "only" need to replace the lexer, parser and the psiToFir module.
d
I think at first someone need to commonize ASM
h
and isolate other modules from Psi usage, eg https://github.com/JetBrains/kotlin/blob/v1.9.0/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBuilder.java, which is in backend (according to name) but still uses PsiElement.
d
ClassBuilder
is part of old jvm backend, so it's a subject to remove
But yeah, there is a lot of usages of PSI
b
Kotlin compiler on js/wasm would unlock interractive code snippets on doc pages like rust has (although they send it to the server for compilation). Having it work without the server would be super cool!
But I think jb mentioned somewhere that they deliberately are not bootstrapping compiler code so they can continuously test java interop while working on the compiler. In other words, compiler having some java code is desirable.
d
Having java code in compiler itself is not an issue. There were no new java classes in compiler for years We have other java+kotlin projects to test atm, like intellij ultimate
👍 1
m
But if kotlin compiler on WASM could only compile to WASM, then libraries like ASM would not be needed 🤔
💡 1