Skip to content

feat: par-map builtin — general parallel fan-out (ILO-67)#610

Merged
danieljohnmorris merged 1 commit into
mainfrom
feature/par-map
May 22, 2026
Merged

feat: par-map builtin — general parallel fan-out (ILO-67)#610
danieljohnmorris merged 1 commit into
mainfrom
feature/par-map

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

  • Adds par-map fn xs [n] builtin: applies a function to each list element in parallel, up to n items at a time, returning L (R b t) in input order
  • Default concurrency = num_cpus; override with ILO_PAR_MAP_CONCURRENCY env var
  • Tree-walker implementation via std::thread::scope + chunked batches (mirrors get-many); VM/Cranelift route through the existing tree bridge
  • Per-item errors surface as Err in the result list — no short-circuit, unlike mapr
  • 3 interpreter tests, examples/par-map.ilo, and 4 doc touchpoints updated

Implementation notes

  • par_map_run extracted as #[inline(never)] per ILO-289 dispatch-arm-size convention
  • Worker threads each get a fresh Env built from a snapshot of env.functions + env.caps, so inner functions can use any builtin (including I/O / capability-checked builtins)
  • Parser entry: arity 2, slot 0 is fn-ref position (same pattern as map/flt)
  • Verifier: 2-or-3-arg arity check; builtin_check_args arm returns L (R b t) from fn return type
  • VM tree-bridge: (Builtin::ParMap, 2) | (Builtin::ParMap, 3) => true

Test plan

  • cargo test --lib passes (3333 tests, 0 failures)
  • cargo run -- run examples/par-map.ilo run-demo outputs [1, 4, 9, 16, 25, 36, 49, 64] then [2, 4, 6, 8, 10, 12, 14, 16]
  • par-map sq [1 2 3] 2 returns Ok-wrapped squared values
  • par-map fn [] returns []

Follow-up tickets (out of scope for v1)

  • VM native opcode path for par-map (currently bridges to tree)
  • Cranelift JIT/AOT native path
  • Chunking strategy for very large lists (current: process all in one pass)
  • Ordering guarantees documentation and cancellation design

Closes ILO-67.

🤖 Generated with Claude Code

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@danieljohnmorris
Copy link
Copy Markdown
Collaborator Author

needs manual rebase (conflicts in: src/builtins.rs)

@danieljohnmorris
Copy link
Copy Markdown
Collaborator Author

needs manual — rebase conflict in non-doc file(s)

@danieljohnmorris danieljohnmorris force-pushed the feature/par-map branch 2 times, most recently from 72aed01 to 176f358 Compare May 22, 2026 13:25
Implements `par-map fn xs [n]` — a general concurrency primitive that
applies a function to each element of a list in parallel, up to `n`
items at a time (default: num_cpus; override via ILO_PAR_MAP_CONCURRENCY).
Returns `L (R b t)`: per-item Ok/Err in input order without short-circuit.

Tree-walker implementation using std::thread::scope with chunked batches,
following the get-many pattern. VM/Cranelift bail to tree via the existing
bridge (is_tree_bridge_eligible). Large handler extracted into #[inline(never)]
par_map_run per the ILO-289 dispatch-arm-size convention.

Touches: src/builtins.rs, src/interpreter/mod.rs, src/parser/mod.rs,
src/verify.rs, src/vm/mod.rs, SPEC.md, ai.txt, skills/ilo/ilo-builtins-io.md,
examples/par-map.ilo. Includes 3 interpreter tests. Closes ILO-67.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@danieljohnmorris
Copy link
Copy Markdown
Collaborator Author

mini pc is reviewing this

@danieljohnmorris danieljohnmorris merged commit ca3037c into main May 22, 2026
6 of 10 checks passed
@danieljohnmorris danieljohnmorris deleted the feature/par-map branch May 22, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant