feat(hydro_lang): add by_ref() singleton capture support to Stream::filter_map#2937
Closed
MingweiSamuel wants to merge 3 commits into
Closed
feat(hydro_lang): add by_ref() singleton capture support to Stream::filter_map#2937MingweiSamuel wants to merge 3 commits into
by_ref() singleton capture support to Stream::filter_map#2937MingweiSamuel wants to merge 3 commits into
Conversation
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
by_ref() singleton capture support to Stream::filter_map
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
0b8b972 to
5e28c01
Compare
Contributor
There was a problem hiding this comment.
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_mapto support capturingSingletonRefvalues.
💡 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() | ||
| }); |
8394943 to
d7147bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
with_singleton_capturewrapper toStream::filter_mapso thatSingletonRefvalues can be captured insidefilter_mapclosures viaq!(), matching the existing support inmap,filter,flat_map_ordered,flat_map_unordered,partition, andinspect.Co-authored-by: Infinity 🤖 infinity@hydro.run