Skip to main content

TypeManager

Struct TypeManager 

Source
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

Source

pub fn new() -> Self

Source

pub fn get_or_make_int(&self, size: usize) -> TypeId

Source

pub fn get_or_make_bool(&self) -> TypeId

Source

pub fn get_or_make_space_address( &self, size: usize, space: impl Into<MemorySpaceId>, ) -> TypeId

Source

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.

Source

pub fn get_or_make_named_aggregate(&self, fields: Vec<AggregateField>) -> TypeId

Source

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.

Source

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.

Source

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.

Source

pub fn get_or_make_struct( &self, name: impl Into<String>, size: usize, fields: Vec<AggregateField>, ) -> TypeId

Source

pub fn get_or_make_struct_pointer(&self, size: usize, pointee: TypeId) -> TypeId

Source

pub fn get_or_make_code_pointer(&self, size: usize) -> TypeId

Source

pub fn get_struct_pointer(&self, size: usize, pointee: TypeId) -> Option<TypeId>

Access an already-published struct-pointer type without creating state.

Source

pub fn get_named_aggregate(&self, fields: &[AggregateField]) -> Option<TypeId>

Access an already-published structural aggregate without creating state.

Source

pub fn get_or_make_array(&self, elem: TypeId, count: usize) -> TypeId

Source

pub fn get_array(&self, elem: TypeId, count: usize) -> Option<TypeId>

Access an already-published array type without creating shared state.

Source

pub fn get_list(&self, elem: TypeId, bound: Option<usize>) -> Option<TypeId>

Access an already-published list type without creating shared state.

Source

pub fn get_seq(&self, elem: TypeId, len: usize, is_list: bool) -> Option<TypeId>

Access an already-published sequence type of the requested kind.

Source

pub fn get_or_make_list(&self, elem: TypeId, bound: usize) -> TypeId

Source

pub fn get_or_make_unbounded_list(&self, elem: TypeId) -> TypeId

Source

pub fn get_or_make_seq(&self, elem: TypeId, len: usize, is_list: bool) -> TypeId

Build the sequence type of the given kind: a List when is_list, else a fixed Array. The inverse of seq_of.

Source

pub fn binop_result(&self, lhs: TypeId, op: Binop, rhs: TypeId) -> TypeId

Source

pub fn bool_id(&self) -> Option<TypeId>

Source

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.

Source

pub fn get_bool(&self) -> TypeId

Access the already-published canonical boolean type.

Source

pub fn struct_by_name(&self, name: &str) -> Option<TypeId>

Source

pub fn function_return(&self, owner: FunctionId) -> Option<TypeId>

Source

pub fn is_bool(&self, id: TypeId) -> bool

Source

pub fn function_return_owner(&self, id: TypeId) -> Option<FunctionId>

Source

pub fn size_of(&self, id: TypeId) -> usize

Source

pub fn space_of(&self, id: TypeId) -> Option<MemorySpaceId>

Source

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

Source

pub fn array_of(&self, id: TypeId) -> Option<(TypeId, usize)>

Source

pub fn list_of(&self, id: TypeId) -> Option<(TypeId, Option<usize>)>

Source

pub fn seq_of(&self, id: TypeId) -> Option<(TypeId, usize, bool)>

Source

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

Source

pub fn type_name(&self, id: TypeId) -> String

Source

pub fn field_type(&self, id: TypeId, index: usize) -> Option<TypeId>

Source

pub fn field_index(&self, id: TypeId, name: &str) -> Option<usize>

Source

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.

Source

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.

Source

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.

Source

pub fn struct_name_of(&self, id: TypeId) -> Option<&str>

Source

pub fn aggregate_fields(&self, id: TypeId) -> Option<&[AggregateField]>

Source

pub fn field_by_offset( &self, id: TypeId, offset: usize, ) -> Option<(usize, &AggregateField)>

Source

pub fn field_name(&self, id: TypeId, index: usize) -> Option<&str>

Trait Implementations§

Source§

impl Clone for TypeManager

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for TypeManager

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for TypeManager

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TypeManager

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.