Kotlin Bytecode

Does the Kotlin compiler generate it’s own bytecode, before compiling down to a supported language (e.g. Java Bytecode or JS).

I’m not asking how Kotlin and Java interpolates, I’m asking if Kotlin does (or is able to) generate a bytecode of it’s own, that keeps all Kotlin features (like objects, data classes) in it’s pure state, instead of compiling them into something that can be understood by Java.

If yes, how would one go about finding it, because I can’t find anything like this in the “build” folder of Gradle. However, this would be a nice feature, which would allow for optimization tools specialized on Kotlin and/or custom language targets.

Sorry if my wording is a bit weird to follow, I’m not sure how to express what I mean exactly. Essentially, is there a way to access the structure of a Kotlin project without having to parse the raw files or reverse engineering from generate bytecode.

Any clarification would be appreciated :slight_smile:

1 Like

The compiler uses an intermediate representation. But I think this is only kept in memory.


Thanks! I will look into it and try to figure out a way to dump the IR data to a file.

No, it is not only in memory. Klib format actually contains serialized representation of IR. Right now it is the default library format for Kotlin-native and Kotlin-JS-IR. Kotlin JVM stores metadata in class annotations, but common code is also stored as serialized IR.