Skip to main content

ContextView

Struct ContextView 

Source
pub struct ContextView<'a> { /* private fields */ }
Expand description

Routing view implementing ContextAccess over (&mut World, &mut FlowLocal).

This is what the VM’s drive path receives as its impl ContextAccess. Every op computes an effective scope for its unit — see ContextView::effective_scope — and then routes exactly as before:

  • World-scoped: always routes straight to World — reads and writes are immediately visible to every flow sharing that World.
  • Local-scoped, read: chain read-through — walks the FlowLocal’s own overrides, then its frozen base (recursively, see FlowLocal::chain_get_global and friends), then falls back to World’s current value on a total miss (so a flow that has never written a Local unit, nor inherited one from a base, sees the shared default until its first local write).
  • Local-scoped, write: lands in the FlowLocal’s own top-layer overrides only; World (and any frozen base) is untouched.
  • Local-scoped, increment (increment_visit, increment_turn_index): copy-on-write from the chain read-through value — read the current value (own override, else base chain, else World fallback), add one, store the result as the new top-layer override. This is what makes a flow’s first local increment start from the chain’s (or World’s) count rather than 0.

The effective scope, not the raw policy scope, drives all of the above. In Mode::Normal (every construction path before F3.2, and every non-forked flow today) the effective scope of a unit is its ResolvedPolicy scope — unchanged from F2.2/F3.1. In Mode::Sandbox the effective scope of every unit is Local, no matter what the policy says: a sandboxed flow’s reads still chain-read-through to World’s live value on a miss (so it observes current shared state), but its writes — including to units the policy homes to World — land only in its own FlowLocal overrides. World is therefore a read-only base from a sandboxed flow’s perspective: nothing it does can mutate the shared world.

Because the all-World policy (the only policy the oracle corpus exercises) takes the World branch on every op and no existing construction path ever sets Mode::Sandbox, this is byte-identical to the F1.3 all-World passthrough for every existing single-flow construction path.

Implementations§

Source§

impl<'a> ContextView<'a>

Source

pub fn new(world: &'a mut World, local: &'a mut FlowLocal) -> Self

Build a routing view over a World and FlowLocal pair for the duration of one step.

Trait Implementations§

Source§

impl ContextAccess for ContextView<'_>

Source§

fn global(&self, idx: u32) -> &Value

Source§

fn set_global(&mut self, idx: u32, value: Value)

Source§

fn visit_count(&self, id: DefinitionId) -> u32

Source§

fn increment_visit(&mut self, id: DefinitionId)

Source§

fn set_visit_count(&mut self, id: DefinitionId, count: u32)

Set a visit count directly, rather than incrementing it. Used by crate::load_state to reconcile a durable save, whose entries carry absolute counts rather than deltas.
Source§

fn turn_count(&self, id: DefinitionId) -> Option<u32>

Source§

fn set_turn_count(&mut self, id: DefinitionId, turn: u32)

Source§

fn turn_index(&self) -> u32

Source§

fn increment_turn_index(&mut self)

Source§

fn set_turn_index(&mut self, index: u32)

Set the turn index directly, rather than incrementing it. Used by crate::load_state to restore a saved turn index.
Source§

fn rng_seed(&self) -> i32

Source§

fn set_rng_seed(&mut self, seed: i32)

Source§

fn previous_random(&self) -> i32

Source§

fn set_previous_random(&mut self, val: i32)

Source§

fn next_random<R: StoryRng>(&self, seed: i32) -> i32

Source§

fn random_sequence<R: StoryRng>(&self, seed: i32, count: usize) -> Vec<i32>

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for ContextView<'a>

§

impl<'a> Freeze for ContextView<'a>

§

impl<'a> RefUnwindSafe for ContextView<'a>

§

impl<'a> Send for ContextView<'a>

§

impl<'a> Sync for ContextView<'a>

§

impl<'a> Unpin for ContextView<'a>

§

impl<'a> UnsafeUnpin for ContextView<'a>

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, 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.