You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Using the new type metadata to get the enum variant discriminator
mapping and ADT Def ID
* Enums are created as `Aggregate` values, which now carry the variant
index
* `Aggregate`s for `struct`s and `enum`s now have a correct `Ty` field
(still `TyUnknown` for tuples, though)
* `RValue::Discriminant` is implemented:
- for an `enum`, it looks up the discriminant and returns it as a `u128`
(discriminant type information unavailable)
- for other `Aggregate`s, it will always return `0` (see related
discussion in `rustc`: rust-lang/rust#91095)
This is a first step. The data returned by `Discriminant` is actually
not consistent (bit width and signedness do not match the indicated
`Ty`), which will cause issues if the obtained discriminant is used in
any way other than as a `SwitchInt` argument.
Fixes#499
---------
Co-authored-by: devops <[email protected]>
The `Map` of types is static information used for decoding constants and allocated data into `Value`s.
57
-
It maps `Ty` IDs to `RigidTy` that can be supplied to decoding functions.
58
+
It maps `Ty` IDs to `TypeInfo` that can be supplied to decoding and casting functions as well as operations involving `Aggregate` values (related to `struct`s and `enum`s).
@@ -75,6 +76,28 @@ It maps `Ty` IDs to `RigidTy` that can be supplied to decoding functions.
75
76
[owise]
76
77
```
77
78
79
+
Another type-related `Map` is required to associate an `AdtDef` ID with its corresponding `Ty` ID for `struct`s and `enum`s when creating or using `Aggregate` values.
@@ -603,21 +603,31 @@ Other `RValue`s exist in order to construct or operate on arrays and slices, whi
603
603
```
604
604
605
605
Likewise built into the language are aggregates (tuples and `struct`s) and variants (`enum`s).
606
+
Besides their list of arguments, `enum`s also carry a `VariantIdx` indicating which variant was used. For tuples and `struct`s, this index is always 0.
606
607
607
-
Tuples and structs are built as `Aggregate` values with a list of argument values.
608
+
Tuples, `struct`s, and `enum`s are built as `Aggregate` values with a list of argument values.
609
+
For `enums`, the `VariantIdx` is set, and for `struct`s and `enum`s, the type ID (`Ty`) is retrieved from a special mapping of `AdtDef` to `Ty`.
// #readOperands accumulates a list of `TypedLocal` values from operands
@@ -640,8 +650,39 @@ Tuples and structs are built as `Aggregate` values with a list of argument value
640
650
#readOperandsAux(ACC ListItem(VAL), REST)
641
651
...
642
652
</k>
653
+
```
643
654
644
-
// Discriminant, ShallowIntBox: not implemented yet
655
+
The `Aggregate` type carries a `VariantIdx` to distinguish the different variants for an `enum`.
656
+
This variant index is used to look up the _discriminant_ from a table in the type metadata during evaluation of the `Rvalue::Discriminant`. Note that the discriminant may be different from the variant index for user-defined discriminants and uninhabited variants.
0 commit comments