Skip to content

Commit 2e5f2da

Browse files
committed
repr relation def
1 parent cec5671 commit 2e5f2da

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: reference/src/glossary.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,18 @@ requirement of 2.
179179

180180
#### Padding
181181

182-
*Padding* refers to the space that the compiler leaves between fields of a struct or enum variant to satisfy alignment requirements, and before/after variants of a union or enum to make all variants equally sized.
182+
*Padding* (of a type `T`) refers to the space that the compiler leaves between fields of a struct or enum variant to satisfy alignment requirements, and before/after variants of a union or enum to make all variants equally sized.
183183

184184
Padding can be though of as `[Pad; N]` for some hypothetical type `Pad` (of size 1) with the following properties:
185185
* `Pad` is valid for any byte, i.e., it has the same validity invariant as `MaybeUninit<u8>`.
186186
* Copying `Pad` ignores the source byte, and writes *any* value to the target byte. Or, equivalently (in terms of Abstract Machine behavior), copying `Pad` marks the target byte as uninitialized.
187187

188+
We can also define padding in terms of the [representation relation]:
189+
A byte at index `i` is a padding byte for type `T` if,
190+
for all values `v` and lists of bytes `b` such that `v` and `b` are related at `T` (let's write this `Vrel_T(v, b)`),
191+
changing `b` at index `i` to any other byte yields a `b'` such `v` and `b'` are related (`Vrel_T(v, b')`).
192+
In other words, the byte at index `i` is entirely ignored by `Vrel_T` (the value relation for `T`), and two lists of bytes that only differ in padding bytes relate to the same value(s), if any.
193+
188194
#### Place
189195

190196
A *place* (called "lvalue" in C and "glvalue" in C++) is the result of computing a [*place expression*][place-value-expr].
@@ -208,6 +214,7 @@ Values are ephemeral; they arise during the computation of an instruction but ar
208214
(This is comparable to how run-time data in a program is ephemeral and is only ever persisted in serialized form.)
209215

210216
#### Representation (relation)
217+
[representation relation]: #representation-relation
211218

212219
A *representation* of a [value](#value) is a list of bytes that is used to store or "represent" that value in memory.
213220

0 commit comments

Comments
 (0)