Module rustc::middle::trans::adt[src]
Representation of Algebraic Data Types
This module determines how to represent enums, structs, and tuples based on their monomorphized types; it is responsible both for choosing a representation and translating basic operations on values of those types. (Note: exporting the representations for debuggers is handled in debuginfo.rs, not here.)
Note that the interface treats everything as a general case of an enum, so structs/tuples/etc. have one pseudo-variant with discriminant 0; i.e., as if they were a univariant enum.
Having everything in one place will enable improvements to data structure representation; possibilities include:
User-specified alignment (e.g., cacheline-aligning parts of concurrently accessed data structures); LLVM can't represent this directly, so we'd have to insert padding fields in any structure that might contain one and adjust GEP indices accordingly. See issue #4578.
Store nested enums' discriminants in the same word. Rather, if some variants start with enums, and those enums representations have unused alignment padding between discriminant and body, the outer enum's discriminant can be stored there and those variants can start at offset 0. Kind of fancy, and might need work to make copies of the inner enum type cooperate, but it could help with
OptionorResultwrapped around another enum.Tagged pointers would be neat, but given that any type can be used unboxed and any field can have pointers (including mutable) taken to it, implementing them for Rust seems difficult.
Structs
| Struct | For structs, and struct-like parts of anything fancier. |
Enums
| Repr | Representations. |
Functions
| const_get_discrim | Get the discriminant of a constant value. (Not currently used.) |
| const_get_field | Extract a field of a constant value, as appropriate for its representation. |
| finish_type_of | |
| incomplete_type_of | |
| is_ffi_safe | Determine, without doing translation, whether an ADT must be FFI-safe. For use in lint or similar, where being sound but slightly incomplete is acceptable. |
| ll_inttype | |
| num_args | The number of fields in a given case; for use when obtaining this information from the type or definition is less convenient. |
| represent_node | Convenience for |
| represent_type | Decides how to represent a given type. |
| sizing_type_of | |
| trans_case | Yield information about how to dispatch a case of the
discriminant-like value returned by |
| trans_const | Construct a constant value, suitable for initializing a
GlobalVariable, given a case and constant values for its fields.
Note that this may have a different LLVM type (and different
alignment!) from the representation's |
| trans_drop_flag_ptr | Access the struct drop flag, if present. |
| trans_field_ptr | Access a field, at a point when the value's case is known. |
| trans_get_discr | Obtain the actual discriminant of a value. |
| trans_start_init | Begin initializing a new value of the given case of the given
representation. The fields, if any, should then be initialized via
|
| trans_switch | Obtain a representation of the discriminant sufficient to translate destructuring; this may or may not involve the actual discriminant. |
| ty_of_inttype | |
| type_of | LLVM-level types are a little complicated. |