Skip to main content

Var

Struct Var 

Source
pub struct Var {
    pub namespace: Arc<str>,
    pub name: Arc<str>,
    pub value: Mutex<Option<Value>>,
    pub shared_root: Arc<ArcSwap<Option<SharedValue>>>,
    pub is_macro: bool,
    pub meta: Mutex<Option<Value>>,
    pub watches: Mutex<Vec<(Value, Value)>>,
}
Expand description

A Clojure var — a namespace-interned mutable root binding.

§Two-tier root (Phase B3, issue #171)

A var’s root binding uses the same two-tier mechanism as shared-atom:

  • value — the isolate-local, GC-backed fast path. Every var deref, the IR tier, and the JIT/AOT rt_* ABI read this slot; promotion never touches it, so compiled inline caches and pointer-identity assumptions baked into native code stay valid.
  • shared_root — a Send + Sync cross-isolate mirror, Arc<ArcSwap<Option<SharedValue>>>, reusing crate::shared::SharedValue. bind (i.e. def / alter-var-root / set!) promotes-on-write: if the new root value is promotable the cell holds Some(SharedValue), otherwise it is cleared to None (option (b) of the ADR — non-promotable roots, e.g. closures, stay isolate-local).

The shared cell is what crosses the structured-clone boundary: a var def’d in one isolate is observable by value from another, with keyword /symbol identity preserved through the intern table. See crate::clone for the serialize/deserialize seam.

Dynamic binding is unchanged — it is already thread-local / per-isolate and lives on the binding stack, not in the var root.

Fields§

§namespace: Arc<str>§name: Arc<str>§value: Mutex<Option<Value>>§shared_root: Arc<ArcSwap<Option<SharedValue>>>

Cross-isolate mirror of the root binding (Phase B3). None when the var is unbound or its current root is not promotable.

§is_macro: bool§meta: Mutex<Option<Value>>

Metadata map (e.g. {:dynamic true}).

§watches: Mutex<Vec<(Value, Value)>>

Implementations§

Source§

impl Var

Source

pub fn new(namespace: impl Into<Arc<str>>, name: impl Into<Arc<str>>) -> Self

Source

pub fn from_shared_root( namespace: impl Into<Arc<str>>, name: impl Into<Arc<str>>, is_macro: bool, shared_root: Arc<ArcSwap<Option<SharedValue>>>, ) -> Self

Reconstruct a var on the receiving side of an isolate boundary.

The shared_root cell is the same Arc as the sending isolate’s, so both isolates share the cross-isolate root cell. The local value fast-path slot is seeded by demoting the current shared snapshot, so an immediate deref observes the value the var carried at crossing time.

Source

pub fn is_bound(&self) -> bool

Source

pub fn deref(&self) -> Option<Value>

Source

pub fn deref_shared(&self) -> Option<Value>

Read the cross-isolate root by demoting the shared cell, ignoring the isolate-local fast path. Returns None when the shared root is empty (unbound or non-promotable). Used to observe writes another isolate made through the shared cell.

Source

pub fn bind(&self, v: Value)

Source

pub fn get_meta(&self) -> Option<Value>

Source

pub fn set_meta(&self, m: Value)

Source

pub fn full_name(&self) -> String

Trait Implementations§

Source§

impl Debug for Var

Source§

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

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

impl Trace for Var

Source§

fn trace(&self, visitor: &mut MarkVisitor)

Source§

fn gc_size_extra(&self) -> usize

Auto Trait Implementations§

§

impl !Freeze for Var

§

impl !Send for Var

§

impl !Sync for Var

§

impl RefUnwindSafe for Var

§

impl Unpin for Var

§

impl UnsafeUnpin for Var

§

impl UnwindSafe for Var

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more