Skip to content

Support for enums #499

Open
Open
@jberthold

Description

@jberthold

Essentially, the Aggregate constructor of the Value sort will require an additional indicator of which variant of a represented enum is being used. The AggregateKind is available at creation and contains a VariantIdx (wrapped Int) which numbers the variants from 0 .. N (presumably in source code order).

The Rvalue::Discriminant operation retrieves an indicator of which variant is being matched (and 0 for all values that are not enums).
However, as it turned out, this indicator is not the VariantIdx included in the AggregateKind that is provided upon creation of the Value. Specifically, the discriminant of enum variants can be set to arbitrary unique usizes using

enum Thing {                     #[repr(u8)]
  A = 65,                        enum ThingWithFields {
  B, // = 66,                      X(x:isize) = 88,
  D = 68,                          Y(y: isize, z:u8) = 89,
}                                }

and the discriminant for A will be 65, whereas the AggregateKind for an A contains a VariantIdx of 0.

The SwitchInt terminator will use these Discriminant values, whereas the Downcast projection uses the VariantIdx.

Reliable information about what exactly the Discriminant should return is difficult to find, and part of its semantics is even not fully determined among experts, see this discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-Token M2P-tokenrequired for supporting P-token code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions