Kotlin rules cannot be compiled against abi jars
See original GitHub issuef43e2d20913443d7047fd4219e7559d9108a802a introduced a regression that puts abi jars on the kotlinc classpath instead of full jars. kotlinc
does not like this and errors out on compilation when using methods from the kotlin standard library with the following stacktrace
Caused by: java.lang.IllegalStateException: Couldn't obtain compiled function body for public inline fun <T> mutableListOf(): kotlin.collections.MutableList<T> defined in kotlin.collections[DeserializedSimpleFunctionDescriptor@727380c2]
at org.jetbrains.kotlin.codegen.inline.InlineCodegen$1.invoke(InlineCodegen.java:280)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen$1.invoke(InlineCodegen.java:275)
at org.jetbrains.kotlin.codegen.inline.InlineCacheKt.getOrPut(InlineCache.kt:34)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.createMethodNode(InlineCodegen.java:274)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.genCallInner(InlineCodegen.java:180)
... 69 more
val words = mutableListOf<String>()
^
A repro case is available here: https://github.com/uber/okbuck/tree/gk_kotlin_abi
Command to run: ./buckw build //libraries/kotlinlibrary/...
After removing the compile_against_abis = true
change in .buckconfig
in the repro, everything works as expected
Seems like this option is not safe for kotlin modules yet. The kotlin compiler is actually introspecting the classes to extract out and inline the method into the compiled code. If we compile against the abi jars, the compiled method body will not be found. I think as part of refactoring and reusing base jvm descriptions etc for f43e2d20913443d7047fd4219e7559d9108a802a , it inadvertently introduced kotlinc to be able to pickup abi jars for compilation
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (15 by maintainers)
Top GitHub Comments
For those still following along, I am trying to add this capability now. I have class ABIs half way there - we use the KotlinMetadataReader to retain inline functions and inline property getter/setters, but there also seem to be some inner classes that we need to retain that I haven’t quite figured out yet.
For source ABIs we’ll use the Kotlin Compiler Plugin jvm-abi-gen that will generate the ABIs for us. This will work on sources but for prebuilt jars we still need the class ABI generation.
Kotlin should now be able to compile against class ABIs. The one known case that it doesn’t handle is the
expect
andactual
keywords, which are currently experimental. The hacky workaround here is to just setgenerate_abi = False
for the prebuilt jars where they are found (seems to be coroutines for now, perhaps there are other uses too).