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
Copy file name to clipboardExpand all lines: src/types/boolean.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ r[type.bool.layout]
21
21
An object with the boolean type has a [size and alignment] of 1 each.
22
22
23
23
r[type.bool.repr]
24
-
A `bool` is represented as a single initialized byte with a value of `0x00` corresponding to `false` and a value of `0x01` corresponding to `true`. This byte does not have a pointer fragment.
24
+
A `bool` is represented as a single initialized byte with a value of `0x00` corresponding to `false` and a value of `0x01` corresponding to `true`.
25
25
26
26
> [!NOTE]
27
27
> No other representations are valid for `bool`. Undefined Behaviour occurs when any other byte is read as type `bool`.
Copy file name to clipboardExpand all lines: src/types/enum.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,14 +28,13 @@ An enum value corresponds to exactly one variant of the enum, and consists of th
28
28
> [!NOTE]
29
29
> An enum with no variants therefore has no values.
30
30
31
-
r[type.enum.value.variant-padding]
32
-
A byte is a padding byte in a variant `V` if the byte is not used for computing the discriminant, and the byte would be a padding byte in a struct consisting of the fields of the variant at the same offsets.
33
-
34
31
r[type.enum.value.value-padding]
35
-
A byte is a padding byte of an enum if it is a padding byte in each variant of the enum. A byte that is not a padding byte of an enum is a value byte.
32
+
A byte is a [padding][type.union.value.padding] byte of an enum if that byte is not part of the representation of the discriminant of the enum, and in each variant it either:
33
+
* Does not overlap with a field of the variant, or
34
+
* Overlaps with a padding byte in a field of that variant.
36
35
37
36
r[type.enum.value.repr]
38
-
The representation of a value of an enum type includes the representation of each field of the variant at the appropriate offsets. When encoding a value of an enum type, each byte which is a padding byte in the variant is set to uninit. In the case of a [`repr(C)`][layout.repr.c.adt] or a [primitive-repr][layout.repr.primitive.adt] enum, the discriminant of the variant is represented as though by the appropriate integer type stored at offset 0.
37
+
The representation of a value of an enum type includes the representation of each field of the variant at the appropriate offsets. When encoding a value of an enum type, each byte which is not use d to store a field of the variant or the discriminant is . In the case of a [`repr(C)`][layout.repr.c.adt] or a [primitive-repr][layout.repr.primitive.adt] enum, the discriminant of the variant is represented as though by the appropriate integer type stored at offset 0.
39
38
40
39
> [!NOTE]
41
40
> Most `repr(Rust)` enums will also store a discriminant in the representation of the enum, but the exact placement or type of the discriminant is unspecified, as is the value that represents each variant.
The range of values an integer type can represent depends on its signedness and its width, in bits. The width of type `uN` or `iN` is `N`. The width of type `usize` or `isize` is the value of the `target_pointer_width` property.
71
71
72
72
> [!NOTE]
73
-
> There are exactly `1<<N` unique values of an integer type of width `N`.
73
+
> There are exactly `1<<N` unique values of an integer type of width `N`.
74
+
> In particular, for an unsigned type, these values are in the range `0..(1<<N)` and for a signed type, are in the range `-(1<<(N-1))..(1<<(N-1))`, using rust range syntax.
74
75
75
76
r[type.numeric.repr.unsigned]
76
77
A value `i` of an unsigned integer type `U` is represented by a sequence of initialized bytes, where the `m`th successive byte according to the byte order of the platform is `(i >> (m*8)) as u8`, where `m` is between `0` and the size of `U`. None of the bytes produced by encoding an unsigned integer has a pointer fragment.
@@ -82,13 +83,26 @@ A value `i` of an unsigned integer type `U` is represented by a sequence of init
82
83
> [!WARN]
83
84
> On `little` endian, the order of bytes used to decode an integer type is the same as the natural order of a `u8` array - that is, the `m` value corresponds with the `m` index into a same-sized `u8` array. On `big` endian, however, the order is the opposite of this order - that is, the `m` value corresponds with the `size_of::<T>() - m` index in that array.
84
85
86
+
85
87
r[type.numeric.repr.signed]
86
88
A value `i` of a signed integer type with width `N` is represented the same as the corresponding value of the unsigned counterpart type which is congruent modulo `2^N`.
87
89
90
+
> [!NOTE]
91
+
> This encoding of signed integers is known as the 2s complement encoding.
92
+
93
+
r[type.numeric.repr.float-width]
94
+
Each floating-point type has a width. The type `fN` has a width of `N`.
95
+
88
96
r[type.numeric.repr.float]
89
-
A floating-point value is represented the same as a value of the unsigned integer type with the same width given by its [IEEE 754-2019] encoding.
97
+
A floating-point value is represented by the following decoding:
98
+
* The byte sequence is decoded as the unsigned integer type with the same width as the floating-point type,
99
+
* The resulting integer is decoded according to [IEEE 754-2019] into the format used for the type.
100
+
101
+
> [!NOTE]
102
+
> The representation of each finite number and infinity is unique as a result of this.
103
+
> The exact behaviour of encoding and decoding NaNs is not yet decided
90
104
91
105
r[type.numeric.repr.float-format]
92
-
The [IEEE 754-2019]`binary32` format is used for `f32`, and the `binary64` format is used for `f64`.
106
+
The [IEEE 754-2019]`binary32` format is used for `f32`, and the `binary64` format is used for `f64`. The set of values for each floating-point type are determined by the respective format.
Copy file name to clipboardExpand all lines: src/types/pointer.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,11 +106,12 @@ A wide pointer or reference consists of a data pointer or reference, and a point
106
106
r[type.pointer.value.wide-reference]
107
107
The data pointer of a wide reference has a non-null address, well aligned for `align_of_val(self)`, and with provenance for `size_of_val(self)` bytes.
108
108
109
-
r[type.pointer.value.wide-representation]
109
+
r[type.pointer.value.wide-repr]
110
110
A wide pointer or reference is represented the same as `struct WidePointer<M>{data: *mut (), metadata: M}` where `M` is the pointee metadata type, and the `data` and `metadata` fields are the corresponding parts of the pointer.
111
111
112
112
> [!NOTE]
113
113
> The `WidePointer` struct has no guarantees about layout, and has the default representation.
114
+
> In particular, it is not guaranteed that you can write a struct type with the same layout as `WidePointer<M>`.
Copy file name to clipboardExpand all lines: src/types/struct.md
-14Lines changed: 0 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,20 +36,6 @@ r[type.struct.value]
36
36
r[type.struct.value.intro]
37
37
A value of a struct type consists of a list of values for each field.
38
38
39
-
r[type.struct.value.value-bytes]
40
-
A byte `b` in the representation of an aggregate is a value byte if there exists a field of that aggregate such that:
41
-
* The field has some type `T`,
42
-
* The offset of that field `o` is such that `b` falls at an offset in `o..(o+size_of::<T>())`,
43
-
* Either `T` is a primitive type or the offset of `b` within the field is a value byte in the representation of `T`.
44
-
45
-
> [!NOTE]
46
-
> A byte in a union is a value byte if it is a value byte in *any* field.
47
-
48
-
r[type.struct.value.padding]
49
-
Every byte in an aggregate which is not a value byte is a padding byte.
50
-
51
-
> [!NOTE]
52
-
> Enum types can also have padding bytes.
53
39
54
40
r[type.struct.value.encode-decode]
55
41
When a value of a struct type is encoded, each field of the struct is encoded at its corresponding offset and each byte that is not within a field of the struct is set to uninit.
Copy file name to clipboardExpand all lines: src/types/union.md
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,8 +24,27 @@ The memory layout of a `union` is undefined by default (in particular, fields do
24
24
*not* have to be at offset 0), but the `#[repr(...)]` attribute can be used to
25
25
fix a layout.
26
26
27
+
## Union Values
28
+
27
29
r[type.union.value]
28
-
A value of a union type consists of a sequence of bytes, corresponding to each [value byte][type.struct.value.value-bytes]. The value bytes of a union are represented exactly. Each [padding byte][type.struct.value.padding] is set to uninit when encoded.
30
+
31
+
r[type.union.value.value-bytes]
32
+
A byte `b` in the representation of a struct or union is a value byte if there exists a field of that aggregate such that:
33
+
* The field has some type `T`,
34
+
* The offset of that field `o` is such that `b` falls at an offset in `o..(o+size_of::<T>())`,
35
+
* Either `T` is a primitive type or the offset of `b` within the field is not a padding byte in the representation of `T`.
36
+
37
+
> [!NOTE]
38
+
> A byte in a union is a value byte if it is a value byte in *any* field.
39
+
40
+
r[type.struct.value.padding]
41
+
Every byte in an struct or union which is not a value byte is a padding byte. [Enum types][type.enum.value.value-padding], [tuple types][type.tuple.padding], and other types may also have padding bytes.
42
+
43
+
> [!NOTE]
44
+
> Primitive types, such as integer types, do not have padding bytes.
45
+
46
+
r[type.union.value.encoding]
47
+
A value of a union type consists of a sequence of bytes, corresponding to each [value byte][type.union.value.value-bytes]. The value bytes of a union are represented exactly. Each [padding byte][type.union.value.padding] is set to uninit when encoded.
29
48
30
49
> [!NOTE]
31
50
> A given value byte is guaranteed allowed to be uninit if it is padding in any field, recursively expanding union fields. Whether a byte of a union is allowed to be uninit in any other case is not yet decided.
0 commit comments