Skip to content

feat(hydro_lang): add by_ref() singleton capture support to Stream::filter_map#2937

Closed
MingweiSamuel wants to merge 3 commits into
mingwei/handoff-refsfrom
mingwei/filtermap-ref
Closed

feat(hydro_lang): add by_ref() singleton capture support to Stream::filter_map#2937
MingweiSamuel wants to merge 3 commits into
mingwei/handoff-refsfrom
mingwei/filtermap-ref

Conversation

@MingweiSamuel

@MingweiSamuel MingweiSamuel commented Jun 11, 2026

Copy link
Copy Markdown
Member

Added with_singleton_capture wrapper to Stream::filter_map so that
SingletonRef values can be captured inside filter_map closures via
q!(), matching the existing support in map, filter, flat_map_ordered,
flat_map_unordered, partition, and inspect.

Co-authored-by: Infinity 🤖 infinity@hydro.run

MingweiSamuel and others added 2 commits June 10, 2026 21:56
Renamed internal terminology for consistency with DFIR's concept of
"handoffs" being the general inter-subgraph buffering mechanism:

- Module: `slot_ref` → `handoff_ref`
- Enum: `SlotKind` → `HandoffRefKind`
- Macro: `define_slot_ref!` → `define_handoff_ref!`
- Internal functions: `slot_ref_ident` → `handoff_ref_ident`,
  `register_ref` → `register_handoff_ref`

Public-facing type names remain unchanged (SingletonRef, OptionalRef, etc.).

Co-authored-by: Infinity 🤖 <infinity@hydro.run>

Add deploy integration tests and compile-fail test for handoff refs

Added deploy-and-run integration tests that verify actual runtime behavior:

- `hydro_test/src/local/optional_ref.rs`: 3 tests
  - test_optional_ref: by_ref on reduce result, unwrap_or in map
  - test_optional_ref_none: by_ref on empty optional, verifies None behavior
  - test_optional_ref_and_consume: by_ref with separate ref-only usage

- `hydro_test/src/local/stream_ref.rs`: 4 tests
  - test_stream_ref: by_ref on stream, read .len()
  - test_stream_ref_contents: by_ref, iterate and sum contents
  - test_stream_ref_no_consumer: by_ref with no pipe consumer
  - test_stream_mut: by_mut with .retain() mutation

Added compile-fail test:
- `stream_by_ref_unbounded.rs`: verifies that calling by_ref() on an
  unbounded stream produces a clear IsBounded error message

Also added a stageleft reexport for `core::iter::sources::*` → `std::iter`
to fix type path resolution for `std::iter::empty()` in codegen.

Co-authored-by: Infinity 🤖 <infinity@hydro.run>
PR: #2936
…nology

- Remove unused `hydro_lang::location::Location` import from
  `hydro_test/src/local/stream_ref.rs` and `hydro_test/src/local/optional_ref.rs`
- Fix misleading comment in `optional_ref.rs` test that said "fold" but code
  uses `reduce`
- Update all "slot reference" / "SlotRef" terminology in `handoff_ref.rs`
  comments and panic messages to use "handoff reference" / "HandoffRef" to
  match the public API names (SingletonRef, OptionalRef, StreamRef)

Co-authored-by: Infinity 🤖 <infinity@hydro.run>
PR: #2936
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 11, 2026

Copy link
Copy Markdown

Deploying hydro with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5e28c01
Status:🚫  Build failed.

View logs

@MingweiSamuel MingweiSamuel changed the title Add by_ref() singleton capture support to Stream::filter_map feat(hydro_lang): add by_ref() singleton capture support to Stream::filter_map Jun 11, 2026
Added `with_singleton_capture` wrapper to `Stream::filter_map` so that
`SingletonRef` values can be captured inside `filter_map` closures via
`q!()`, matching the existing support in `map`, `filter`, `flat_map_ordered`,
`flat_map_unordered`, `partition`, and `inspect`.

Co-authored-by: Infinity 🤖 <infinity@hydro.run>
PR: #2937
@MingweiSamuel MingweiSamuel force-pushed the mingwei/filtermap-ref branch from 0b8b972 to 5e28c01 Compare June 11, 2026 16:31
@MingweiSamuel MingweiSamuel changed the base branch from main to mingwei/handoff-refs June 11, 2026 16:31
@MingweiSamuel MingweiSamuel marked this pull request as ready for review June 11, 2026 16:32
Copilot AI review requested due to automatic review settings June 11, 2026 16:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds by_ref()/SingletonRef capture support for Stream::filter_map closures (via q!()), aligning filter_map with other Stream combinators that already support reference capture.

Changes:

  • Wrap Stream::filter_map’s closure splicing in a singleton/reference capture scope.
  • Adjust closure preparation in filter_map to support capturing SingletonRef values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +921 to +923
let f = crate::singleton_ref::with_singleton_capture(|| {
f.splice_fn1_ctx(&self.location).into()
});
Comment on lines 917 to +923
pub fn filter_map<U, F>(self, f: impl IntoQuotedMut<'a, F, L>) -> Stream<U, L, B, O, R>
where
F: Fn(T) -> Option<U> + 'a,
{
let f = f.splice_fn1_ctx(&self.location).into();
let f = crate::singleton_ref::with_singleton_capture(|| {
f.splice_fn1_ctx(&self.location).into()
});
@MingweiSamuel MingweiSamuel force-pushed the mingwei/handoff-refs branch 3 times, most recently from 8394943 to d7147bf Compare June 11, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants