Struct Memory

Source
pub struct Memory<F> {
    inner: Vec<MemoryValue<F>>,
}
Expand description

The VM’s memory.

Memory is internally represented as a vector of values. We grow the memory when values past the end are set, extending with 0s.

§Capacity Limits

The inner Vec is subject to Rust’s allocator limit of isize::MAX bytes. This means:

  • On 64-bit: Practical limit is available RAM (~200 GB for full u32 range)
  • On 32-bit: Hard limit of ~44 million addressable slots

Exceeding these limits will cause a panic with “capacity overflow”.

Fields§

§inner: Vec<MemoryValue<F>>

Implementations§

Source§

impl<F: AcirField> Memory<F>

Source

const MAX_MEMORY_SIZE: usize = 2_147_483_647usize

Maximum number of memory slots that can be allocated.

This limit is set to i32::MAX to ensure deterministic behavior across all architectures. On 32-bit systems, Rust’s allocator limits allocations to isize::MAX bytes, which would restrict us to fewer elements anyway. By using i32::MAX, we ensure the same behavior on both 32-bit and 64-bit systems.

See: https://github.com/rust-lang/rust/pull/95295 and https://doc.rust-lang.org/1.81.0/src/core/alloc/layout.rs.html

Source

fn get_stack_pointer(&self) -> u32

Read the value from slot 0.

Panics if it’s not a U32.

Source

fn resolve(&self, address: MemoryAddress) -> u32

Resolve an address to either:

  • itself, if it’s a direct address, or
  • the current stack pointer plus the offset, if it’s relative.

Returns a memory slot index.

Source

pub fn read(&self, address: MemoryAddress) -> MemoryValue<F>

Reads the numeric value at the address.

If the address is beyond the size of memory, a default value is returned.

Source

pub fn read_ref(&self, ptr: MemoryAddress) -> MemoryAddress

Reads the value at the address and returns it as a direct memory address, without dereferencing the pointer itself to a numeric value.

Source

pub fn write_ref(&mut self, ptr: MemoryAddress, address: MemoryAddress)

Sets ptr to point at address.

Source

pub fn read_slice( &self, address: MemoryAddress, len: usize, ) -> &[MemoryValue<F>]

Read a contiguous vector of memory starting at address, up to len slots.

Panics if the end index is beyond the size of the memory.

Source

pub fn write(&mut self, address: MemoryAddress, value: MemoryValue<F>)

Sets the value at address to value

Source

fn resize_to_fit(&mut self, size: usize)

Increase the size of memory fit size elements, or the current length, whichever is bigger.

§Panics

Panics if size exceeds Self::MAX_MEMORY_SIZE.

Source

pub fn write_slice(&mut self, address: MemoryAddress, values: &[MemoryValue<F>])

Sets the values after address to values

Source

pub fn values(&self) -> &[MemoryValue<F>]

Returns the values of the memory

Trait Implementations§

Source§

impl<F: Clone> Clone for Memory<F>

Source§

fn clone(&self) -> Memory<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug> Debug for Memory<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Default> Default for Memory<F>

Source§

fn default() -> Memory<F>

Returns the “default value” for a type. Read more
Source§

impl<F: PartialEq> PartialEq for Memory<F>

Source§

fn eq(&self, other: &Memory<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Eq> Eq for Memory<F>

Source§

impl<F> StructuralPartialEq for Memory<F>

Auto Trait Implementations§

§

impl<F> Freeze for Memory<F>

§

impl<F> RefUnwindSafe for Memory<F>
where F: RefUnwindSafe,

§

impl<F> Send for Memory<F>
where F: Send,

§

impl<F> Sync for Memory<F>
where F: Sync,

§

impl<F> Unpin for Memory<F>
where F: Unpin,

§

impl<F> UnwindSafe for Memory<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V