Skip to main content

Workspace

Struct Workspace 

Source
pub struct Workspace { /* private fields */ }
Expand description

A caller-owned, bounded workspace: an ArenaProvider pre-sized to one WorkspaceReq, so a steady-state execute whose requirement is within the bound allocates nothing.

A plan computes a conservative requirement (Plan::workspace_req in the owning crate) and execute_raw_in checks it component-wise against Workspace::req before any write. The bound is grow-only and component-wise: Workspace::reserve keeps the maximum of each field, so a large A block does not stand in for a missing B panel. A parallel executor must call Workspace::prepare_for so every worker slot is warmed before the execute.

§Examples

use tcontract_exec::{Workspace, WorkspaceReq};
let mut ws = Workspace::with_req(&WorkspaceReq { a_bytes: 64, ..Default::default() });
assert!(ws.req().a_bytes >= 64);
ws.reserve(&WorkspaceReq { b_bytes: 128, ..Default::default() });
// Component-wise: the A block is kept and the B panel is added.
assert!(ws.req().a_bytes >= 64 && ws.req().b_bytes >= 128);
let _provider = ws.as_provider();

Implementations§

Source§

impl Workspace

Source

pub fn with_req(req: &WorkspaceReq) -> Self

A workspace sized and warmed for req: the worker slot of the calling thread and one team set are grown to hold it, so a later execute within the bound does not grow the arena.

Source

pub fn reserve(&mut self, req: &WorkspaceReq)

Grow the bound to cover req as well, component-wise. The bound never shrinks, and every field keeps its own maximum.

Source

pub fn have(&self) -> usize

The bound this workspace was sized to, in bytes.

Source

pub fn req(&self) -> &WorkspaceReq

The per-component bound this workspace was sized to.

Source

pub fn slots(&self) -> usize

How many worker slots have been warmed. Workspace::prepare_for raises it to the executor’s budget.

Source

pub fn prepare_for(&mut self, exec: &Exec<'_>)

Warm one worker slot per worker the executor may run on, so a parallel execute within the bound does not allocate a slot per lane. broadcast runs the closure on budget distinct workers, one call to with_worker each; a context that cannot co-schedule (a serial one or a same-pool worker) keeps the calling thread’s slot only.

Source

pub fn as_provider(&self) -> &dyn WorkspaceProvider

The provider a plan lends to the driver for one call.

Source

pub fn retained_bytes(&self) -> usize

Bytes the owner currently retains, idle or in use. A test observes it to prove an execute did not grow the arena.

Trait Implementations§

Source§

impl Debug for Workspace

Source§

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

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

impl Default for Workspace

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.