Skip to content

Commit 13da89f

Browse files
author
Alan Jeffrey
committed
Added representation of pointer types.
1 parent 67537c4 commit 13da89f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Representation of reference and pointer types
2+
3+
### Terminology
4+
5+
Reference types are types of the form `&T` or `&mut T`.
6+
7+
Raw pointer types are types of the form `*const T` or `*mut T`.
8+
9+
### Representation
10+
11+
The alignment of reference and raw pointer types is the word size.
12+
13+
The sizes of `&T`, `&mut T`, `*const T` and `*mut T` are the same,
14+
and are at least one word.
15+
16+
* If `T` is a trait, then the size of `&T` is two words.
17+
* If `T` is a sized type then the size of `&T` is one word.
18+
* The size of `&[T]` is two words.
19+
20+
Raw pointer types have no requirements of their representation.
21+
22+
The representations of `&T` and `&mut T` are the same.
23+
24+
The representation of `&T` when `T` is a trait is the same as that of:
25+
```rust
26+
#[repr(C)]
27+
struct DynObject {
28+
data: &u8,
29+
vtable: &usize,
30+
}
31+
```
32+
33+
The representation of `&[T]` is the same as that of:
34+
```rust
35+
#[repr(C)]
36+
struct Slice<T> {
37+
ptr: &T,
38+
len: usize,
39+
}
40+
```
41+
42+
### Notes
43+
44+
The validity requirements of `&T` include that all values are non-null, which
45+
impacts niche optimizations and hence representation of types which include `&T`.
46+
In particular, `Option<&T>` is one word.

0 commit comments

Comments
 (0)