Has anyone already tried to use IR to compile Kotl...
# compiler
k
Has anyone already tried to use IR to compile Kotlin to a different language yet?
And if so, was it to a language that oop, or to a language that is more restrictive?
d
JavaScript lol
r
@Kroppeb not sure if it helps but I’m using it to compile to a different IR expressed in lisp but not as binary target beyond JVM
k
mmh, How can I tell the compiler to just compile to IR? Cause to me it seems I have to compile to a certain target and have a plugin to create the desired extra files.
Which is annoying
g
I don't think it's supported out of the box, worth to report a feature request, but in general it looks as a new target platform for Kotlin and not sure that there is simple way. You can start from checking how WASM target is doing this
r
Eventually I think KLibs will be serialized IR I think, it's been mentioned in a few places (Kotlin 1.4 event multiplatform talk maybe?) that they want the ability to publish purely common libraries, which would require it. See https://kotlinlang.org/docs/reference/native/libraries.html
g
Well, yes, hopefully there is will be support of IR-based dependencies for Kotlin which is great feature, but generating different language from this raw IR is possible in theory, but probably not the most efficient way, you really need integration with compiler to get all the code of backend to read, interpret it and generate some output, so this why I think it is a lot more efficient to integrate with compiler, which has all the facilities to create new platforms (K/N and especially WASM targets are good show cases of it, because already based on IR)
r
Yeah, if you want to add another platform, I'd definitely do it that way. I meant more that if you wanted to take an already-compiled kotlin lib and convert it to another language, I would think you could use the compiler artifact to deserialize the IR from a klib and work from there.
g
also one point, if you just need raw IR, compiler plugin API is probably the easiest way to do that now and it already works, not need to generate IR dependency (after all it’s just intermediate output) and those dependencies are not supported yet