pub struct TypeContext { /* private fields */ }Expand description
Central registry for types, symbols, and expression metadata.
Implementations§
Source§impl TypeContext
impl TypeContext
pub fn new() -> Self
Sourcepub fn seed_defs(
&mut self,
def_names: &[Symbol],
name_to_def: &HashMap<Symbol, DefId>,
)
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.
Sourcepub fn intern_type(&mut self, shape: TypeShape) -> TypeId
pub fn intern_type(&mut self, shape: TypeShape) -> TypeId
Intern a type, returning its ID. Deduplicates identical types.
Sourcepub fn get_or_intern(&mut self, shape: TypeShape) -> (TypeId, &TypeShape)
pub fn get_or_intern(&mut self, shape: TypeShape) -> (TypeId, &TypeShape)
Get or create a type, returning both the ID and a reference.
Sourcepub fn intern_struct(&mut self, fields: BTreeMap<Symbol, FieldInfo>) -> TypeId
pub fn intern_struct(&mut self, fields: BTreeMap<Symbol, FieldInfo>) -> TypeId
Intern a struct type from fields.
Sourcepub fn intern_single_field(&mut self, name: Symbol, info: FieldInfo) -> TypeId
pub fn intern_single_field(&mut self, name: Symbol, info: FieldInfo) -> TypeId
Intern a struct type with a single field.
Sourcepub fn get_struct_fields(
&self,
id: TypeId,
) -> Option<&BTreeMap<Symbol, FieldInfo>>
pub fn get_struct_fields( &self, id: TypeId, ) -> Option<&BTreeMap<Symbol, FieldInfo>>
Get struct fields from a TypeId, if it points to a Struct.
Sourcepub fn set_term_info(&mut self, expr: Expr, info: TermInfo)
pub fn set_term_info(&mut self, expr: Expr, info: TermInfo)
Cache term info for an expression.
Sourcepub fn get_term_info(&self, expr: &Expr) -> Option<&TermInfo>
pub fn get_term_info(&self, expr: &Expr) -> Option<&TermInfo>
Get cached term info for an expression.
Sourcepub fn register_def(&mut self, interner: &mut Interner, name: &str) -> DefId
pub fn register_def(&mut self, interner: &mut Interner, name: &str) -> DefId
Register a definition by name, returning its DefId.
Sourcepub fn register_def_sym(&mut self, sym: Symbol) -> DefId
pub fn register_def_sym(&mut self, sym: Symbol) -> DefId
Register a definition by pre-interned Symbol, returning its DefId.
Sourcepub fn get_def_id_sym(&self, sym: Symbol) -> Option<DefId>
pub fn get_def_id_sym(&self, sym: Symbol) -> Option<DefId>
Get DefId for a definition by Symbol.
Sourcepub fn get_def_id(&self, interner: &Interner, name: &str) -> Option<DefId>
pub fn get_def_id(&self, interner: &Interner, name: &str) -> Option<DefId>
Get DefId for a definition name (requires interner for lookup).
Sourcepub fn def_name_sym(&self, def_id: DefId) -> Symbol
pub fn def_name_sym(&self, def_id: DefId) -> Symbol
Get the name Symbol for a DefId.
Sourcepub fn def_name<'a>(&self, interner: &'a Interner, def_id: DefId) -> &'a str
pub fn def_name<'a>(&self, interner: &'a Interner, def_id: DefId) -> &'a str
Get the name string for a DefId.
Sourcepub fn mark_recursive(&mut self, def_id: DefId)
pub fn mark_recursive(&mut self, def_id: DefId)
Mark a definition as recursive.
Sourcepub fn is_recursive(&self, def_id: DefId) -> bool
pub fn is_recursive(&self, def_id: DefId) -> bool
Check if a definition is recursive.
Sourcepub fn set_def_type(&mut self, def_id: DefId, type_id: TypeId)
pub fn set_def_type(&mut self, def_id: DefId, type_id: TypeId)
Register the output type for a definition by DefId.
Sourcepub fn set_def_type_by_name(
&mut self,
interner: &mut Interner,
name: &str,
type_id: TypeId,
)
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.
Sourcepub fn get_def_type(&self, def_id: DefId) -> Option<TypeId>
pub fn get_def_type(&self, def_id: DefId) -> Option<TypeId>
Get the output type for a definition by DefId.
Sourcepub fn get_def_type_by_name(
&self,
interner: &Interner,
name: &str,
) -> Option<TypeId>
pub fn get_def_type_by_name( &self, interner: &Interner, name: &str, ) -> Option<TypeId>
Get the output type for a definition by string name.
Sourcepub fn iter_types(&self) -> impl Iterator<Item = (TypeId, &TypeShape)>
pub fn iter_types(&self) -> impl Iterator<Item = (TypeId, &TypeShape)>
Iterate over all interned types.
Sourcepub fn type_count(&self) -> usize
pub fn type_count(&self) -> usize
Number of interned types.
Sourcepub fn iter_def_types(&self) -> impl Iterator<Item = (DefId, TypeId)> + '_
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).
Sourcepub fn set_type_name(&mut self, type_id: TypeId, name: Symbol)
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).
Sourcepub fn get_type_name(&self, type_id: TypeId) -> Option<Symbol>
pub fn get_type_name(&self, type_id: TypeId) -> Option<Symbol>
Get the explicit name for a type, if any.
Sourcepub fn iter_type_names(&self) -> impl Iterator<Item = (TypeId, Symbol)> + '_
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
impl Clone for TypeContext
Source§fn clone(&self) -> TypeContext
fn clone(&self) -> TypeContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more