Hello, I've written a compiler plugin for the new ...
# compiler
f
Hello, I've written a compiler plugin for the new 1.4.0 IR compiler backend, and I am now using it in a project of mine. I want to see the bytecode output, and to do so I am using the IntelliJ "Kotlin Bytecode Viewer" built-in tool. In that tool, there is a checkbox for using IR, so I enabled it, but it caused this error when trying to display the bytecode:
java.lang.IllegalStateException: No module deserializer found for <library Gradle: net.minecraft:minecraftSrc:1.12.2> is a module[ModuleDescriptorImpl@5c013a11]
. I'm not sure what this means?
u
I’m also not sure what it means, but we basically do not guarantee anything about the Kotlin Bytecode toolwindow, and it might not even work sometimes at all. I recommend you to use
javap
(probably with
-v
for verbose) instead. It’s not as convenient, but is pretty fast if you’re used to it and it’s guaranteed to work
f
Oh okay, thank you. By the way, is there a way for me to check to make sure the compiler is even using the IR backend (I'm using Gradle)?
I have what I believe is the correct configuration, but my plugin doesn't seem to be doing anything.
u
The most fireproof method is to check the value of the flag
xi
in the
kotlin.Metadata
annotation on the class file. Using
javap -v Some.class
, you can see this at the end:
Copy code
RuntimeVisibleAnnotations:
  0: #25(#26=[I#27,I#28,I#27],#29=[I#27,I#30,I#31],#32=I#33,#34=I#35,#36=[s#37],#38=[s#5,s#39,s#23,s#39])
    kotlin.Metadata(
      mv=[1,4,1]
      bv=[1,0,3]
      k=2
      xi=16
      d1=[...]
      d2=[...]
    )
If the value of
xi & 16
is not zero, then the class file is compiled using the IR backend :). For example, 16 means that it is. (As per https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/jvm/runtime/kotlin/Metadata.kt#L71)
❤️ 1