Skip to content

Commit ef3ad89

Browse files
authored
Merge pull request #67 from gnzlbg/consistent_layout
Use layout consistently instead of mixing it with representation
2 parents cfc5cf9 + df6ec48 commit ef3ad89

File tree

9 files changed

+32
-30
lines changed

9 files changed

+32
-30
lines changed

active_discussion/representation.md renamed to active_discussion/layout.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Data structure representation
1+
# Data structure layout
22

33
## Introduction
44

@@ -135,9 +135,9 @@ To start, we will create threads for each major categories of types
135135
- When using the C ABI, these map to the C pointer types, presumably
136136
- Raw pointers
137137
- Effectively same as integers?
138-
- Is `ptr::null` etc guaranteed to be equal in representation to `0_usize`?
138+
- Is `ptr::null` etc guaranteed to be equal to `0_usize`?
139139
- C does guarantee that `0` when cast to a pointer is NULL
140-
- Representation knobs:
140+
- Layout knobs:
141141
- Custom alignment ([RFC 1358])
142142
- Packed ([RFC 1240] talks about some safety issues)
143143

reference/src/SUMMARY.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
- [Keeping secrets](./active_discussion/crypto_concerns/keeping_secrets.md)
88
- [Constant time code](./active_discussion/crypto_concerns/constant_time_code.md)
99
- [Zeroing](./active_discussion/crypto_concerns/zeroing.md)
10-
- [Data structure representation](./active_discussion/representation.md)
10+
- [Data structure layout](./active_discussion/layout.md)
1111
- [Stable addresses](./active_discussion/stable_addresses.md)
1212
- [Storage liveness](./active_discussion/storage_liveness.md)
1313
- [Uninhabited types like `!` and exhaustiveness](./active_discussion/uninhabited_types.md)
1414
- [Unions](./active_discussion/unions.md)
1515
- [Uninitialized memory](./active_discussion/uninitialized_memory.md)
16-
- [Data representation](./representation.md)
17-
- [Structs and tuples](./representation/structs-and-tuples.md)
18-
- [Integers and Floating Points] (./integers-floatingpoint.md)
19-
- [Unions](./representation/unions.md)
20-
- [Vectors](./representation/vectors.md)
16+
- [Data layout](./layout.md)
17+
- [Structs and tuples](./layout/structs-and-tuples.md)
18+
- [Integers and Floating Points](./layout/integers-floatingpoint.md)
19+
- [Unions](./layout/unions.md)
20+
- [Vectors](./layout/vectors.md)
2121
- [Optimizations](./optimizations.md)
2222
- [Optimizing immutable memory](./optimizations/immutable_memory.md)
2323
- [Glossary](./glossary.md)

reference/src/glossary.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,18 @@ Moreover, such unsafe code must not return a non-UTF-8 string to the "outside" o
4949
To summarize: *Data must always be valid, but it only must be safe in safe code.*
5050
For some more information, see [this blog post](https://www.ralfj.de/blog/2018/08/22/two-kinds-of-invariants.html).
5151

52-
#### Layout / Representation
52+
#### Layout
5353

5454
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).
5555
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.
5656

57-
We often use *representation* as a synonym for "layout".
57+
Note: Originally, *layout* and *representation* were treated as synonyms, and Rust language features like the `#[repr]` attribute reflect this.
58+
In this document, *layout* and *representation* are not synonyms.
5859

5960
### TODO
6061

6162
* *niche*
6263
* *tag*
6364
* *rvalue*
6465
* *lvalue*
66+
* *representation*

reference/src/representation/integers-floatingpoint.md renamed to reference/src/layout/integers-floatingpoint.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Representation of Boolean, Floating Point, and Integral Types
1+
# Layout of Boolean, Floating Point, and Integral Types
22
This chapter represents the consensus from issue [#9]. It documents the memory layout and considerations for `bool`, `usize`, `isize`, floating point types, and integral types.
33
[#9]: https://github.com/rust-rfcs/unsafe-code-guidelines/issues/9
44

55
## Overview
6-
These are all scalar types, representing a single value. These types have no representation variants (no #[repr(C)] or #[repr(Rust)]. Their size is fixed and well-defined across FFI boundaries and map to their corresponding integral types in the C ABI.
6+
These are all scalar types, representing a single value. These types have no layout variants (no #[repr(C)] or #[repr(Rust)]. Their size is fixed and well-defined across FFI boundaries and map to their corresponding integral types in the C ABI.
77
- `bool`: 1 byte
88
- any `bool` can be cast into an integer, taking on the values 1 (true) or 0 (false)
99
- `usize`, `isize`: pointer-sized unsigned/signed integer type
@@ -20,7 +20,7 @@ These are all scalar types, representing a single value. These types have no rep
2020
- represents [Unicode scalar value](http://www.unicode.org/glossary/#unicode_scalar_value)
2121

2222
##`usize`/`isize`
23-
Types `usize` and `isize` are committed to having the same size as a native pointer on the platform. The representation of `usize` determines the following:
23+
Types `usize` and `isize` are committed to having the same size as a native pointer on the platform. The layout of `usize` determines the following:
2424
- how much a pointer of a certain type can be offseted,
2525
- the maximum size of Rust objects (because size_of/size_of_val return `usize`),
2626
- the maximum number of elements in an array ([T; N: usize]),

reference/src/representation/pointers.md renamed to reference/src/layout/pointers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Representation of reference and pointer types
1+
# Layout of reference and pointer types
22

33
### Terminology
44

@@ -29,13 +29,13 @@ and are at least one word.
2929

3030
### Notes
3131

32-
The representations of `&T`, `&mut T` and `*T` are the same.
32+
The layouts of `&T`, `&mut T` and `*T` are the same.
3333

34-
We do not make any guarantees about the representation of
34+
We do not make any guarantees about the layout of
3535
multi-trait objects `&(dyn T + U)` or references to other dynamically sized types,
3636
other than that they are at least word-aligned, and have size at least one word.
3737

38-
The representation of `&dyn T` when `T` is a trait is the same as that of:
38+
The layout of `&dyn T` when `T` is a trait is the same as that of:
3939
```rust
4040
#[repr(C)]
4141
struct DynObject {
@@ -44,7 +44,7 @@ struct DynObject {
4444
}
4545
```
4646

47-
The representation of `&[T]` is the same as that of:
47+
The layout of `&[T]` is the same as that of:
4848
```rust
4949
#[repr(C)]
5050
struct Slice<T> {
@@ -53,4 +53,4 @@ struct Slice<T> {
5353
}
5454
```
5555

56-
The representation of `&str` is the same as that of `&[u8]`.
56+
The layout of `&str` is the same as that of `&[u8]`.

reference/src/representation/structs-and-tuples.md renamed to reference/src/layout/structs-and-tuples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Representation of structs and tuples
1+
# Layout of structs and tuples
22

33
**Disclaimer:** This chapter represents the consensus from issues
44
[#11] and [#12]. The statements in here are not (yet) "guaranteed"
@@ -36,7 +36,7 @@ extend unsizing to other elements of tuples as well.
3636
Some related discussion:
3737

3838
- [RFC #1582](https://github.com/rust-lang/rfcs/pull/1582) proposed
39-
that tuple structs should have a "nested representation", where
39+
that tuple structs should have a "nested layout", where
4040
e.g. `(T1, T2, T3)` would in fact be laid out as `(T1, (T2,
4141
T3))`. The purpose of this was to permit variadic matching and so
4242
forth against some suffix of the struct. This RFC was not accepted,

reference/src/representation/unions.md renamed to reference/src/layout/unions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Representation of unions
1+
# Layout of unions
22

33
**Disclaimer:** This chapter represents the consensus from issue
44
[#13]. The statements in here are not (yet) "guaranteed"

reference/src/representation/vectors.md renamed to reference/src/layout/vectors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Representation of vectors
1+
# Layout of vectors
22

33
**Disclaimer:** This chapter represents the consensus from issue
44
[#38]. The statements in here are not (yet) "guaranteed"

reference/src/representation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# Data structure representation
1+
# Data structure layout
22

33
## Introduction
44

5-
## Representation of scalars
5+
## Layout of scalars
66

77
https://github.com/rust-rfcs/unsafe-code-guidelines/issues/9
88

9-
## Representation of enums
9+
## Layout of enums
1010

1111
https://github.com/rust-rfcs/unsafe-code-guidelines/issues/10
1212

13-
## Representation of unions
13+
## Layout of unions
1414

1515
https://github.com/rust-rfcs/unsafe-code-guidelines/issues/13
1616

17-
## Representation of references and raw pointers
17+
## Layout of references and raw pointers
1818

1919
https://github.com/rust-rfcs/unsafe-code-guidelines/issues/16
2020

21-
## Representation of function pointers
21+
## Layout of function pointers
2222

2323
https://github.com/rust-rfcs/unsafe-code-guidelines/issues/14

0 commit comments

Comments
 (0)