mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
Document valtree
This commit is contained in:
parent
c30c1be1e6
commit
bc8641a487
@ -3,8 +3,26 @@ use rustc_macros::HashStable;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)]
|
||||
#[derive(HashStable)]
|
||||
/// This datastructure is used to represent the value of constants used in the type system.
|
||||
///
|
||||
/// We explicitly choose a different datastructure from the way values are processed within
|
||||
/// CTFE, as in the type system equal values must also have equal representation.
|
||||
/// Since CTFE uses `AllocId` to represent pointers, it often happens that two different
|
||||
/// `AllocId`s point to equal values. So we may end up with different representations for
|
||||
/// two constants whose value is `&42`. Furthermore any kind of struct that has padding will
|
||||
/// have arbitrary values within that padding, even if the values of the struct are the same.
|
||||
///
|
||||
/// `ValTree` does not have this problem with representation, as it only contains integers or
|
||||
/// lists of values of itself.
|
||||
pub enum ValTree<'tcx> {
|
||||
/// ZSTs, integers, `bool`, `char` are represented as scalars.
|
||||
/// See the `ScalarInt` documentation for how `ScalarInt` guarantees that equal values
|
||||
/// of these types have the same representation.
|
||||
Leaf(ScalarInt),
|
||||
/// The fields of any kind of aggregate. Structs, tuples and arrays are represented by
|
||||
/// listing their fields' values in order.
|
||||
/// Enums are represented by storing their discriminant as a field, followed by all
|
||||
/// the fields of the variant.
|
||||
Branch(&'tcx [ValTree<'tcx>]),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user