Skip to main content

Module shape_graph_current

Module shape_graph_current 

Source
Expand description

Task-local “current” ShapeTransitionTable handle.

Mirrors the pattern established in shape-runtime::type_schema::current for TypeSchemaRegistry (B1.3), but lives in shape-value because ShapeTransitionTable is a shape-value type and pulling it up into shape-runtime would invert the crate dependency.

Two layers, consulted in order:

  1. Task-local (CURRENT_SHAPE_TABLE) — survives task migration across tokio worker threads so any descendant .await in a Shape execution future inherits the handle automatically.
  2. Thread-local (SYNC_CURRENT_SHAPE_TABLE) — fallback for synchronous entry points (CLI, tests, REPL one-shots) that are not running under a tokio task. A SyncShapeTableScope RAII guard pushes/pops the value so nested scopes compose correctly.

Unlike the type-schema current module, this one exposes a try_current_shape_table accessor that is the primary lookup used by shape_graph’s free functions (shape_transition, shape_for_hashmap_keys, shape_property_index, drain_shape_transitions). When no scope is active those free functions degrade to None / empty-drain — this preserves the existing “fall back to hash lookup, no shape tracking” semantic that was already returned for lock-poisoned or overflow cases by the previous global-backed implementation, which keeps unit tests that poke HashMapData::compute_shape without a VM alive.

Structs§

ShapeTableHandle
Shareable handle to a shape transition table and its transition log.
SyncShapeTableScope
RAII guard that installs a shape-table handle on the thread-local slot for the lifetime of the guard.

Functions§

current_shape_table
Panicking variant of try_current_shape_table. Callers that are guaranteed to execute within a VM scope may prefer this for fast- fail diagnostics.
try_current_shape_table
Return the current ambient shape-table handle, or None if no scope is active.
with_async_shape_table_scope
Run fut with handle installed as the task-local current shape table. Inherited by all descendant .await points and survives tokio task migration across worker threads.