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:

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. There should probably be more or these, for places in trans where the ty::t isn't directly available.

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_switch.

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 type_of, so it needs a pointer cast before use.

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_field_ptr.

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.