Skip to main content

Ctx

Struct Ctx 

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

The thin evaluation context threaded through the tree-walker: the unique-id source (closure identities) and the builtin module cache. It carries no module registry and no loader — a module’s imports are resolved before evaluation begins (see crate::load_module), and a loaded module is an ordinary Rc-held value, kept alive only by whatever holds it.

Implementations§

Source§

impl Ctx

Source

pub fn new() -> Self

A context with a fresh id source. Used by eval and apply.

Source

pub fn with_ids(ids: u64) -> Self

A context resuming an id source at ids, so identities it mints continue where an earlier context left off.

A host that builds a fresh Ctx per call and hands values out between them — the Python bindings do exactly this — needs it: a module reserves its item id block when it is instantiated (see instantiate), and the programs that later use it mint closure ids from a different context. If both started at zero, an item and an unrelated closure would get the same id and __eq would call them equal. The host reads ids_used back when the context is done and seeds the next one with it.

The counter is carried by value rather than shared behind an Rc: the pointer chase it would add to every closure mint costs ~2% on fib_naive, and only the host needs the continuity.

Source

pub fn ids_used(&self) -> u64

How far this context’s id source has run — the value to seed a successor with (see with_ids).

Trait Implementations§

Source§

impl Default for Ctx

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !Freeze for Ctx

§

impl !RefUnwindSafe for Ctx

§

impl !Send for Ctx

§

impl !Sync for Ctx

§

impl Unpin for Ctx

§

impl UnsafeUnpin for Ctx

§

impl !UnwindSafe for Ctx

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.