From 9fe06186b1b5cf12a67b0183626a796831640d7f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 30 Mar 2025 05:07:26 -0700 Subject: [PATCH 1/3] Define byte This is split off from https://github.com/rust-lang/reference/pull/1664 which defines what a "byte" is. Closes https://github.com/rust-lang/reference/issues/1673 --- src/memory-model.md | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/memory-model.md b/src/memory-model.md index 404240db8..5d44ab199 100644 --- a/src/memory-model.md +++ b/src/memory-model.md @@ -1,5 +1,26 @@ +r[memory] # Memory model -Rust does not yet have a defined memory model. Various academics and industry professionals -are working on various proposals, but for now, this is an under-defined place -in the language. +> [!WARNING] +> The memory model of Rust is incomplete and not fully decided. + +r[memory.bytes] +## Bytes + +r[memory.bytes.intro] +The most basic unit of memory in Rust is a byte. All values are computed from zero or more bytes read from an allocation. + +> [!NOTE] +> While bytes are typically lowered to hardware bytes, Rust uses an "abstract" notion of bytes that can make distinctions which are absent in hardware, such as being uninitialized, or storing part of a pointer. + +r[memory.bytes.contents] +Each byte may have one of the following values: + +r[memory.bytes.init] +* An initialized byte containing a `u8` value and optional [provenance][std::ptr#provenance], + +r[memory.bytes.uninit] +* An uninitialized byte. + +> [!NOTE] +> The above list is not yet guaranteed to be exhaustive. From c4152895c534604ab6a5bd2946acc5d58ae625e6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 1 Apr 2025 12:16:20 -0700 Subject: [PATCH 2/3] Add suggestion from RalfJung --- src/memory-model.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/memory-model.md b/src/memory-model.md index 5d44ab199..8b8f7addc 100644 --- a/src/memory-model.md +++ b/src/memory-model.md @@ -11,7 +11,7 @@ r[memory.bytes.intro] The most basic unit of memory in Rust is a byte. All values are computed from zero or more bytes read from an allocation. > [!NOTE] -> While bytes are typically lowered to hardware bytes, Rust uses an "abstract" notion of bytes that can make distinctions which are absent in hardware, such as being uninitialized, or storing part of a pointer. +> While bytes are typically lowered to hardware bytes, Rust uses an "abstract" notion of bytes that can make distinctions which are absent in hardware, such as being uninitialized, or storing part of a pointer. Those distinctions can affect whether your program has undefined behavior, so they still have tangible impact on how compiled Rust programs behave. r[memory.bytes.contents] Each byte may have one of the following values: From a1e39238d0603fc5978f5e10eade1b5f700f269d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 1 Apr 2025 12:24:18 -0700 Subject: [PATCH 3/3] Drop sentence about being from an allocation We didn't feel like this was well-defined enough to go into right now, and didn't seem necessary to include right now. --- src/memory-model.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/memory-model.md b/src/memory-model.md index 8b8f7addc..cc3cf02ec 100644 --- a/src/memory-model.md +++ b/src/memory-model.md @@ -8,7 +8,7 @@ r[memory.bytes] ## Bytes r[memory.bytes.intro] -The most basic unit of memory in Rust is a byte. All values are computed from zero or more bytes read from an allocation. +The most basic unit of memory in Rust is a byte. > [!NOTE] > While bytes are typically lowered to hardware bytes, Rust uses an "abstract" notion of bytes that can make distinctions which are absent in hardware, such as being uninitialized, or storing part of a pointer. Those distinctions can affect whether your program has undefined behavior, so they still have tangible impact on how compiled Rust programs behave.