feat(units): uom-backed newtypes + dim currency for typed math #37
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "patman/uom-units"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What this does
Establishes a two-layer typed-units architecture, motivated by the upcoming (heavily AI-assisted) CAM build-out: compile-time dimensional analysis catches structurally-wrong equations (
m/s + m, bad derivative chains) that tests only catch case-by-case.common::types::units:Length,Velocity, …) — wrap a uomQuantity(SI storage), stay operator-free with explicitfrom_*/as_*and CNC unit I/O (from_rpm,from_thou). Used for storage and edges (.roo/config/serialized state, public API).dimcomputation currency (new module re-exporting uom quantities) — full dimension-checked arithmetic for the math/CAM/kinematics layer (Length / Time → Velocity;m/s + mwon't compile).to_uom()/from_uom()bridge on every scalar (the newtype wraps exactly thedimquantity, so conversion is a field move).f64(SI) in dirac — nalgebra needs the scalar closed under*, andLength*Length=Areabreaks that. uom guards scalar formulas and kernel seams, not interiors. Documented as a caveat.docs/dev-tips/uom.md(zensical) as the guardrail doc for CAM agents.diracuntouched.Background
Replaces the original "uom hidden, no operators" framing of this PR. An adversarial review correctly noted that the opaque newtype gave no dimensional checking (no arithmetic). With CAM next and AI-driven, the fix is to expose uom as the computation currency rather than revert — this PR does that.
Stack position
PR 2 of 2. Based on #36 (wait-timeout lint fix), required so tests can run.
Verification
buck2 build //common:commongreen;buck2 test //common:common-tests→ 85 passed, including a newcurrency_arithmetic_is_dimension_checkedtest exercisingLength / Time → Velocitythrough the bridge.Review focus
to_uom/from_uombridge (common/src/types/units/{mod.rs,dim.rs}).si()struct-literal construction keepingconstconstructors (depends on uom field visibility — documented; loud failure if uom closes them).6a34c20634to50c340455bfeat(units): back unit newtypes with uom for dimensional checkingto feat(units): uom-backed newtypes + dim currency for typed math50c340455btoda93205d56Hardened after a second adversarial review (force-pushed):
AngleKindlimitation (the angular chain needs.into()) acrossdim.rs,mod.rs, CLAUDE.md, anddocs/dev-tips/uom.md— previously the docs overstated "operators just work".dimnow re-exports base SI units (dim::unit) so the currency is self-contained.dim::Lengthvs newtypeLengthcollision rule (never glob both).compile_faildoctest form/s + mand a passing angular-chain (.into()) test; re-scoped the misleading "dimension-checked" test comment.implblocks per scalar.Note: the
compile_faildoctest documents the negative case but is not executed by the buck2rust_testtarget (doctests aren't run there). Hard CI enforcement of compile-fail would need atrybuilddev-dep — deferred pending dep approval. Typed angular helpers split into #38.