You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: wip/memory-interface.md
+25-14Lines changed: 25 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -9,25 +9,25 @@ This interface is a key part of the Rust Abstract Machine: it lets us separate c
9
9
10
10
The interface shown below is also opinionated in several ways.
11
11
It is not intended to be able to support *any imaginable* memory model, but rather start the process of reducing the design space of what we consider a "reasonable" memory model for Rust.
12
-
For example, it explicitly acknowledges that pointers are not just integers and that uninitialized memory is special (both are true for C and C++ as well but you have to read the standard very careful, and consult [non-normative defect report responses](http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_260.htm), to see this).
12
+
For example, it explicitly acknowledges that pointers are not just integers and that uninitialized memory is special (both are true for C and C++ as well but you have to read the standard very careful, and consult [defect report responses](http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_260.htm), to see this).
13
13
Another key property of the interface presented below is that it is *untyped*.
14
-
This implies that in Rust, *operations are typed, but memory is not*---a key difference to C and C++ with their type-based strict aliasing rules.
14
+
This implies that in Rust, *operations are typed, but memory is not* - a key difference to C and C++ with their type-based strict aliasing rules.
15
15
At the same time, the memory model provides a *side-effect free* way to turn pointers into "raw bytes", which is *not*[the direction C++ is moving towards](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2364.pdf), and we might have to revisit this choice later if it turns out to not be workable.
16
16
17
17
## Pointers
18
18
19
19
One key question a memory model has to answer is *what is a pointer*.
20
20
It might seem like the answer is just "an integer of appropriate size", but [that is not the case][pointers-complicated].
21
21
This becomes even more prominent with aliasing models such as [Stacked Borrows].
22
-
So the interface will leave it up to the concrete instance to answer this question, and carry`Pointer` as an associated type.
22
+
So we leave it up to the memory model to answer this question, and make`Pointer` an associated type.
23
23
Practically speaking, `Pointer` will be some representation of an "address", plus [provenance] information.
The unit of communication between the memory model and the rest of the program is a *byte*.
30
-
Again the question of "what is a byte" is not as trivial as it might seem; beyond `u8` values we have to represent `Pointer`s and [uninitialized memory][uninit].
30
+
Again, the question of "what is a byte" is not as trivial as it might seem; beyond `u8` values we have to represent `Pointer`s and [uninitialized memory][uninit].
31
31
We define the `Byte` type (in terms of an arbitrary `Pointer` type) as follows:
32
32
33
33
```rust
@@ -39,6 +39,7 @@ enum Byte<Pointer> {
39
39
/// One byte of a pointer.
40
40
PtrFragment {
41
41
/// The pointer of which this is a byte.
42
+
/// That is, the byte is a fragment of this pointer.
42
43
ptr:Pointer,
43
44
/// Which byte of the pointer this is.
44
45
/// `idx` will always be in `0..PTR_SIZE`.
@@ -47,10 +48,15 @@ enum Byte<Pointer> {
47
48
}
48
49
```
49
50
50
-
The purpose of `PtrFragment` is to be able to have a byte-wise representation of a `Pointer`.
51
+
The purpose of `PtrFragment` is to enable a byte-wise representation of a `Pointer`.
51
52
On a 32-bit system, the sequence of 4 bytes representing `ptr: Pointer` is:
Copy file name to clipboardExpand all lines: wip/value-domain.md
+12-10Lines changed: 12 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -17,28 +17,30 @@ The Rust value domain is described by the following (incomplete) type definition
17
17
18
18
```rust
19
19
enumValue<Pointer> {
20
-
/// A mathematical integer.
20
+
/// A mathematical integer, used for `i*`/`u*` types.
21
21
Int(BigInt),
22
-
/// A Boolean value.
22
+
/// A Boolean value, used for `bool`.
23
23
Bool(bool),
24
-
/// A pointer.
24
+
/// A pointer value, used for (thin) references and raw pointers.
25
25
Ptr(Pointer),
26
26
/// An uninitialized value.
27
27
Uninit,
28
-
/// An n-tuple.
28
+
/// An n-tuple, used for arrays, structs, tuples, SIMD vectors.
29
29
Tuple(Vec<Self>),
30
-
/// A variant of a sum type.
30
+
/// A variant of a sum type, used for enums.
31
31
Variant {
32
-
idx:u64,
32
+
idx:BigInt,
33
33
data:Box<Self>,
34
34
},
35
-
/// A "bag of raw bytes".
35
+
/// A "bag of raw bytes", used for unions.
36
36
RawBag(Vec<Byte<Pointer>>),
37
37
/* ... */
38
38
}
39
39
```
40
40
41
-
As Rust grows, we might expand this definition. That is okay; all previously defined representation relations are still well-defined when the domain grows, the newly added values will just not be valid for old types as one would expect.
41
+
The point of this type is to capture the mathematical concepts that are represented by the data we store in memory.
42
+
The definition is likely incomplete, and even if it was complete now, we might expand it as Rust grows.
43
+
That is okay; all previously defined representation relations are still well-defined when the domain grows, the newly added values will just not be valid for old types as one would expect.
42
44
43
45
## Example value relations
44
46
@@ -97,10 +99,10 @@ One key use of the value representation is to define a "typed" interface to memo
0 commit comments