Skip to content

Commit f4683c8

Browse files
committed
alphabetize the entries
1 parent 710f0ea commit f4683c8

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

reference/src/glossary.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,13 @@ If data immediately pointed to by a `*const T` or `&*const T` is mutated, that's
1414
*Interior mutability* refers to the ability to perform interior mutation without causing UB.
1515
All interior mutation in Rust has to happen inside an [`UnsafeCell`](https://doc.rust-lang.org/core/cell/struct.UnsafeCell.html), so all data structures that have interior mutability must (directly or indirectly) use `UnsafeCell` for this purpose.
1616

17-
#### Validity Invariant
18-
19-
The *validity invariant* is an invariant that all data must uphold any time it is accessed or copied in a typed manner.
20-
This invariant is known to the compiler and exploited by optimizations such as improved enum layout or eliding in-bounds checks.
17+
#### Layout
2118

22-
In terms of MIR statements, "accessed or copied" means whenever an assignment statement is executed.
23-
That statement has a type (LHS and RHS must have the same type), and the data being assigned must be valid at that type.
24-
Moreover, arguments passed to a function must be valid at the type given in the callee signature, and the return value of a function must be valid at the type given in the caller signature.
25-
OPEN QUESTION: Are there more cases where data must be valid?
19+
The *layout* of a type defines its size and alignment as well as the offsets of its subobjects (e.g. fields of structs/unions/enum/... or elements of arrays).
20+
Moreover, the layout of a type records its *function call ABI* (or just *ABI* for short): how the type is passed *by value* across a function boundary.
2621

27-
In terms of code, some data computed by `TERM` is valid at type `T` if and only if the following program does not have UB:
28-
```rust,ignore
29-
fn main() { unsafe {
30-
let t: T = std::mem::transmute(TERM);
31-
} }
32-
```
22+
Note: Originally, *layout* and *representation* were treated as synonyms, and Rust language features like the `#[repr]` attribute reflect this.
23+
In this document, *layout* and *representation* are not synonyms.
3324

3425
#### Safety Invariant
3526

@@ -53,14 +44,6 @@ Moreover, such unsafe code must not return a non-UTF-8 string to the "outside" o
5344
To summarize: *Data must always be valid, but it only must be safe in safe code.*
5445
For some more information, see [this blog post](https://www.ralfj.de/blog/2018/08/22/two-kinds-of-invariants.html).
5546

56-
#### Layout
57-
58-
The *layout* of a type defines its size and alignment as well as the offsets of its subobjects (e.g. fields of structs/unions/enum/... or elements of arrays).
59-
Moreover, the layout of a type records its *function call ABI* (or just *ABI* for short): how the type is passed *by value* across a function boundary.
60-
61-
Note: Originally, *layout* and *representation* were treated as synonyms, and Rust language features like the `#[repr]` attribute reflect this.
62-
In this document, *layout* and *representation* are not synonyms.
63-
6447
#### Niche
6548

6649
The *niche* of a type determines invalid bit-patterns that will be used by layout optimizations.
@@ -75,6 +58,22 @@ niches. For example, the "all bits uninitialized" is an invalid bit-pattern for
7558
`&mut T`, but this bit-pattern cannot be used by layout optimizations, and is not a
7659
niche.
7760

61+
#### Validity Invariant
62+
63+
The *validity invariant* is an invariant that all data must uphold any time it is accessed or copied in a typed manner.
64+
This invariant is known to the compiler and exploited by optimizations such as improved enum layout or eliding in-bounds checks.
65+
66+
In terms of MIR statements, "accessed or copied" means whenever an assignment statement is executed.
67+
That statement has a type (LHS and RHS must have the same type), and the data being assigned must be valid at that type.
68+
Moreover, arguments passed to a function must be valid at the type given in the callee signature, and the return value of a function must be valid at the type given in the caller signature.
69+
OPEN QUESTION: Are there more cases where data must be valid?
70+
71+
In terms of code, some data computed by `TERM` is valid at type `T` if and only if the following program does not have UB:
72+
```rust,ignore
73+
fn main() { unsafe {
74+
let t: T = std::mem::transmute(TERM);
75+
} }
76+
```
7877

7978
### TODO
8079

0 commit comments

Comments
 (0)