Repository navigation
Conversation
Adds the `baml.iter` namespace (Iterator/Iterable, Done sentinel, ArrayIterator/Range/Repeat sources, lazy adapters, and consumer methods), implemented in pure BAML. All `implements` blocks are IN-BODY (the out-of-body `implements<T> Iface for Class<T>` form does not yet dispatch correctly for inferred generic instantiations). Stacked on #3698 (thread inferred generic type args to callee frames), which fixes the core dispatch bug for in-body implementors. Working today (see crates/baml_tests/baml_src/ns_iter): ArrayIterator/Range sources, `collect`/`reduce`/`count`, and `chain`. Known-blocked (documented in the test file), each on a distinct compiler bug: - `.map()`/`.filter()`/`.filter_map()`/`.flat_map()` — adapter whose interface instantiation has a union error arg `Iterator<R, E | E2>` fails to subtype-coerce. - `.step_by()` — its `next()` uses a C-style `for` loop (separately buggy). - `[1,2,3].iter()` — the `T[]` blanket `implements` does not attach `.iter()`. Also adds `#![allow(clippy::iter_not_returning_iterator)]` in bex_vm's package_baml so the generated native glue for the BAML `iter()` method lints clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
Binary size checks passed✅ 7 passed
Generated by |
|
implemented |
What this adds
A pure-BAML
baml.iternamespace undercrates/baml_builtins2/baml_std/baml/ns_iter/:iter.baml—Donesentinel,Iterable<T, E>/Iterator<T, E> requires Iterable<T, E>interfaces, lazy adapter methods (map/filter/filter_map/flat_map/peekable/step_by/chain) and consumer methods (collect/reduce/count/some/every/find).utility.baml—ArrayIterator<T>,Range,Repeat<T>sources.adapters.baml—Map/Filter/FilterMap/FlatMap/Flatten/Peekable/StepBy/Chainadapter classes.All
implementsblocks are in-body. The out-of-bodyimplements<T> Iface for Class<T>form does not dispatch correctly for inferred generic instantiations (see Known issues), so everything is written in-body.Also adds
#![allow(clippy::iter_not_returning_iterator)]inbex_vm/src/package_baml— the BAMLiter()method generates native glue literally namediterreturningValue, which trips that lint on generated code.Status
Verified against this branch (
cargo test -p baml_tests --test baml_src, namespaceiter):✅ Working
ArrayIterator.new(...)andRange.new(...)sourcescollect,reduce,countchainThese pass because #3698 fixes inferred-generic type-arg threading for in-body implementors, and
Chain<T, E>implementsIterator<T, E>(no union error arg).❌ Blocked — each on a distinct, still-open compiler bug
.map()/.filter()/.filter_map()/.flat_map()Iterator<R, E | E2>— fails to subtype-coerce. Even an explicitMap<int,int,never,never>{}is rejected asIterator<int,never>. This is the main blocker for the closure adapters..step_by()next()uses a C-styleforloop, which is separately buggy in the VM.[1,2,3].iter()T[]blanketimplements(out-of-body, on a builtin array type) does not attach.iter()—type int[] has no member iter.implements<T> Iface for Class<T>+ inferred ctorThe blocked cases are kept in
ns_iter/iter.bamlas commented-out tests with the bug each waits on.Repro for the headline remaining bug
Minimal, verified repro for the union error-arg coercion issue is the natural failure of
it.map(f).collect(); the earlier inferred-static-ctor dispatch bug (now fixed by #3698) has a standalone repro in the task notes.Not done / out of scope here
for (let x in iterable)desugaring (TIR/MIR) — deferred.$rust_functionnext()+ForIteropcodes (perf) — deferred.next()for the closure adapters depends on the union-coercion fix first.🤖 Generated with Claude Code