Skip to content

Unions / tagged unions? #16

@juliusikkala

Description

@juliusikkala

Do we need these in the language?

Currently, dynamic dispatching with interfaces can be used to serve a similar purpose as tagged unions, although some of it is in a work-in-progress state. These cannot serve use cases where we want a generic union; something similar to std::variant or Result<T, E>.

Here's some use cases:

  • Result<T, E> could be a real type defined in the core library, instead of being an IR-only type with an explicit lowering pass.
  • In scalar CPU code, it'd make C bindings cleaner, as C unions could maybe be represented as a union in Slang too. This usecase is currently served by generating property accessors that reinterpret each member into and out of common storage. This is a rare corner case though, and can already be solved, and could impose unwanted limitations on a union spec if taken into account.
  • Discord discussion where such a type would've been desirable: https://discord.com/channels/1303735196696445038/1373318704372256928/1374175344243900509

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions