Skip to content

Commit c59d504

Browse files
committed
Add section giving a brief explainer of provenance.
1 parent 1de1fc5 commit c59d504

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/values.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ The operation to encode or decode a value is determined by the representation of
4242
r[value.encoding.decode]
4343
If a value of type `T` is decoded from a sequence of bytes that does not correspond to a defined value, the behavior is undefined. If a value of type `T` is decoded from a sequence of bytes that contain pointer fragments, which are not used to represent the value, the pointer fragments are ignored.
4444

45+
## Pointer Provenance
46+
47+
r[value.provenance]
48+
49+
r[value.provenance.intro]
50+
Pointer Provenance is a term that refers to additional data carried by pointer values in Rust, beyond its address. When stored in memory, Provenance is encoded in the Pointer Fragment part of each byte of the pointer.
51+
52+
r[value.provenance.allocation]
53+
Whenever a pointer to a particular allocation is produced by using the reference or raw reference operators, or when a pointer is returned from an allocation function, the resulting pointer has provenance that refers to that allocation.
54+
55+
> [!NOTE]
56+
> There is additional information encoded by provenance, but the exact scope of this information is not yet decided.
57+
58+
r[value.provenance.dangling]
59+
A pointer is dangling if it has no provenance, or if it has provenance to an allocation that has since been deallocated. An access, except for an access of size zero, using a dangling pointer, is undefined behavior.
60+
61+
> [!NOTE]
62+
> Allocations include local and static variables, as well as temporaries. Local Variables and Temporaries are deallocated when they go out of scope.
63+
64+
> [!WARN]
65+
> The above is necessary, but not sufficient, to avoid undefined behavior. The full requirements for pointer access is not yet decided.
66+
> A reference obtained in safe code is guaranteed to be valid for its usable lifetime, unless interfered with by unsafe code.
67+
4568
## Primitive Values
4669

4770
r[value.primitive]

0 commit comments

Comments
 (0)