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
impl TypeArena
Sourcepub fn freeze(&mut self)
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.
Sourcepub fn free_space(&mut self)
pub fn free_space(&mut self)
Frees types and records allocated after the last freeze call.
Sourcepub fn register_type(&mut self, tpe: Type) -> TypeRef
pub fn register_type(&mut self, tpe: Type) -> TypeRef
Registers a type and returns a deduplicated TypeRef. Returns the existing reference if already registered.
Sourcepub fn alloc_type(&mut self, tpe: Type) -> Type
pub fn alloc_type(&mut self, tpe: Type) -> Type
Allocates a fresh copy of a type. For records, this clones the record definition.
Sourcepub fn alloc_array_of(&mut self, tpe: Type) -> Type
pub fn alloc_array_of(&mut self, tpe: Type) -> Type
Creates an array type containing elements of the given type.
Sourcepub fn alloc_record(&mut self, record: FxHashMap<StrRef, Type>) -> Record
pub fn alloc_record(&mut self, record: FxHashMap<StrRef, Type>) -> Record
Allocates a new record type from a map of field names to types.
Sourcepub fn alloc_args(&mut self, args: &[Type]) -> ArgsRef
pub fn alloc_args(&mut self, args: &[Type]) -> ArgsRef
Allocates a deduplicated list of function argument types and returns an ArgsRef.
Sourcepub fn get_record(&self, key: Record) -> &FxHashMap<StrRef, Type>
pub fn get_record(&self, key: Record) -> &FxHashMap<StrRef, Type>
Returns the field map for the given record.
Sourcepub fn get_args(&self, key: ArgsRef) -> &[Type]
pub fn get_args(&self, key: ArgsRef) -> &[Type]
Returns the argument type slice for the given ArgsRef.
Sourcepub fn get_args_mut(&mut self, key: ArgsRef) -> &mut [Type]
pub fn get_args_mut(&mut self, key: ArgsRef) -> &mut [Type]
Returns a mutable reference to the argument type slice for the given ArgsRef.
Sourcepub fn args_idxes(&self, key: ArgsRef) -> impl Iterator<Item = usize> + use<>
pub fn args_idxes(&self, key: ArgsRef) -> impl Iterator<Item = usize> + use<>
Returns an iterator over valid indices for the given ArgsRef.
Sourcepub fn args_get(&self, key: ArgsRef, idx: usize) -> Type
pub fn args_get(&self, key: ArgsRef, idx: usize) -> Type
Returns the argument type at index idx for the given ArgsRef.
Sourcepub fn record_get(&self, record: Record, field: StrRef) -> Option<Type>
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.
Sourcepub fn record_iter(
&self,
record: Record,
) -> impl Iterator<Item = (StrRef, Type)>
pub fn record_iter( &self, record: Record, ) -> impl Iterator<Item = (StrRef, Type)>
Iterates over all (field name, type) pairs in the given record.
Sourcepub fn record_keys(&self, record: Record) -> impl Iterator<Item = StrRef>
pub fn record_keys(&self, record: Record) -> impl Iterator<Item = StrRef>
Iterates over all field names in the given record.
Sourcepub fn records_have_same_keys(&self, rec_a: Record, rec_b: Record) -> bool
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.
Sourcepub fn instantiate_record(&mut self) -> Record
pub fn instantiate_record(&mut self) -> Record
Creates an empty record type.
Sourcepub fn record_field_exists(&self, record: Record, field: StrRef) -> bool
pub fn record_field_exists(&self, record: Record, field: StrRef) -> bool
Returns true if the given field exists in the record.
Sourcepub fn record_entry(
&mut self,
record: Record,
key: StrRef,
) -> Entry<'_, StrRef, Type>
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.
Sourcepub fn record_set(&mut self, record: Record, field: StrRef, value: Type)
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.
Sourcepub fn record_len(&self, record: Record) -> usize
pub fn record_len(&self, record: Record) -> usize
Returns the number of fields in the given record.
Sourcepub fn record_is_empty(&self, record: Record) -> bool
pub fn record_is_empty(&self, record: Record) -> bool
Returns true if the given record has no fields.