Tagged Unions in valhalla
Chen Liang
chen.l.liang at oracle.com
Tue Dec 9 21:22:42 UTC 2025
I don't think flattening or scalarization is required by the specs for any JVM implementation. The reference implementation may be able to support such inlining in the future, but it definitely requires all classes in this hierarchy are described in the LoadableDescriptors attribute.
________________________________
From: valhalla-spec-observers <valhalla-spec-observers-retn at openjdk.org> on behalf of Ben <benharless820 at gmail.com>
Sent: Thursday, November 13, 2025 12:27 PM
To: valhalla-spec-observers at openjdk.org <valhalla-spec-observers at openjdk.org>
Subject: Tagged Unions in valhalla
Hello,
I've been looking for information on how tagged unions will pan out in valhalla.
A tagged union in java would be something like
```
public sealed abstract value class Shape permits Circle, Square {}
public value class Circle extends Shape {
public float radius;
}
public value class Square extends Shape {
public float side;
}
```
(adapted from https://docs.oracle.com/en/java/javase/17/language/sealed-classes-and-interfaces.html)
>From what I know currently, this wouldn't end up being scalarized or flattened, even though the JVM runtime knows that only Circle and Square can extend Shape.
Is there a future where these do end up getting flattened or scalarized?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-observers/attachments/20251209/6c57af35/attachment-0001.htm>
More information about the valhalla-spec-observers
mailing list