Skip to main content

Module assertions

Module assertions 

Source
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 (SRD 15 §“Type and Value Assertion Nodes”). The assertion runs the check; the downstream node still trusts its inputs.

Two families:

  • Type assertions — one per supported PortType. They confirm the runtime Value variant matches the static port type and pass it through. Useful when provenance can’t prove the wire already carries the right type (dynamic JSON navigation, Ext unwraps, cross-adapter values).

  • Value assertions — one per PortType, parameterised by a ConstConstraint. Pass the value through if the constraint holds, otherwise panic with a structured message. The same vocabulary the const-constraint metadata uses on ParamSpec is reused on Port (SRD 15 §“Strict Wire Mode”) and on these nodes.

Auto-insertion is the compiler’s job (M2 §“Strict Wire Mode”) — these nodes are also user-callable from Polydat source for ad-hoc guards.

Structs§

AssertType
Pass-through guard that confirms the runtime value variant matches a declared PortType. Panics on mismatch.
AssertValue
Runtime value-constraint guard. Holds a ConstConstraint the 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.
assert_value_node
Construct a value assertion node for the given (type, constraint) pair.