I really love to leverage the compiler to explicitly verify my intent. This is great for example with the tailrec modifier.
With inline classes, the compiler is smart enough to figure out when to use a wrapper and when not to, and this is a productivity booster in many cases. However, when using inline classes for performance reasons, I want the compiler to help me detect and change these usages.
I haven’t thought much about it, but two ideas come to mind:
You got me there: I have no measurements to support this request. But hear me out!
I work on a Java project and I’m exploring Kotlin on my free time, evaluating different aspects to make it appealing to my boss and coworkers.
We work quite a lot with integral types, and I get a lot of pushback when creating abstractions for type safety. Inline classes as they are already offer great advantages, but being able to prove that no allocations are made would be an even better selling point.
This is why I compare it with tailrec: you can write a function and expect the compiler to optimize it, but it’s better to enforce it when needed.
In Java, you have the int and Integer types giving control over boxing/unboxing/allocation. As we discuss this, I remember that Kotlin’s Int type hides this away, which kind of goes against this idea.
I guess I got carried away by the great compile time support the language has. It would be cool to have more fine grained control over the inline class compilation process, but I am not ready to talk numbers at the moment.