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/AOTrt_*ABI read this slot; promotion never touches it, so compiled inline caches and pointer-identity assumptions baked into native code stay valid.shared_root— aSend + Synccross-isolate mirror,Arc<ArcSwap<Option<SharedValue>>>, reusingcrate::shared::SharedValue.bind(i.e.def/alter-var-root/set!) promotes-on-write: if the new root value is promotable the cell holdsSome(SharedValue), otherwise it is cleared toNone(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>>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
impl Var
pub fn new(namespace: impl Into<Arc<str>>, name: impl Into<Arc<str>>) -> 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.
pub fn is_bound(&self) -> bool
pub fn deref(&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.