pub struct RegistryBuilder { /* private fields */ }Expand description
Implementations§
Source§impl RegistryBuilder
impl RegistryBuilder
pub fn new() -> Self
Sourcepub fn register_dag(&mut self, name: DeclName, decl: DagDecl)
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.
Sourcepub fn merge_from_registry(&mut self, parent: &Registry)
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.
Sourcepub fn mark_affine_prone(&mut self, id: BaseDimId)
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).
Sourcepub fn is_affine_prone(&self, dim: &Dimension) -> bool
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.
pub fn register_base_dimension( &mut self, name: DimName, id: BaseDimId, ) -> BaseDimId
Sourcepub fn register_base_dimension_with_symbol(
&mut self,
name: DimName,
id: BaseDimId,
symbol: String,
) -> BaseDimId
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).
Sourcepub fn set_base_dim_symbol(&mut self, id: BaseDimId, symbol: String)
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).
Sourcepub fn register_dimension(&mut self, name: DimName, dim: Dimension)
pub fn register_dimension(&mut self, name: DimName, dim: Dimension)
Register a named dimension.
Sourcepub fn register_unit(
&mut self,
name: impl Into<UnitRef>,
dimension: Dimension,
scale: PositiveFiniteScale,
)
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.
Sourcepub fn register_unit_with_scale(
&mut self,
name: impl Into<UnitRef>,
dimension: Dimension,
scale: UnitScale,
constness: UnitConstness,
)
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.
Sourcepub fn register_unit_dynamic(
&mut self,
name: impl Into<UnitRef>,
dimension: Dimension,
scale: UnitScale,
)
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.
Sourcepub fn register_type(&mut self, def: TypeDef)
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).
Sourcepub fn register_index(&mut self, def: IndexDef)
pub fn register_index(&mut self, def: IndexDef)
Register an index definition.
Sourcepub fn ensure_nat_range_index(&mut self, size: NonZeroUsize) -> NatRangeIndex
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.
Sourcepub fn get_dimension(&self, name: &str) -> Option<&Dimension>
pub fn get_dimension(&self, name: &str) -> Option<&Dimension>
Look up a dimension by name.
Sourcepub fn all_units(
&self,
) -> impl Iterator<Item = (&UnitRef, &Dimension, &UnitScale)>
pub fn all_units( &self, ) -> impl Iterator<Item = (&UnitRef, &Dimension, &UnitScale)>
Iterate over all units: (reference, dimension, scale).
Sourcepub fn get_index(&self, name: &str) -> Option<&IndexDef>
pub fn get_index(&self, name: &str) -> Option<&IndexDef>
Look up a declared index definition by name.
Sourcepub fn get_nat_range(&self, index: NatRangeIndex) -> Option<&IndexDef>
pub fn get_nat_range(&self, index: NatRangeIndex) -> Option<&IndexDef>
Look up a compiler-generated Nat range index by typed identity.
Sourcepub const fn base_dim_names(&self) -> &BTreeMap<BaseDimId, String>
pub const fn base_dim_names(&self) -> &BTreeMap<BaseDimId, String>
Get the base dimension names map (for display purposes).
Sourcepub const fn base_dim_symbols(&self) -> &BTreeMap<BaseDimId, String>
pub const fn base_dim_symbols(&self) -> &BTreeMap<BaseDimId, String>
Get the base dimension symbols map for runtime display.
Sourcepub fn format_dimension(&self, dim: &Dimension) -> String
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.
Sourcepub fn resolve_dim_expr(
&self,
expr: &DimExpr,
) -> Result<Option<Dimension>, RationalError>
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.
Sourcepub fn resolve_type_expr(
&self,
type_expr: &TypeExpr,
) -> Result<Option<Dimension>, RationalError>
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.
Sourcepub fn resolve_unit_expr(
&self,
expr: &UnitExpr,
) -> Result<(Dimension, f64), UnitResolveError>
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.
Sourcepub fn resolve_unit_dimension(
&self,
expr: &UnitExpr,
) -> Result<Dimension, UnitResolveError>
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.