Add mapr: short-circuit Result propagation across map#296
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
f182f12 to
d0f8b1c
Compare
Derives the outer Result shape from the callback's return type, rejects non-fn first args (ILO-T013), and rejects callbacks that don't return a Result with a hint to use map for non-fallible fns.
For each item the callback must return ~v or ^e. On ~v the inner value is accumulated; on ^e the whole call returns that ^e immediately, skipping the rest of the list. Final return on the all-Ok path is ~(L b). A callback that returns anything else surfaces ILO-R009.
Adds (Builtin::Mapr, 2) to is_tree_bridge_eligible and Mapr to tree_bridge_returns_result. VM and Cranelift dispatch the HOF via the same ACTIVE_AST_PROGRAM path grp/uniqby/partition/srt use; the bridge unwrap epilogue handles ! propagation on the Result return.
Pins the all-Ok, empty, head/mid/tail Err short-circuit, ! propagation, and user-fn dispatch cases across tree, VM, and Cranelift. Plus verifier rejections for non-fn first arg, non-Result callback, and wrong arity.
Demonstrates the persona-relevant scenarios: ~[list] on the all-Ok path, first ^err short-circuit, ! propagation into the surrounding fn, and the trivial empty case. Pulled into examples_engines harness so every engine validates the contract.
Adds the mapr row to the builtins table in SPEC.md, the token-dense ai.txt context line, and the HOF section in skills/ilo/SKILL.md with the persona-facing motivation (retires the ton helper).
d0f8b1c to
723cbb8
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.
Summary
Adds a new HOF
mapr fn xs : R (L b) ethat callsfnon each item, accumulates the inner Ok values on the all-Ok path, and short-circuits on the first Err. Mirrors Rust'scollect::<Result<Vec<_>, _>>()pattern.Originating friction:
ilo_assessment_feedback.mdline 2541 (html-scraper rerun3). The personas kept writing:maprcollapses both lines to one and preserves the err shape:Pair with
!to thread the err up into a Result-returning caller without per-item match boilerplate. The assessment doc says this "would remove thetonhelper entirely" across every CSV/HTML-parsing program.Repro before/after
Before:
After:
Tree, VM, and Cranelift all agree byte-for-byte.
What's in the diff (per-commit)
builtins: register mapr discriminant, name, and tag(b1ec0fa) - enum variant, name table both directions, ALL list, round-trip test fixtures.parser: mapr takes a fn-ref in slot 0 like other HOFs(5955b96) - parser knows to keep the first arg as a fn-ref (parallel tomap,flt,flatmap).verify: type mapr as R (L b) e from fn return R b e(2a86130) - derives the outer Result shape from the callback. Rejects non-fn first args and callbacks that don't return Result withILO-T013plus a hint to usemapfor non-fallible fns.interpreter: implement mapr short-circuit Result propagation(6a41689) - tree-walker arm.vm: route mapr through the tree bridge on VM and Cranelift(0c2be43) -(Builtin::Mapr, 2)joinsgrp/uniqby/partition/srtinis_tree_bridge_eligible, andtree_bridge_returns_resultincludesMaprso!propagation works.test: cross-engine regression coverage for mapr(b645194) - 11 cross-engine cases covering happy path, empty, head/mid/tail Err,!propagation, user-fn dispatch, and verifier rejections.example: mapr happy/bail/bang/empty paths(546f081) -examples/mapr.ilopicked up by theexamples_enginesharness.docs: document mapr in SPEC, ai.txt, and SKILL(95c59b5) - in-repo docs. Site reference is updated in ilo-lang/site#docs/mapr-builtin.Test plan
cargo test --release --features cranelift --test regression_mapr(11 tests, all engines)cargo test --release --features cranelift --test examples_engines(mapr.ilo runs across tree + vm with bothoutanderrassertions)cargo test --release --features cranelift(full suite green; AOT tests needtarget/release/libilo.a, which is the standard CI layout)cargo clippy --release --features cranelift --all-targets -- -D warningscargo fmt --allFollow-ups
mapr fn ctx xs) deliberately omitted; will add if a workload turns up that needs it.ilo-lang/siteon branchdocs/mapr-builtin.