Expand description
Handle types for simulator hooks: scripting the decisions of unsafe operators.
Every unsafe operator (like Stream::batch or
Singleton::snapshot) takes a
NonDet guard. A guard can optionally carry a hook handle,
which lets a simulation test take manual control of the non-deterministic decision made
by that operator (which elements form the next batch, which version of a piece of state
a snapshot reveals, …). See hydro_lang::sim::hooks for the test-side scripting API.
Handles are created from the FlowBuilder via
FlowBuilder::sim_hook before the
program under test is constructed, and attached to the operator they control with the
nondet!(... hook = handle) syntax. Handles are small and Copy: the same value is
passed into the program during construction and used later inside the test body to
script decisions.
§Hook scopes
Every handle type carries a scope parameter naming the kind of root location the
hooked operator runs on, mirroring
Location::SimHookScope:
OnProcess<P>(the default): the operator has one instance, scripted directly.OnCluster<C>: every cluster member runs its own instance of the operator; select the one to script with.on(member_id), which yields anOnMember<C>-scoped handle.
Operators name the scope in their NonDet payload type, so scope mismatches fail to
compile.
This module contains only the handle types themselves (plain data), so components can
expose hookable signatures (e.g. nondet_batch: NonDet<Option<BatchHook<u32>>>, passed
directly to the batch operator it controls) without pulling
in any simulator machinery; binding a hook in a flow that is deployed rather than
simulated is harmless metadata that non-simulator backends ignore.
Structs§
- Batch
Hook - A hook handle controlling a
batchoperator over a stream ofTelements with orderingOand retry guaranteeR(mirroring the type of the stream being batched).Sis the handle’s scope. - Keyed
Batch Hook - A hook handle controlling a
batchoperator over a keyed stream with keysK, valuesV, per-key value orderingO, and retry guaranteeR(mirroring the type of the keyed stream being batched).Sis the handle’s scope. - Keyed
Merge Ordered Hook - A hook handle controlling a
merge_orderedoperator over keyed streams with keysKand valuesV.Sis the handle’s scope. - Keyed
Ordering Hook - A hook handle controlling an
assume_orderingoperator over a keyed stream with keysKand valuesV.Sis the handle’s scope. - Keyed
Snapshot Hook - A hook handle controlling a
snapshot(orbatch) operator over a keyed singleton with keysKand valuesV.Sis the handle’s scope. - Merge
Ordered Hook - A hook handle controlling a
merge_orderedoperator over streams ofTelements.Sis the handle’s scope. - OnCluster
- Hook scope marker: the hooked operator runs on a
Clusterwith tagC, so every member runs its own independent instance of the operator. - OnMember
- Hook scope marker: one selected member’s instance of an operator running on a
Clusterwith tagC, produced by.on(member_id). - OnProcess
- Hook scope marker: the hooked operator runs on a
Processwith tagPand has one instance, which the handle scripts directly. - Ordering
Hook - A hook handle controlling an
assume_orderingoperator overTelements.Sis the handle’s scope. - Partial
Ordering Hook - A hook handle controlling an
entries_partially_orderedoperator over a keyed stream with keysKand valuesV.Sis the handle’s scope. - Snapshot
Hook - A hook handle controlling a
snapshotoperator over a singleton ofT.Sis the handle’s scope.
Traits§
- Bindable
Hook Scope - Hook scopes a handle can be created and bound with:
OnProcessandOnCluster. Operator signatures select the scope throughLocation::SimHookScope. - Scriptable
Hook Scope - Hook scopes that name a single instance of the hooked operator and can therefore
script decisions and pauses:
OnProcessandOnMember. AnOnCluster-scoped handle must first select a member with.on(member_id). - SimHook
- A simulator hook handle (or a set of them) that can be created in one call to
FlowBuilder::sim_hook.