Skip to main content

TypeArena

Struct TypeArena 

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

An arena-based allocator for type information.

Stores and deduplicates types, record definitions, and function argument lists. Supports freezing to mark a baseline and freeing types allocated after the baseline.

Implementations§

Source§

impl TypeArena

Source

pub fn freeze(&mut self)

Marks the current allocation state as the baseline.

Subsequent calls to free_space will deallocate only types and records allocated after this point.

Source

pub fn free_space(&mut self)

Frees types and records allocated after the last freeze call.

Source

pub fn register_type(&mut self, tpe: Type) -> TypeRef

Registers a type and returns a deduplicated TypeRef. Returns the existing reference if already registered.

Source

pub fn alloc_type(&mut self, tpe: Type) -> Type

Allocates a fresh copy of a type. For records, this clones the record definition.

Source

pub fn alloc_array_of(&mut self, tpe: Type) -> Type

Creates an array type containing elements of the given type.

Source

pub fn alloc_record(&mut self, record: FxHashMap<StrRef, Type>) -> Record

Allocates a new record type from a map of field names to types.

Source

pub fn alloc_args(&mut self, args: &[Type]) -> ArgsRef

Allocates a deduplicated list of function argument types and returns an ArgsRef.

Source

pub fn get_type(&self, key: TypeRef) -> Type

Retrieves the type for the given TypeRef.

Source

pub fn get_record(&self, key: Record) -> &FxHashMap<StrRef, Type>

Returns the field map for the given record.

Source

pub fn get_args(&self, key: ArgsRef) -> &[Type]

Returns the argument type slice for the given ArgsRef.

Source

pub fn get_args_mut(&mut self, key: ArgsRef) -> &mut [Type]

Returns a mutable reference to the argument type slice for the given ArgsRef.

Source

pub fn args_idxes(&self, key: ArgsRef) -> impl Iterator<Item = usize> + use<>

Returns an iterator over valid indices for the given ArgsRef.

Source

pub fn args_get(&self, key: ArgsRef, idx: usize) -> Type

Returns the argument type at index idx for the given ArgsRef.

Source

pub fn record_get(&self, record: Record, field: StrRef) -> Option<Type>

Returns the type of a field in the given record, or None if the field doesn’t exist.

Source

pub fn record_iter( &self, record: Record, ) -> impl Iterator<Item = (StrRef, Type)>

Iterates over all (field name, type) pairs in the given record.

Source

pub fn record_keys(&self, record: Record) -> impl Iterator<Item = StrRef>

Iterates over all field names in the given record.

Source

pub fn records_have_same_keys(&self, rec_a: Record, rec_b: Record) -> bool

Checks whether two records have the exact same set of field names.

Source

pub fn instantiate_record(&mut self) -> Record

Creates an empty record type.

Source

pub fn record_field_exists(&self, record: Record, field: StrRef) -> bool

Returns true if the given field exists in the record.

Source

pub fn record_entry( &mut self, record: Record, key: StrRef, ) -> Entry<'_, StrRef, Type>

Returns the hash map entry for a field in the given record, for in-place manipulation.

Source

pub fn record_set(&mut self, record: Record, field: StrRef, value: Type)

Sets the type of a field in the given record, inserting or updating as needed.

Source

pub fn record_len(&self, record: Record) -> usize

Returns the number of fields in the given record.

Source

pub fn record_is_empty(&self, record: Record) -> bool

Returns true if the given record has no fields.

Trait Implementations§

Source§

impl Default for TypeArena

Source§

fn default() -> TypeArena

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

impl Serialize for TypeArena

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§

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> 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, 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.