pub struct TypeManager { /* private fields */ }Expand description
The type registry: a global, append-only table of TypeId identities behind a
RwLock so that types can be minted through a shared & reference (a
prerequisite for running function passes in parallel against a shared
ContextView). Reads — including the get_or_make_* hit path — take a read
lock; only a cache miss takes the write lock (and re-checks under it).
Interned TypeIds are globally stable and never remapped.
Implementations§
Source§impl TypeManager
impl TypeManager
pub fn new() -> Self
pub fn get_or_make_int(&self, size: usize) -> TypeId
pub fn get_or_make_bool(&self) -> TypeId
pub fn get_or_make_space_address( &self, size: usize, space: impl Into<MemorySpaceId>, ) -> TypeId
Sourcepub fn get_or_make_aggregate(&self, fields: Vec<TypeId>) -> TypeId
pub fn get_or_make_aggregate(&self, fields: Vec<TypeId>) -> TypeId
Returns the TypeId for an AggregateType with default field names
(field1, field2, …), creating it if it does not yet exist.
pub fn get_or_make_named_aggregate(&self, fields: Vec<AggregateField>) -> TypeId
Sourcepub fn create_function_return(
&mut self,
owner: FunctionId,
fields: Vec<AggregateField>,
) -> Result<TypeId, String>
pub fn create_function_return( &mut self, owner: FunctionId, fields: Vec<AggregateField>, ) -> Result<TypeId, String>
Create a fresh nominal return-record type owned by owner.
This never structurally deduplicates: identical records owned by two functions receive distinct TypeIds. Exclusive access confines publication to a module barrier; function passes will eventually return this request as an effect for the driver to apply through the same API.
Sourcepub fn edit_function_return(
&mut self,
owner: FunctionId,
fields: Vec<AggregateField>,
) -> Result<TypeId, String>
pub fn edit_function_return( &mut self, owner: FunctionId, fields: Vec<AggregateField>, ) -> Result<TypeId, String>
Replace an owned return record’s fields while preserving its TypeId. Readers that began before this exclusive barrier retain the previous published declaration; subsequent reads observe the replacement.
Sourcepub fn create_requested_types(
&mut self,
requests: &[TypeRequest],
) -> Vec<TypeId>
pub fn create_requested_types( &mut self, requests: &[TypeRequest], ) -> Vec<TypeId>
Create a batch of types requested by function passes, in request order,
then publish one new read generation. This is the module-barrier creation
path; workers only use the corresponding get_* accessors.
pub fn get_or_make_struct( &self, name: impl Into<String>, size: usize, fields: Vec<AggregateField>, ) -> TypeId
pub fn get_or_make_struct_pointer(&self, size: usize, pointee: TypeId) -> TypeId
pub fn get_or_make_code_pointer(&self, size: usize) -> TypeId
Sourcepub fn get_struct_pointer(&self, size: usize, pointee: TypeId) -> Option<TypeId>
pub fn get_struct_pointer(&self, size: usize, pointee: TypeId) -> Option<TypeId>
Access an already-published struct-pointer type without creating state.
Sourcepub fn get_named_aggregate(&self, fields: &[AggregateField]) -> Option<TypeId>
pub fn get_named_aggregate(&self, fields: &[AggregateField]) -> Option<TypeId>
Access an already-published structural aggregate without creating state.
pub fn get_or_make_array(&self, elem: TypeId, count: usize) -> TypeId
Sourcepub fn get_array(&self, elem: TypeId, count: usize) -> Option<TypeId>
pub fn get_array(&self, elem: TypeId, count: usize) -> Option<TypeId>
Access an already-published array type without creating shared state.
Sourcepub fn get_list(&self, elem: TypeId, bound: Option<usize>) -> Option<TypeId>
pub fn get_list(&self, elem: TypeId, bound: Option<usize>) -> Option<TypeId>
Access an already-published list type without creating shared state.
Sourcepub fn get_seq(&self, elem: TypeId, len: usize, is_list: bool) -> Option<TypeId>
pub fn get_seq(&self, elem: TypeId, len: usize, is_list: bool) -> Option<TypeId>
Access an already-published sequence type of the requested kind.
pub fn get_or_make_list(&self, elem: TypeId, bound: usize) -> TypeId
pub fn get_or_make_unbounded_list(&self, elem: TypeId) -> TypeId
pub fn binop_result(&self, lhs: TypeId, op: Binop, rhs: TypeId) -> TypeId
pub fn bool_id(&self) -> Option<TypeId>
Sourcepub fn get_int(&self, size: usize) -> TypeId
pub fn get_int(&self, size: usize) -> TypeId
Access an already-published canonical integer type.
Function passes use this instead of silently creating shared state. A missing width means the pass failed to derive its type from published IR.
pub fn struct_by_name(&self, name: &str) -> Option<TypeId>
pub fn function_return(&self, owner: FunctionId) -> Option<TypeId>
pub fn is_bool(&self, id: TypeId) -> bool
pub fn function_return_owner(&self, id: TypeId) -> Option<FunctionId>
pub fn size_of(&self, id: TypeId) -> usize
pub fn space_of(&self, id: TypeId) -> Option<MemorySpaceId>
pub fn pointee_of(&self, id: TypeId) -> Option<TypeId>
pub fn array_of(&self, id: TypeId) -> Option<(TypeId, usize)>
pub fn list_of(&self, id: TypeId) -> Option<(TypeId, Option<usize>)>
pub fn seq_of(&self, id: TypeId) -> Option<(TypeId, usize, bool)>
pub fn seq_elem_of(&self, id: TypeId) -> Option<TypeId>
pub fn type_name(&self, id: TypeId) -> String
pub fn field_type(&self, id: TypeId, index: usize) -> Option<TypeId>
pub fn field_index(&self, id: TypeId, name: &str) -> Option<usize>
Sourcepub fn published_len(&self) -> usize
pub fn published_len(&self) -> usize
The number of published types.
Lock-free, and monotonic because type identities are never removed, so a consumer can use it as a cheap “has anything been added” probe before paying for a question that needs the lock.
Sourcepub fn has_sequence_types(&self) -> bool
pub fn has_sequence_types(&self) -> bool
Whether any array or list type has been created in this module.
Answers “could any value here be sequence-typed” in one step, without
inspecting a value. An interpreter uses it to skip a per-operand type
query entirely on the overwhelmingly common modules that contain no
sequences at all. Takes the lock, so pair it with
published_len rather than calling it per access.
Sourcepub fn get(&self, id: TypeId) -> &dyn Type
pub fn get(&self, id: TypeId) -> &dyn Type
Returns a reference to the concrete Type for id.
The lookup loads one immutable published index generation and takes no
lock. The reference remains valid across later publications because the
TypeIds are never removed, and each published Box<dyn Type> pointee is
heap-allocated and never moved or freed, including superseded owned
declarations retained for older generations.