TypeContext

Struct TypeContext 

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

Central registry for types, symbols, and expression metadata.

Implementations§

Source§

impl TypeContext

Source

pub fn new() -> Self

Source

pub fn seed_defs( &mut self, def_names: &[Symbol], name_to_def: &HashMap<Symbol, DefId>, )

Seed definition mappings from DependencyAnalysis. This avoids re-registering definitions that were already assigned DefIds.

Source

pub fn intern_type(&mut self, shape: TypeShape) -> TypeId

Intern a type, returning its ID. Deduplicates identical types.

Source

pub fn get_type(&self, id: TypeId) -> Option<&TypeShape>

Get the TypeShape for a TypeId.

Source

pub fn get_or_intern(&mut self, shape: TypeShape) -> (TypeId, &TypeShape)

Get or create a type, returning both the ID and a reference.

Source

pub fn intern_struct(&mut self, fields: BTreeMap<Symbol, FieldInfo>) -> TypeId

Intern a struct type from fields.

Source

pub fn intern_single_field(&mut self, name: Symbol, info: FieldInfo) -> TypeId

Intern a struct type with a single field.

Source

pub fn get_struct_fields( &self, id: TypeId, ) -> Option<&BTreeMap<Symbol, FieldInfo>>

Get struct fields from a TypeId, if it points to a Struct.

Source

pub fn set_term_info(&mut self, expr: Expr, info: TermInfo)

Cache term info for an expression.

Source

pub fn get_term_info(&self, expr: &Expr) -> Option<&TermInfo>

Get cached term info for an expression.

Source

pub fn register_def(&mut self, interner: &mut Interner, name: &str) -> DefId

Register a definition by name, returning its DefId.

Source

pub fn register_def_sym(&mut self, sym: Symbol) -> DefId

Register a definition by pre-interned Symbol, returning its DefId.

Source

pub fn get_def_id_sym(&self, sym: Symbol) -> Option<DefId>

Get DefId for a definition by Symbol.

Source

pub fn get_def_id(&self, interner: &Interner, name: &str) -> Option<DefId>

Get DefId for a definition name (requires interner for lookup).

Source

pub fn def_name_sym(&self, def_id: DefId) -> Symbol

Get the name Symbol for a DefId.

Source

pub fn def_name<'a>(&self, interner: &'a Interner, def_id: DefId) -> &'a str

Get the name string for a DefId.

Source

pub fn mark_recursive(&mut self, def_id: DefId)

Mark a definition as recursive.

Source

pub fn is_recursive(&self, def_id: DefId) -> bool

Check if a definition is recursive.

Source

pub fn set_def_type(&mut self, def_id: DefId, type_id: TypeId)

Register the output type for a definition by DefId.

Source

pub fn set_def_type_by_name( &mut self, interner: &mut Interner, name: &str, type_id: TypeId, )

Register the output type for a definition by string name. Registers the def if not already known.

Source

pub fn get_def_type(&self, def_id: DefId) -> Option<TypeId>

Get the output type for a definition by DefId.

Source

pub fn get_def_type_by_name( &self, interner: &Interner, name: &str, ) -> Option<TypeId>

Get the output type for a definition by string name.

Source

pub fn get_arity(&self, expr: &Expr) -> Option<Arity>

Get arity for an expression.

Source

pub fn iter_types(&self) -> impl Iterator<Item = (TypeId, &TypeShape)>

Iterate over all interned types.

Source

pub fn type_count(&self) -> usize

Number of interned types.

Source

pub fn iter_def_types(&self) -> impl Iterator<Item = (DefId, TypeId)> + '_

Iterate over all definition types as (DefId, TypeId) in DefId order. DefId order corresponds to SCC processing order (leaves first).

Source

pub fn def_count(&self) -> usize

Number of registered definitions.

Source

pub fn set_type_name(&mut self, type_id: TypeId, name: Symbol)

Associate an explicit name with a type (from @x :: TypeName on struct captures).

Source

pub fn get_type_name(&self, type_id: TypeId) -> Option<Symbol>

Get the explicit name for a type, if any.

Source

pub fn iter_type_names(&self) -> impl Iterator<Item = (TypeId, Symbol)> + '_

Iterate over all explicit type names as (TypeId, Symbol).

Trait Implementations§

Source§

impl Clone for TypeContext

Source§

fn clone(&self) -> TypeContext

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 TypeContext

Source§

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

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

impl Default for TypeContext

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> 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 = 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.