Are there any plans to introduce Valhalla support to Scala in near future?

I know that Java 19 is still fresh, and maybe designers prefer to wait first for the ‘long support release’, but I wondered what kind of priority this may have in the eyes of the developers.

Some features in my codebase rely on @specialization - in fact, some make no sense without it. We have Steppers and may use the same principle for other cases, but its a lot of duplication, works on a case by case basis, and is at best a stop gap until we receive something proper (I know that their primary function is Java interoperability, but it also provides access to a properly specialized Java iterator which can be use in such situations). If I wanted to port specialized collections to Scala based on the same design principle, I would have to do it on the IterableOnce level, as type signatures for basic methods like map would need to change to pass information about the underlying type (aside from the widened, specialized type).

Has anyone started to think about how to proceed with integration? I weren’t able to find anything relevant here. Or is everyone waiting until Java implements generics support for primitive types?
Sorry if I sound entilted, I simply would like to create a road map for my scala 2 libraries and have an idea when can I adopt Scala 3, as this is the sole stopper for me (aside from a lot of work involved, that is).

Java 19 does not include any part of Valhalla yet. From following the discussions in The valhalla-spec-experts Archives it seems that value classes might be coming as a preview feature in a release of the JDK in the not-so-distant future (and we’ll have to see how we can integrate that with Scala’s own concept of value classes, it seems compatible so far), but class specialization itself still seems to be a long way off.

2 Likes

You are right, it’s a Java 20 feature, I remembered reading about it in a ‘what’s new’ article and somehow assumed it’s about a released version. Nevertheless it’s around the corner. On the language level itself it seems like the integration of value classes should go seamlessly, although the value/reference duality in Valhalla is more explicit than in Scala. Bummed to hear about specialization, it really hurt’s, as the choice is either to wait with adoption for years, or create a whole new, detached library to be thrown out also in the timeframe of a couple of years :frowning:

Thanks for info, though.

Also: are functions treated specially in Scala 3 and remain specialized, or did we lose that, too?

Yes, both functions and tuples are special-cased in the compiler to be specialized.

Well, the alternative would be an evolution, rather than revolution. Some libraries may become obsolete or partially obsolete when the language changes, but many, which provide unrelated features, may at most require a port. Throwing stuff out and starting anew is always extremely risky, project management-wise, not to mention disheartening.

1 Like

I sympathize with your eagerness. I’ve been waiting for Valhalla for near 15 years myself.

I think people in the Scala space understand what a big deal Valhalla is. It opens the way for demanding computational problems to run well on the JVM, from scientific computing to AI to games & graphics. And Scala’s precise type system and typeclass support are well suited to heavily computational code.

However… this isn’t a fast journey. If you need Valhalla-like structs right now, C++ or C# is a better choice than Scala. I wouldn’t be surprised if it’s another 5 years until we see Valhalla well supported in Scala, ie with enough specialization that whole algorithms can run without hitting boxing. Of course, value types defined in Java will be usable from Scala much earlier than that.

6 Likes

there’s already scala-native :wink:

3 Likes

I think the more proper term would be ‘there will be’ :wink: But these are two completely different beasts, unless Scala native somehow introduced transparent startup of a JVM and rpc to interact with external libraries, even the standard Java library, it’s use is seriously limited. I am happy it exists, because if ever I need to compile something to machine code I can use a language I am intimately familiar with, in the same way that Scala can be used as a scripting language, but it doesn’t make it the best choice for those use cases in general.

Counter-point:

3 Likes

Valhalla update from John Rose: new/dup/init: The Dance Goes On

What has been suprising to us is not that Java classes are adequate to model struct-like flat values. The surprise is that we can do this without sacrificing our performance goals. This note describes the removal of Q-types and v-bytecodes, and the resulting adjusted VM design

6 Likes