Skip to main content

RegistryBuilder

Struct RegistryBuilder 

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

Mutable builder for constructing a Registry.

Used during IR lowering and prelude loading. Call build() to produce an immutable Registry.

Implementations§

Source§

impl RegistryBuilder

Source

pub fn new() -> Self

Source

pub fn build(self) -> Registry

Freeze the builder into an immutable Registry.

Source

pub fn register_dag(&mut self, name: DeclName, decl: DagDecl)

Register a dag declaration body keyed by the declaration’s name.

Accessed later during dim-checking of inline @dag(args).out expressions.

Source

pub fn merge_from_registry(&mut self, parent: &Registry)

Merge every entry from a frozen Registry into this builder.

Used by inline-dag compilation: the dag body is lowered as a virtual file whose registry is seeded with the enclosing file’s dimensions, units, indexes, types, and sibling dags so that reference resolution and type checking behave as if the dag body were declared inline at the top level.

Source

pub fn mark_affine_prone(&mut self, id: BaseDimId)

Register a new base dimension (base dim Foo;).

The caller provides the BaseDimId which encodes the dimension’s identity (prelude name or user-defined file+name). Mark a base dimension as affine-prone: its real-world units (e.g. Celsius/Fahrenheit on Temperature) need offset conversions that unit definitions cannot express, so user unit definitions on the bare dimension are rejected (#648 U4).

Source

pub fn is_affine_prone(&self, dim: &Dimension) -> bool

Returns true when dim is exactly an affine-prone base dimension (power 1). Compound dimensions involving the base (e.g. Temperature / Time) stay allowed: offsets cancel in differences.

Source

pub fn register_base_dimension( &mut self, name: DimName, id: BaseDimId, ) -> BaseDimId

Source

pub fn register_base_dimension_with_symbol( &mut self, name: DimName, id: BaseDimId, symbol: String, ) -> BaseDimId

Register a new base dimension with an SI symbol.

Same as register_base_dimension but also records the default unit symbol used for runtime display (e.g., "m" for Length).

Source

pub fn set_base_dim_symbol(&mut self, id: BaseDimId, symbol: String)

Record an SI symbol for an existing base dimension.

Used when the first base unit for a user-defined dimension is declared (e.g., base unit bit: Information; records "bit" as the symbol).

Source

pub fn register_dimension(&mut self, name: DimName, dim: Dimension)

Register a named dimension.

Source

pub fn register_unit( &mut self, name: impl Into<UnitRef>, dimension: Dimension, scale: PositiveFiniteScale, )

Register a named unit with its dimension and SI scale factor.

Source

pub fn register_unit_with_scale( &mut self, name: impl Into<UnitRef>, dimension: Dimension, scale: UnitScale, constness: UnitConstness, )

Register a named unit with an explicitly specified scale and constness.

Source

pub fn register_unit_dynamic( &mut self, name: impl Into<UnitRef>, dimension: Dimension, scale: UnitScale, )

Register a named runtime unit with a static or dynamic scale factor.

Source

pub fn register_type(&mut self, def: TypeDef)

Register a type definition.

For tagged unions (the common case), also populates the constructor namespace: each variant’s name resolves back to the union it belongs to. Constructor collisions are detected here — the prelude is loaded first, so any later user-defined constructor that collides with a prelude or sibling type’s constructor is silently ignored on the second registration (consistent with the type-name “first wins” behavior).

Source

pub fn register_index(&mut self, def: IndexDef)

Register an index definition.

Source

pub fn ensure_nat_range_index(&mut self, size: NonZeroUsize) -> NatRangeIndex

Ensure a typed Nat range index of the given size is registered.

If the index already exists, this is a no-op.

size is NonZeroUsize because empty indexes are not representable. AST-level u64 literals must be checked at the boundary before reaching this entry point.

Source

pub fn get_dimension(&self, name: &str) -> Option<&Dimension>

Look up a dimension by name.

Source

pub fn get_unit(&self, name: &UnitRef) -> Option<&UnitInfo>

Look up a unit by name.

Source

pub fn all_units( &self, ) -> impl Iterator<Item = (&UnitRef, &Dimension, &UnitScale)>

Iterate over all units: (reference, dimension, scale).

Source

pub fn get_type(&self, name: &str) -> Option<&TypeDef>

Look up a type definition by type name.

Source

pub fn get_index(&self, name: &str) -> Option<&IndexDef>

Look up a declared index definition by name.

Source

pub fn get_nat_range(&self, index: NatRangeIndex) -> Option<&IndexDef>

Look up a compiler-generated Nat range index by typed identity.

Source

pub const fn base_dim_names(&self) -> &BTreeMap<BaseDimId, String>

Get the base dimension names map (for display purposes).

Source

pub const fn base_dim_symbols(&self) -> &BTreeMap<BaseDimId, String>

Get the base dimension symbols map for runtime display.

Source

pub fn format_dimension(&self, dim: &Dimension) -> String

Format a dimension as a human-readable string using registered base dimension names.

Prefers a named dimension alias for compound dimensions, like DimensionRegistry::format_dimension.

Source

pub fn resolve_dim_expr( &self, expr: &DimExpr, ) -> Result<Option<Dimension>, RationalError>

Resolve a DimExpr AST node to a concrete Dimension.

Returns Ok(None) if any dimension name is unknown, and Err if dimension exponent arithmetic overflows i32.

Source

pub fn resolve_type_expr( &self, type_expr: &TypeExpr, ) -> Result<Option<Dimension>, RationalError>

Resolve a TypeExpr to a concrete Dimension.

Returns Ok(None) if the type references unknown dimensions, and Err if dimension exponent arithmetic overflows i32.

Source

pub fn resolve_unit_expr( &self, expr: &UnitExpr, ) -> Result<(Dimension, f64), UnitResolveError>

Resolve a UnitExpr to its dimension and compound static scale factor.

§Errors

Returns a UnitResolveError naming the unknown or dynamic-scale unit, or the exponent overflow.

Source

pub fn resolve_unit_dimension( &self, expr: &UnitExpr, ) -> Result<Dimension, UnitResolveError>

Resolve a UnitExpr to its dimension only (ignoring scales).

Works for both static and dynamic units.

§Errors

Returns a UnitResolveError naming the unknown unit, or the exponent overflow.

Trait Implementations§

Source§

impl Debug for RegistryBuilder

Source§

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

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

impl Default for RegistryBuilder

Source§

fn default() -> RegistryBuilder

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> 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, 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.