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
impl SymbolTable
Sourcepub fn allocate(
&mut self,
name: String,
kind: SymbolKind,
) -> Result<SymbolId, BindError>
pub fn allocate( &mut self, name: String, kind: SymbolKind, ) -> Result<SymbolId, BindError>
Allocate a new symbol with the given canonical name and kind.
§Errors
BindError::SymbolRenameConflictifnameis already in the table (its existing binding must be used or renamed).
Sourcepub fn lookup(&self, name: &str) -> Option<SymbolId>
pub fn lookup(&self, name: &str) -> Option<SymbolId>
Resolve a name (canonical or alias) to a SymbolId.
Sourcepub fn kind_of(&self, id: SymbolId) -> Option<SymbolKind>
pub fn kind_of(&self, id: SymbolId) -> Option<SymbolKind>
Return the SymbolKind for an already-allocated symbol.
Sourcepub fn entry(&self, id: SymbolId) -> Option<&SymbolEntry>
pub fn entry(&self, id: SymbolId) -> Option<&SymbolEntry>
Return the entry for an already-allocated symbol.
Sourcepub fn iter_entries(
&self,
) -> impl Iterator<Item = (SymbolId, &SymbolEntry)> + '_
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.
Sourcepub fn add_alias(&mut self, a_name: &str, b_name: &str) -> Result<(), BindError>
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
BindError::AliasChainLengthExceededif adding this alias would push the chain pastALIAS_CHAIN_LIMIT.BindError::SymbolRenameConflictifb_nameresolves to a different symbol thana_name(merging two distinct symbols is not an alias operation; it must go through rename).
Sourcepub fn rename(
&mut self,
old_name: &str,
new_name: &str,
) -> Result<SymbolId, BindError>
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
BindError::UnknownSymbolifold_namedoes not resolve.BindError::SymbolRenameConflictifnew_nameis already bound to a different symbol.BindError::AliasChainLengthExceededif adding the old name as an alias would push the chain past the cap.
Sourcepub fn retire(&mut self, name: &str) -> Result<SymbolId, BindError>
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
BindError::UnknownSymbolifnamedoes not resolve.
Sourcepub fn unretire(&mut self, name: &str) -> Result<SymbolId, BindError>
pub fn unretire(&mut self, name: &str) -> Result<SymbolId, BindError>
Clear a retirement flag. Symmetric with Self::retire.
§Errors
BindError::UnknownSymbolifnamedoes not resolve.
Sourcepub fn is_retired(&self, id: SymbolId) -> bool
pub fn is_retired(&self, id: SymbolId) -> bool
Whether the symbol is currently retired.
Sourcepub fn replay_allocate(
&mut self,
id: SymbolId,
name: String,
kind: SymbolKind,
) -> Result<(), BindError>
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
BindError::SymbolRenameConflictifidornameis already bound (log corruption; replay must be strictly monotonic).
Sourcepub fn replay_alias(
&mut self,
id: SymbolId,
alias: String,
) -> Result<(), BindError>
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
BindError::UnknownSymbolifidhas never been allocated.BindError::AliasChainLengthExceededif adding the alias would exceedALIAS_CHAIN_LIMIT.
Sourcepub fn replay_rename(
&mut self,
id: SymbolId,
new_canonical: String,
) -> Result<(), BindError>
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
BindError::UnknownSymbolifidhas never been allocated.
Sourcepub fn replay_retire(
&mut self,
id: SymbolId,
name: String,
) -> Result<(), BindError>
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
BindError::UnknownSymbolifidhas never been allocated.
Trait Implementations§
Source§impl Clone for SymbolTable
impl Clone for SymbolTable
Source§fn clone(&self) -> SymbolTable
fn clone(&self) -> SymbolTable
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SymbolTable
impl Debug for SymbolTable
Source§impl Default for SymbolTable
impl Default for SymbolTable
Source§fn default() -> SymbolTable
fn default() -> SymbolTable
Source§impl PartialEq for SymbolTable
impl PartialEq for SymbolTable
impl Eq for SymbolTable
impl StructuralPartialEq for SymbolTable
Auto Trait Implementations§
impl Freeze for SymbolTable
impl RefUnwindSafe for SymbolTable
impl Send for SymbolTable
impl Sync for SymbolTable
impl Unpin for SymbolTable
impl UnsafeUnpin for SymbolTable
impl UnwindSafe for SymbolTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.