Specializer M-cranelift: codegen backend behind the same interface (TASK-44) - #27
Merged
Merged
Conversation
…wired, in-tree JIT smoke green (TASK-44) TASK-43 marked Done (PR #26 merged); TASK-44 stretch plan recorded in backlog. cranelift-{jit,module,codegen,frontend} 0.126 added and a smoke test JITs and executes a function on x86_64-pc-windows-msvc — the spike result is now validated in-tree, not just in a note. The real per-row backend (extern "C" fn(ctx) -> i64 ABI, coverage-first with shared helpers, interpreter fallback) lands next per the stretch plan. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ferential green, wired behind DuckDBInferFn (TASK-44 stretches 1-3) One JIT'd function per program, called per row: extern "C" fn(*mut Cx) -> i64 (0 emit / 1 skip / 2 helper trap / 3+k term trap). Coverage-first: float arith, int compares, logic, select, itof, fabs, and consts map inline to CLIF; everything nontrivial — checked int arith, all string ops, loads/stores, statics, probes — calls extern helpers that delegate to the interpreter's own semantic functions (casemap, substr_window, duck_fcmp, DuckF64, the arena), so the backends cannot drift where they share code. Strings travel as (offset, length) i64 pairs; trap_flag at Cx offset 0 is checked after every fallible helper call. CraneliftFn owns a compiled InterpFn for input/state checks, prepared statics, and the always-available fallback. The 500-seed random-IR differential (fuzz_cranelift_agrees_with_ interpreter) demands byte-identical outputs and traps — it caught two real bugs before landing: load.opt and sload.opt must NORMALIZE payloads to type defaults under a false flag, exactly as the interpreter documents. DuckDBInferFn now compiles cranelift-first with interpreter fallback (AC #2) and exposes .backend; the whole pytest suite — 32 duck_check differentials and the 678-case corpus replay at 0 FAILs — now exercises the JIT. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…gines, raw-compute isolation (TASK-44 stretch 4)
scripts/bench_specializer.py reports p50/p99 ns/call at n in
{1,8,64,1024} for the no-op boundary baseline, cranelift, the
interpreter control (SPECIALIZER_FORCE_INTERP env knob, also a
debugging escape hatch), and the existing native + codegen engines.
Measured on this machine: the pydantic boundary dominates end-to-end
(a no-op passthrough costs within ~20% of a full join), cranelift and
interp are at parity through Python, and both beat native/codegen by
~1.5-2x at larger n. The ignored backend_compute_bench isolates raw
compute without the boundary: cranelift 13.2 ns/row vs interpreter
37.6 ns/row (2.8x) — the JIT win is real and waiting behind the
boundary, which is M-boundary's job.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ahrzb
approved these changes
Jul 26, 2026
claude-agent-ahrzb Bot
pushed a commit
that referenced
this pull request
Jul 26, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What (TASK-44, milestone m-7 — COMPLETE, all 4 acceptance criteria)
Cranelift-jit 0.126 backend for the imperative IR, behind the same interface as the interpreter, with full instruction coverage.
Shape (design doc §7): one JIT'd function per program, called per row —
extern "C" fn(*mut Cx) -> i64(0 emit / 1 skip / 2 helper trap / 3+k term trap).Cxisrepr(C); generated code reads exactly one field directly (trap_flagat offset 0, checked after every fallible helper call). IR blocks map 1:1 to CLIF blocks + params (the IR was shaped for this); strings travel as (offset, length) i64 pairs into the shared arena.Coverage-first strategy: consts, float arithmetic, integer compares, logic, select, itof, fabs are inline CLIF; everything nontrivial — checked int arithmetic, all string ops, loads/stores, statics, probes — calls
extern "C"helpers that delegate to the interpreter's own semantic functions (casemap, substr_window, duck_fcmp, DuckF64, the arena). The backends physically cannot drift where they share code. Inlining hot helpers is a later, measured optimization.Verification (AC #1, #4):
load.opt/sload.optmust normalize payloads to type defaults under a false flag)Fallback (AC #2):
DuckDBInferFncompiles cranelift-first, falls back to the interpreter on any compile error;SPECIALIZER_FORCE_INTERPenv knob pins the control;.backendgetter pins the choice in tests.Numbers (AC #3),
scripts/bench_specializer.py, p50/p99 ns/call at n ∈ {1, 8, 64, 1024} vs interpreter control + existing native + codegen engines, boundary no-op baselined first per §10:backend_compute_bench): cranelift 13.2 ns/row vs interpreter 37.6 ns/row — 2.8×. The JIT win is real and waiting behind the boundary; M-boundary (generated row marshaller) is where it becomes end-to-end visible.🤖 Generated with Claude Code