Re:Kotlin becomes second most popular language on the JVM
by pjmlp on Thursday February 06, 2020 @03:11AM
(#22254369)
Nowadays there are trying to just get Kotlin anywhere and it remains to be seen how Valhalla and Panama will be usable from Kotlin.
[ Parent
| on HN ]
Re:Kotlin becomes second most popular language on the JVM
by thu2111 on Thursday February 06, 2020 @03:48AM
(#22254531)
Panama would not seem to pose any problems as it's all code generation with MethodHandles/VarHandles. That should be directly callable from Kotlin.
As for Valhalla, it remains to be seen how it's usable from Java, let alone anything else. But Kotlin already has a form of value type (inline classes) so perhaps it'll be an extension of that.
Re:Kotlin becomes second most popular language on the JVM
by pjmlp on Thursday February 06, 2020 @04:55AM
(#22254816)
Kotlin inline classes are heap allocated, they are just syntax sugar for regular classes.
One cannot just change their semantics after the fact.
Re:Kotlin becomes second most popular language on the JVM
by Nullabillity on Thursday February 06, 2020 @09:19AM
(#22256090)
Kotlin's inline classes (and Scala's AnyVal classes) are syntax sugar for static methods. The object itself is erased completely whenever possible (just like primitive values).
Re:Kotlin becomes second most popular language on the JVM
by pjmlp on Thursday February 06, 2020 @12:03PM
(#22257797)
Which is not the same as the semantic meaning of doing stack allocations or being stored in registers.
Re:Kotlin becomes second most popular language on the JVM
by Nullabillity on Thursday February 06, 2020 @12:51PM
(#22258318)
The following:
case class Foo(x: Int) extends AnyVal {
def square: Int = x * x
}
val bar: Foo = Foo(5)
println(bar.square) // => 25
Compiles down to (the moral equivalent of) object Foo {
def square(x: Int): Int = x * x
}
val bar: Int = 5
println(Foo.square(bar)) // => 25
If the inner value (x, in this case) can be stack-allocated or stored in registers then `Foo(x): Foo` will as well. `Foo(x): Bar` (where Bar is a supertype of Foo) will be autoboxed, but that also applies to primitive types (`5: Any` becomes a java.lang.Integer in memory).
Re:Kotlin becomes second most popular language on the JVM
by pjmlp on Thursday February 06, 2020 @01:02PM
(#22258421)
Neither of those represent the same semantics of:
inline class { ... ]
Which is guaranteed to be always stack-allocated or stored in registers, again you cannot retrofit semantics, specially when passing those classes to binary libraries.
Re:Kotlin becomes second most popular language on the JVM
by Nullabillity on Thursday February 06, 2020 @01:29PM
(#22258722)
You're correct that the Scala version isn't ABI-compatible. But Scala doesn't care about ABI between minor releases anyway, so that probably wouldn't stop them from changing it to align with Java.
There is also precedence for this, Scala 2.12 changed the encoding of lambdas from anonymous classes to Java 8's invokedynamic.