Skip to content

Lift ct 2 / ct 3 count-by-predicate to native VM dispatch (PR C of ILO-45)#707

Merged
danieljohnmorris merged 1 commit into
nextfrom
feature/lift-ct
May 22, 2026
Merged

Lift ct 2 / ct 3 count-by-predicate to native VM dispatch (PR C of ILO-45)#707
danieljohnmorris merged 1 commit into
nextfrom
feature/lift-ct

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

PR C of ILO-45 — third slice of the tree-walker eval-loop deletion. Lifts ct fn xs and ct fn ctx xs off the tree-bridge to native VM dispatch via a per-element OP_CALL_DYN loop with a numeric counter accumulator. No new opcode needed — counter increments via the existing OP_ADDK_N on the true branch of the bool typecheck.

After this PR, every FnRef-taking entry on is_tree_bridge_eligible has been lifted. The remaining bridge entries are all non-HOF builtins (regex, fmt, fs metadata, crypto, calendar, sleep, run, env-all, math constants, jkeys). PR D will audit those for transitive eval_body reachability, and PR E will delete the eval loop itself.

What's in the diff

Single commit, two files:

  • src/vm/mod.rs
    • New combined (Builtin::Ct, 2) | (Builtin::Ct, 3) => arm in compile_call. Argc=1 (plain) vs argc=2 (closure-bind) handled by conditionally allocating arg1_reg. Same bool-typecheck error shape as flt 2/3 ("ct: predicate must return bool" via WRAPERR + PANIC_UNWRAP).
    • Counter accumulator: numeric register initialised to 0, increments via OP_ADDK_N (with OP_ADD + LOADK fallback if the 1.0 const overflows the 8-bit K-table — defensive, effectively dead since 1.0 interns early).
    • Two entries removed from is_tree_bridge_eligible.
  • tests/aot-baselines/obj-baselines.tsv
    • 2 entries updated: ct-count-by-predicate and reserved-names (the only examples exercising ct). Other 134 baselines byte-identical to PR B's regen.

Test plan

  • cargo test --release --features cranelift — full suite green
  • Smoke test: pos/above-threshold counts give identical output across default / --vm / --jit
  • examples/ct-count-by-predicate.@ covers both ct 2 and ct 3 closure-bind — now natively dispatched
  • superpowers:code-reviewer subagent run on the diff — no blockers (flagged a closure-with-captures coverage gap that's shared with PRs A and B's lifts, not new in C)

Follow-ups

  • PR D: audit non-HOF bridge entries for transitive eval_body reachability; lift any that still call into the eval loop internally
  • PR E: delete eval_body / eval_stmt / eval_expr / Env / trampoline / ACTIVE_AST_PROGRAM (the headline LoC win)

PR C of ILO-45. Adds a combined `(Builtin::Ct, 2) | (Builtin::Ct, 3)`
compiler arm that emits a per-element OP_CALL_DYN loop with a numeric
counter accumulator. No new opcode or finalizer needed — counter
increments via OP_ADDK_N on the true branch of the bool typecheck,
identical to flt's predicate shape minus the LISTAPPEND.

Argc=1 for plain `ct fn xs`, argc=2 for closure-bind `ct fn ctx xs`.
Both share the same arm; the ctx variant just allocates the extra
contiguous arg1_reg before the loop. Cranelift inherits via the
existing OP_CALL_DYN codegen.

Two entries removed from is_tree_bridge_eligible. After this PR, the
only FnRef-taking entries left on the bridge are gone — the remaining
work for the eval-loop deletion is:
  - PR D: audit non-HOF bridge entries for transitive eval_body
    reachability, lift any that need it
  - PR E: delete eval_body / eval_stmt / eval_expr / Env / trampoline

AOT object baselines updated for the two examples that exercise `ct`
(ct-count-by-predicate, reserved-names). The remaining 134 baselines
are byte-identical to PR B's regen.

Test plan: cargo test --release --features cranelift green.
Smoke test: pos / above-threshold counts give identical output across
default / --vm / --jit. examples/ct-count-by-predicate.@ covers
both ct 2 and ct 3 (closure-bind) — now natively dispatched.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 92.75362% with 5 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/vm/mod.rs 92.75% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@danieljohnmorris danieljohnmorris merged commit 061ea69 into next May 22, 2026
5 checks passed
@danieljohnmorris danieljohnmorris deleted the feature/lift-ct branch May 22, 2026 07:59
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