Skip to main content

NameTable

Struct NameTable 

Source
pub struct NameTable<'str, Id = ValueId> { /* private fields */ }
Expand description

A name → value reverse map with amortized unique-name minting.

The context keeps one global table for module-scoped values (functions, varnodes, spaces, p-code ops, byte blobs); each FunctionBody keeps its own table for its block/instruction/param/Temp names. Keeping those namespaces independent is a prerequisite for running function passes in parallel: a worker mints names against its function’s table with no global lock and no cross-function collisions. Two functions may each name a block loop — they render correctly because a value’s own name field is the source of truth; this table only enforces uniqueness and resolves by name.

Implementations§

Source§

impl<'str, Id: Copy + Eq> NameTable<'str, Id>

Source

pub fn get(&self, name: &str) -> Option<Id>

The value currently holding name, if any.

Source

pub fn contains(&self, name: &str) -> bool

Whether name is taken.

Source

pub fn register( &mut self, name: Cow<'str, str>, id: Id, old_name: Option<&str>, ) -> Result<()>

Register name for id, forgetting old_name first. Errors if name is already taken (callers pre-check via get, so this only fires defensively).

Source

pub fn forget(&mut self, name: &str)

Remove name, keeping the unique suffix hint exact: if name is a generated base_<n> suffix, lower base’s hint so the freed suffix is reconsidered next time.

Source

pub fn unique(&mut self, name: Cow<'str, str>) -> Cow<'str, str>

A free name derived from name: the bare name if untaken, else the first free name_<n>. Resumes suffix probing from a cached lower bound so minting many like-named values stays ~O(1) amortized; the chosen suffix is identical to a naive first-free scan from 1.

Trait Implementations§

Source§

impl<'str, Id: Clone> Clone for NameTable<'str, Id>

Source§

fn clone(&self) -> NameTable<'str, Id>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Id> Default for NameTable<'_, Id>

Source§

fn default() -> Self

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

impl<'de, 'str, Id> Deserialize<'de> for NameTable<'str, Id>
where Id: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'str, Id> Serialize for NameTable<'str, Id>
where Id: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'str, Id> Freeze for NameTable<'str, Id>
where HashMap<Cow<'str, str>, Id, FxBuildHasher>: Freeze,

§

impl<'str, Id> RefUnwindSafe for NameTable<'str, Id>

§

impl<'str, Id> Send for NameTable<'str, Id>
where HashMap<Cow<'str, str>, Id, FxBuildHasher>: Send,

§

impl<'str, Id> Sync for NameTable<'str, Id>
where HashMap<Cow<'str, str>, Id, FxBuildHasher>: Sync,

§

impl<'str, Id> Unpin for NameTable<'str, Id>
where HashMap<Cow<'str, str>, Id, FxBuildHasher>: Unpin,

§

impl<'str, Id> UnsafeUnpin for NameTable<'str, Id>
where HashMap<Cow<'str, str>, Id, FxBuildHasher>: UnsafeUnpin,

§

impl<'str, Id> UnwindSafe for NameTable<'str, Id>
where HashMap<Cow<'str, str>, Id, FxBuildHasher>: UnwindSafe,

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.