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. 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. 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 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 and 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§

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. 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 value against constraint, naming the checked value name in the message. None when the value’s variant is one the constraint vocabulary has no reading of (anything but U64, F64 and Str).
describe_constraint
The condition constraint states, 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.