Expand description
Type and value assertion nodes.
Polydat’s runtime contract: node eval trusts its inputs. Bad input
panics, by design, because the hot path stays branch-free. The
“guarded” version of a node that would otherwise panic is built
as an assembly of two functions — the original node, and an
assertion node spliced in front of one of its inputs. The assertion runs the
check; the downstream node still trusts its inputs.
Two families:
-
Type assertions — one per supported
PortType. They confirm the runtimeValuevariant matches the static port type and pass it through. The compiler inserts none: wires are statically typed, and a resolved wire’s type is the sink port’s type, so a runtime type check has nothing to catch. -
Value assertions — one per
PortType, parameterised by aConstConstraint. Pass the value through if the constraint holds, otherwise panic with a structured message. The same vocabulary the const-constraint metadata uses onParamSpecis reused onPortand on these nodes.
The compiler inserts value assertions under pragma strict_values
(graph_compiler.md §2). Neither family is callable from Polydat
source (library_catalog.md, the hand-written-impl carve-outs).
Structs§
- Assert
Type - Pass-through guard that confirms the runtime value variant
matches a declared
PortType. Panics on mismatch. - Assert
Value - Runtime value-constraint guard. Holds a
ConstConstraintthe value must satisfy each cycle. Panics with a structured message on violation; passes the value through otherwise.
Functions§
- assert_
type_ node - Construct the right type assertion node for a given
PortType. The compiler inserts none: a resolved wire’s type is the sink port’s type (graph_compiler.md §2). - assert_
value_ node - Construct a value assertion node for the given (type, constraint) pair.
- check_
value - Check
valueagainstconstraint, naming the checked valuenamein the message.Nonewhen the value’s variant is one the constraint vocabulary has no reading of (anything butU64,F64andStr). - describe_
constraint - The condition
constraintstates, in words, for diagnostics. - same_
constraint - Whether two constraints state the same condition. A parser constraint equals another only when both name the same function.