feat(hydro_lang): add sim_atomic_input with scheduler support#2851
feat(hydro_lang): add sim_atomic_input with scheduler support#2851shadaj wants to merge 1 commit into
Conversation
d30aa7d to
0826e9f
Compare
Deploying hydro with
|
| Latest commit: |
023ed3b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8474d9ae.hydroflow.pages.dev |
| Branch Preview URL: | https://sandbox-15952e72-fc63-4b8e-a.hydroflow.pages.dev |
dd3fe00 to
87ae805
Compare
87ae805 to
0022399
Compare
There was a problem hiding this comment.
Pull request overview
Adds Process::sim_atomic_input() for the Hydro simulator, returning a SimAtomicSender paired with a Stream whose source is placed directly inside an Atomic<Process> location. A new AtomicSourceHook lets the scheduler treat pending atomic-input items as a non-trivial reason to advance the tick, enabling exhaustive exploration of both same-tick and later-tick interleavings between the atomic input and other inputs. Existing request_response tests are ported off the ack pattern to the simpler synchronous API.
Changes:
- New
SimAtomicSenderwrapper with synchronoussend_atomic/send_many_atomic[_unordered]methods. - New
AtomicSourceHookand dedicatedcreate_external_sourcebranch in the sim builder that buffers items at the root location and releases them into the tick graph via the hook. - New
Process::sim_atomic_inputconstructor andsim_atomic_input_same_tickregression test;hydro_std::request_responsetests migrated to the new API.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| hydro_lang/src/sim/mod.rs | Declares the SimAtomicSender wrapper type. |
| hydro_lang/src/sim/compiled.rs | Implements synchronous send_atomic / send_many*_atomic on SimAtomicSender. |
| hydro_lang/src/sim/runtime.rs | Adds AtomicSourceHook that drains all pending items on each scheduler decision. |
| hydro_lang/src/sim/builder.rs | Special-cases LocationId::Atomic in create_external_source to install the hook and bridge buffer→tick. |
| hydro_lang/src/location/process.rs | Adds Process::sim_atomic_input constructing an ExternalInput directly at the Atomic location. |
| hydro_lang/src/location/tick.rs | Adds sim_atomic_input_same_tick regression test asserting both interleavings are explored. |
| hydro_std/src/request_response.rs | Ports four tests from the ack pattern to sim_atomic_input / send_atomic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| input: #buffered_ident.clone(), | ||
| to_release: None, | ||
| output: #hoff_send_ident, | ||
| format_item_debug: |_| None, |
| /// | ||
| /// The source is placed directly inside the atomic tick, so sent values | ||
| /// are immediately available in the next atomic slice without requiring | ||
| /// a separate tick to batch them in. `send_atomic` is synchronous. |
There was a problem hiding this comment.
I think this description would benefit from a motivating example. I think this will be a likely discovery point for people/agents. Why exactly would you use this over sim_input.
| /// are immediately available in the next atomic slice without requiring | ||
| /// a separate tick to batch them in. `send_atomic` is synchronous. | ||
| #[expect(clippy::type_complexity, reason = "stream markers")] | ||
| pub fn sim_atomic_input< |
Places the ExternalInput source directly at the Atomic location and adds an AtomicSourceHook that signals readiness when items are pending. This allows the sim scheduler to explore both orderings: the batch for the regular input being non-empty on the first tick (same tick as atomic write) or empty (read comes in a later tick). send_atomic is synchronous — values are immediately available in the next atomic slice without requiring a separate tick or ack pattern. Closes #2380 PR: #2851
0022399 to
023ed3b
Compare
Summary
Adds
Process::sim_atomic_input()which returns aSimAtomicSender<T, O, R>and aStream<T, Atomic<Process>, ...>. The sender'ssend_atomicmethod is synchronous — values are immediately available in the next atomic slice without requiring a separate tick or ack pattern.The sim scheduler now properly explores both orderings when an atomic input and a regular input are sent together.
Implementation
Source placement: The
ExternalInputnode is placed directly at theAtomiclocation (not at the top-level process with a batch into the tick).AtomicSourceHook: A new sim hook type that monitors the external input channel. When items are pending,
can_make_nontrivial_decision()returnstrue, which forces the scheduler to consider the tick as ready. On release, all pending items are emitted (no batching choice).Scheduler integration: The hook is registered in
create_external_sourcewhen the source location isAtomic. Items from the external channel are buffered at the process level and released into the tick graph via the hook.Usage
Tests
sim_atomic_input_api: verifies basic send + scheduler explores both orderings (2 instances)sim_atomic_input_same_tick: verifies the scheduler explores the same-tick scenariorequest_responsetests inhydro_stdto use the new APICloses #2380