Skip to content

Commit 7cee58a

Browse files
authored
Merge pull request #457 from RalfJung/abi
separate ABI from Layout
2 parents 0cf4172 + bf3aca5 commit 7cee58a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

reference/src/glossary.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
## Glossary
22

3+
### ABI (of a type)
4+
[abi]: #abi-of-a-type
5+
6+
The *function call ABI* or short *ABI* of a type defines how it is passed *by-value* across a function boundary.
7+
Possible ABIs include passing the value directly in zero or more registers, or passing it indirectly as a pointer to the actual data.
8+
The space of all possible ABIs is huge and extremely target-dependent.
9+
Rust therefore does generally not clearly define the ABI of any type, it only defines when two types are *ABI-compatible*,
10+
which means that it is legal to call a function declared with an argument or return type `T` using a declaration or function pointer with argument or return type `U`.
11+
12+
Note that ABI compatibility is stricter than layout compatibility.
13+
For instance `#[repr(C)] struct S(i32)` is (guaranteed to be) layout-compatible with `i32`, but it is *not* ABI-compatible.
14+
315
### Abstract Byte
416
[abstract byte]: #abstract-byte
517

@@ -100,13 +112,15 @@ All interior mutation in Rust has to happen inside an [`UnsafeCell`](https://doc
100112
### Layout
101113
[layout]: #layout
102114

103-
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).
104-
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.
115+
The *layout* of a type defines its size and alignment as well as the offsets of its subobjects (e.g. fields of structs/unions/enums/... or elements of arrays, and the discriminant of enums).
116+
117+
Note that layout does not capture everything that there is to say about how a type is represented on the machine; it notably does not include [ABI][abi] or [Niches][niche].
105118

106119
Note: Originally, *layout* and *representation* were treated as synonyms, and Rust language features like the `#[repr]` attribute reflect this.
107-
In this document, *layout* and *representation* are not synonyms.
120+
In this document, *layout* and [*representation*][representation relation] are not synonyms.
108121

109122
### Niche
123+
[niche]: #niche
110124

111125
The *niche* of a type determines invalid bit-patterns that will be used by layout optimizations.
112126

0 commit comments

Comments
 (0)