https://kotlinlang.org logo
#announcements
Title
# announcements
f

Fleshgrinder

02/13/2020, 5:54 PM
I wonder why exactly
private const val
symbols are kept in the bytecode. I guess for reflection but what if this is not required? There should be some kind of annotation to drop these symbols after they are inlined everywhere, no? (Maybe should post this in #language-proposals but wanted to first hear if someone has another reason than reflection to keep them.)
m

Mike

02/13/2020, 6:32 PM
Hadn't noticed, but now also curious why they're kept. They can't be used from Java, and should be inlined in all Kotlin code. Perhaps there's a scenario where the compiler can't inline the
const
? Otherwise, I agree. All
private const val
should not appear in the bytecode.
f

Fleshgrinder

02/13/2020, 6:41 PM
A file containing only
private const val X = 1
produces this (IntelliJ Kotlin bytecode viewer).
So it's not about the ability to inline something, or not.
m

Mike

02/13/2020, 6:44 PM
Sorry, I meant perhaps they're always kept because there could be a scenario where the compiler can't inline it, but rather than handling that scenario explicitly, it just generates them all. It's far-fetched at best...
f

Fleshgrinder

02/13/2020, 6:50 PM
I see, in that case it would be easily possible to change the behavior without considering it a breaking change. However, I fear it's reflection…
m

Mike

02/13/2020, 7:29 PM
Time to bring it to the language experts and ask them.
2 Views