Skip to content

vm + cranelift: closure-bind HOF ctx forms via tree-bridge#280

Merged
danieljohnmorris merged 3 commits into
mainfrom
fix/hof-3c-closure-bind
May 15, 2026
Merged

vm + cranelift: closure-bind HOF ctx forms via tree-bridge#280
danieljohnmorris merged 3 commits into
mainfrom
fix/hof-3c-closure-bind

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

PR 3c in the HOF dispatch chain. The closure-bind variants of map, flt, fld, and srt (the 3-arg / 4-arg forms that thread an extra ctx value into every fn invocation) now run on VM and Cranelift, not just the tree interpreter.

Builds on #277 (native map), #278 (native flt / fld / flatmap), and #279 (tree-bridge for grp / uniqby / partition / 2-arg srt).

Repro

Before, this program errored on VM/Cranelift with UndefinedFunction because the dispatcher had no path for ctx-bearing HOFs:

look sym:t m:M t n>n;r=mget m sym;?r{n v:v;_:0}
prices pm:M t n syms:L t>L n;map look pm syms

main>L n;m=mset mmap "a" 10;m=mset m "b" 20;prices m ["a","b","a"]

After, all three engines produce [10, 20, 10].

What's in the diff

  • vm: route closure-bind HOF ctx forms through tree-bridge adds (Map, 3), (Flt, 3), (Fld, 4), (Srt, 3) to is_tree_bridge_eligible. The existing 2-arg native arms short-circuit first, so the common shape still wins on the fast loop. Only the closure-bind forms pay the bridge round-trip, the same cost as 2-arg srt from PR 3b.
  • test: cross-engine coverage for closure-bind HOF variants lifts the four happy-path tests in regression_closure_bind.rs (srt-by-lookup, map-with-lookup, flt-with-threshold, fld-with-external-accumulator) to run via run_all across tree, vm, and cranelift. Verifier-error tests stay tree-only because verify is engine-independent.
  • example: lift vm/cranelift skip from closure-bind.ilo removes the two engine-skip directives. jit skip stays because jit lacks HOF dispatch entirely.

Test plan

  • cargo test --release --features cranelift --test regression_closure_bind (8 passed)
  • cargo test --release --features cranelift --test examples_engines (1 passed; closure-bind.ilo now exercised on vm + cranelift)
  • cargo test --release --features cranelift full suite (2932 + every integration suite green)
  • cargo fmt --check
  • cargo clippy --release --features cranelift --all-targets -- -D warnings

Follow-ups

  • PR 3d: direct FnRef-variable calls (f = dbl; f 10) lifted to OP_CALL_DYN from Expr::Call.
  • PR 4: lift engine-skip: vm/cranelift from inline-lambda examples, now that FnRef + HOF dispatch work everywhere.

The 3-arg ctx variants of map/flt/srt and 4-arg fld weren't lifted to
VM/Cranelift in the earlier HOF chain. Adding them to
is_tree_bridge_eligible reuses the same path PR 3b set up for grp,
uniqby, partition, and 2-arg srt: the bridge passes the args straight
to call_builtin_for_bridge_with_program, which the tree interpreter
handles end-to-end.

The native 2-arg arms for map/flt/fld short-circuit before this check,
so their fast loops still win on the common shape. Only the closure-bind
forms pay the bridge round-trip, which is the same cost as 2-arg srt.
The four happy-path tests (srt with external lookup, map with lookup,
flt with threshold, fld with external accumulator) now run on tree,
vm, and cranelift via run_all. The verifier-error tests stay tree-only
because verify runs before dispatch and produces the same diagnostic
on every engine.
vm and cranelift now run closure-bind via the tree-bridge. jit still
lacks HOF dispatch entirely (per regression_builtins_as_hof.rs) so
its skip stays.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@danieljohnmorris danieljohnmorris merged commit e533545 into main May 15, 2026
5 checks passed
@danieljohnmorris danieljohnmorris deleted the fix/hof-3c-closure-bind branch May 15, 2026 15:11
danieljohnmorris added a commit that referenced this pull request May 15, 2026
- slc / take / drop accept negative indices counting from end (bounds
  clamp), matching at xs i. Closes the quant-trader fencepost and the
  slc xs -np 1 np ergonomics gap (#266).
- Map keys are typed: text or integer. mset m 7 v and mget m 7 work
  directly, no str conversion. Int(1) and Text("1") are distinct.
  Float keys floor to i64; jdmp stringifies numeric keys for JSON (#267).
- Add map / flt / fld to the builtin reference. All HOFs (map, flt,
  fld, srt, grp, uniqby, partition, flatmap) now work cross-engine
  on tree, VM, Cranelift JIT, and AOT (#274 #277 #278 #279 #280 #283).
- New Inline lambdas subsection: Phase 1 literals are cross-engine,
  Phase 2 closure capture is tree-only with automatic fallthrough
  surfacing ILO-R012 on VM and Cranelift (#265 #284).
- AOT-compiled binaries from ilo compile now strip the top-level
  ~/^ wrapper byte-for-byte the same as in-process runners (#281).
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.

1 participant