Skip to main content

SymbolTable

Struct SymbolTable 

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

A per-workspace symbol table.

Symbol IDs are allocated monotonically as a u64; canonical names and alias names are stored in a flat name→id lookup for O(1) resolution.

See symbol-identity-semantics.md § 3 for the design.

§Examples

use mimir_core::bind::SymbolTable;
use mimir_core::SymbolKind;

let mut table = SymbolTable::new();
let id = table
    .allocate("alice".into(), SymbolKind::Agent)
    .unwrap();
assert_eq!(table.lookup("alice"), Some(id));

Implementations§

Source§

impl SymbolTable

Source

pub fn new() -> Self

Construct an empty symbol table.

Source

pub fn allocate( &mut self, name: String, kind: SymbolKind, ) -> Result<SymbolId, BindError>

Allocate a new symbol with the given canonical name and kind.

§Errors
Source

pub fn lookup(&self, name: &str) -> Option<SymbolId>

Resolve a name (canonical or alias) to a SymbolId.

Source

pub fn kind_of(&self, id: SymbolId) -> Option<SymbolKind>

Return the SymbolKind for an already-allocated symbol.

Source

pub fn entry(&self, id: SymbolId) -> Option<&SymbolEntry>

Return the entry for an already-allocated symbol.

Source

pub fn iter_entries( &self, ) -> impl Iterator<Item = (SymbolId, &SymbolEntry)> + '_

Iterate all entries in the table, yielding (SymbolId, &SymbolEntry) pairs. Iteration order is undefined; callers that need stable output should sort on the consuming side.

Source

pub fn add_alias(&mut self, a_name: &str, b_name: &str) -> Result<(), BindError>

Declare an alias — both names resolve to the same symbol.

Both symbols must already be allocated; they must resolve to the same SymbolId already, OR one must not be an alias of the other yet. See symbol-identity-semantics.md § 7.

§Errors
Source

pub fn rename( &mut self, old_name: &str, new_name: &str, ) -> Result<SymbolId, BindError>

Rename a symbol. Old name becomes an alias; new name becomes the canonical.

§Errors
Source

pub fn retire(&mut self, name: &str) -> Result<SymbolId, BindError>

Mark a symbol retired. Existing references still resolve; new references through the agent API trigger stale_symbol warnings on read.

§Errors
Source

pub fn unretire(&mut self, name: &str) -> Result<SymbolId, BindError>

Clear a retirement flag. Symmetric with Self::retire.

§Errors
Source

pub fn is_retired(&self, id: SymbolId) -> bool

Whether the symbol is currently retired.

Source

pub fn replay_allocate( &mut self, id: SymbolId, name: String, kind: SymbolKind, ) -> Result<(), BindError>

Replay an SYMBOL_ALLOC canonical record into this table. Unlike Self::allocate the caller supplies the original SymbolId; the next_id monotonic counter is advanced past the replayed ID so future agent allocations stay unique.

Used by crate::store::Store::open to rebuild the table from a durable log.

§Errors
Source

pub fn replay_alias( &mut self, id: SymbolId, alias: String, ) -> Result<(), BindError>

Replay an SYMBOL_ALIAS canonical record. Attaches alias as an additional name resolving to id.

§Errors
Source

pub fn replay_rename( &mut self, id: SymbolId, new_canonical: String, ) -> Result<(), BindError>

Replay an SYMBOL_RENAME canonical record. The previous canonical name is rotated into aliases.

§Errors
Source

pub fn replay_retire( &mut self, id: SymbolId, name: String, ) -> Result<(), BindError>

Replay an SYMBOL_RETIRE canonical record. Marks the symbol retired. name is the symbol’s canonical name at retire time; propagated into the error for diagnosability.

§Errors

Trait Implementations§

Source§

impl Clone for SymbolTable

Source§

fn clone(&self) -> SymbolTable

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SymbolTable

Source§

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

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

impl Default for SymbolTable

Source§

fn default() -> SymbolTable

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

impl PartialEq for SymbolTable

Source§

fn eq(&self, other: &SymbolTable) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SymbolTable

Source§

impl StructuralPartialEq for SymbolTable

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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