Skip to content

Commit 3d504f1

Browse files
committed
be more clear that the provenance example is just that
1 parent 24022e3 commit 3d504f1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

reference/src/glossary.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ The *provenance* of a pointer is used to distinguish pointers that point to the
6161
Provenance is extra state that only exists in the Rust Abstract Machine; it is needed to specify program behavior but not present any more when the program runs on real hardware.
6262
In other words, pointers that only differ in their provenance can *not* be distinguished any more in the final binary (but provenance can influence how the compiler translates the program).
6363

64+
The exact form of provenance in Rust is unclear.
65+
It is also unclear whether provenance applies to more than just pointers, i.e., one could imagine integers having provenance as well (so that pointer provenance can be preserved when pointers are cast to an integer and back).
66+
In the following, we give some examples if what provenance *could* look like.
67+
68+
**Using provenance to track originating allocation.**
6469
For example, we have to distinguish pointers to the same location if they originated from different allocations.
6570
Cross-allocation pointer arithmetic [does not lead to usable pointers](https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_offset), so the Rust Abstract Machine *somehow* has to remember the original allocation to which a pointer pointed.
6671
It uses provenance to achieve this:
@@ -84,9 +89,11 @@ assert_eq!(raw2 as usize, raw2_wrong as usize);
8489
```
8590

8691
This kind of provenance also exists in C/C++, but Rust is more permissive by (a) providing a [way to do pointer arithmetic across allocation boundaries without causing immediate UB](https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_offset) (though, as we have seen, the resulting pointer still cannot be used for locations outside the allocation it originates), and (b) by allowing pointers to always be compared safely, even if their provenance differs.
92+
For some more information, see [this document proposing a more precise definition of provenance for C](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2364.pdf).
8793

94+
**Using provenance for Rust's aliasing rules.**
8895
Another example of pointer provenance is the "tag" from [Stacked Borrows][stacked-borrows].
89-
For some more information, see [this blog post](https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html) and [this document proposing a more precise definition of provenance for C](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2364.pdf).
96+
For some more information, see [this blog post](https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html).
9097

9198
#### Interior mutability
9299

0 commit comments

Comments
 (0)