So I'm paying around with IR and I've generated a ...
# compiler
d
So I'm paying around with IR and I've generated a simple function. When the Kotlin compiler runs and I export the project JAR, I can see my function in the JAR. Yay! But if I look at the class files in the build folder it's nowhere to be found. Also I can't use the function from the test sources. What am I missing?
s
You probably should generate synthetic descriptors for the class or function you wanted, I remember it solved me a a similar problem.
d
Do you happen to have a link to an example for this? I'm only supplying a
IrGenerationExtension
right now.
s
I think serialization plugin does something similar here: https://github.com/JetBrains/kotlin/blob/master/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/extensions/SerializationResolveExtension.kt However, I am not sure if your problem is related to this directly, I had similar issue in a bit different context 🙂
d
Thanks!
s
Tell me if it helps, really curious myself
d
Auto-complete did not help very much, not sure why it sucks for kotlin compiler stuff. Anyway, adding the synthetic thingy, allows the compiler to compile usages of my generated function but the IDE still doesn't see it. When I decompile the class file to Java, it's there, but when decompiled to Kotlin, it's not there. Weird...... My gut says I'll have to write an IDE plugin but I think that's where I'll call it quits.
s
Yeah, you have to generate the same synthetic descriptor for ide (kotlinx.serialization does that too) Essentially, they have separated frontends: one used in ide and one for compilation
Another interesting point I have noticed while experimenting with backend generation, is that IDEA does not find some of the generated methods whereas bytecode viewer does. It seems like its decompiler relies on kotlin metadata, so your function is indeed in the bytecode, just IDEA (and maybe compiler) is not aware of that.