route I/O JIT helpers through JIT_RUNTIME_ERROR (batch 7)#288
Merged
Conversation
Group E of the JIT-helper permissive-nil sweep (batches 1-6 landed in PRs #264, #259, #282, #285). Helpers in this batch: jit_rd, jit_rdl, jit_wr, jit_wrl, jit_jpar, jit_rdjl, jit_dtfmt, jit_dtparse. Before: every helper above silently returned TAG_NIL on the type-error path (non-string path, non-number epoch, non-string format), diverging from the tree walker and bytecode VM, which both raise VmError::Type with a specific message. Agents calling rd/wr/dtfmt/... with a value they expected to be a string (but wasn't) through a dynamic-dispatch slow path got nil where they expected an error to retry off. After: each type-error path signals via jit_set_runtime_error_with_span using the same wording the VM dispatcher uses ("rd requires a string path", "dtfmt requires a number (epoch)", "wrl list elements must be strings", etc.), so the JIT entry point synthesises a VmRuntimeError that renders with a caret matching tree/VM diagnostics. jit_rdjl additionally routes its fs::read_to_string failure through the same channel with VmError::Type("rdjl failed to read file") to match OP_RDJL in the VM. The Err-returning paths in rd/rdl/wr/wrl for actual I/O failures (heap_err with the io::Error message) stay unchanged because the VM produces the same heap_err there too: those are Result-typed values flowing back to the caller, not runtime errors. Mechanics: - extern "C" signatures grow a span_bits: u64 immediate (packed (start << 32) | end), passed through from chunk.spans[ip] at every cranelift call site in both src/vm/jit_cranelift.rs (in-process JIT) and src/vm/compile_cranelift.rs (AOT). - declare_helper arities updated in both modules. - jit_jpar's existing unit tests updated; 11 new unit tests added inside vm::tests::jit_helpers covering every type-error path for every helper in this batch. Full test suite green locally (4992 tests across 123 binaries).
7 tests covering jit_rd/jit_rdl/jit_wr/jit_wrl round-trips, jit_jpar JSON parse, jit_rdjl JSONL count, and jit_dtfmt/jit_dtparse format round-trip across tree, VM, and Cranelift JIT. The per-helper type-error coverage lives in vm::tests::jit_helpers (the verifier rejects surface programs that statically pass non-strings to these builtins, so the helper slow paths are unreachable from CLI ilo without dynamic dispatch). Includes a no-stale-error-leak guard: an errored cranelift invocation (hd []) followed by a fresh process running a wr/rd happy-path must succeed, pinning that JitRuntimeErrorGuard's clear-on-entry contract holds for the new error sites added in this batch.
Five functions covering text round-trip, lines round-trip, JSONL count, dtfmt, and dtparse. The examples_engines harness runs every function across tree, VM, and Cranelift JIT, so this acts as a higher-level regression test in addition to the dedicated suite. Also gives agents a worked example of the now-consistent I/O helper behaviour: a type error in one of these surfaces a VmError::Type diagnostic on every engine, not nil on Cranelift and an error on tree/VM.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
Group E of the JIT-helper permissive-nil sweep (batches 1-6 in #264, #259, #282, #285). Routes the type-error paths in
jit_rd,jit_rdl,jit_wr,jit_wrl,jit_jpar,jit_rdjl,jit_dtfmt,jit_dtparsethroughJIT_RUNTIME_ERRORso cranelift surfaces aVmError::Typediagnostic on the same inputs where tree and VM raise.jit_rdjladditionally routes itsfs::read_to_stringfailure through the same channel to matchOP_RDJLin the VM. The Result-typedheap_errreturns injit_rd/jit_rdl/jit_wr/jit_wrlfor actual filesystem failures are preserved unchanged because the VM produces the sameheap_errthere too.Manifesto-aligned: agents calling
rd pathwith a value they expected to be a string (but wasn't, through dynamic dispatch) previously gotnilon Cranelift and a typed error on tree/VM. They now get the same diagnostic everywhere, with no token cost in the source program.Repro
Before, on Cranelift:
After:
JIT_RUNTIME_ERRORis then picked up by the entry-point post-call check (PR #254) and surfaced asVmRuntimeErrorwith a caret matching tree/VM.What's in the diff (per commit)
12a92e7route I/O JIT helpers through JIT_RUNTIME_ERROR. All eight helpers grow aspan_bits: u64immediate; call sites insrc/vm/jit_cranelift.rs(in-process JIT) andsrc/vm/compile_cranelift.rs(AOT) packchunk.spans[ip]and pass it through.declare_helperarities updated in both modules. The existingjit_jparunit tests are updated for the new signature, and 11 new unit tests cover every type-error path for the eight helpers.ea6295cadd cross-engine regression suite for batch-7 helpers. 7 CLI tests pin happy-path parity for wr/rd, wrl/rdl, jpar, rdjl, dtfmt, dtparse across tree, VM, Cranelift, plus a stale-error-leak guard.181eff5add example pinning batch-7 helper happy paths through examples_engines. Five functions inexamples/jit-io-roundtrip.ilorun on every engine via thetests/examples_engines.rsharness.Test plan
cargo build --release --features craneliftcleancargo fmt --checkcleancargo clippy --release --features cranelift --all-targetscleancargo test --release --features cranelift4992 passing across 123 binaries (zero failures)regression_jit_nil_sweep_batch7suite passes on all engines (7/7)examples/jit-io-roundtrip.iloruns clean on tree, VM, CraneliftFollow-ups
Groups F+ (network helpers
jit_get/jit_post/jit_geth/jit_posth/jit_getmany,jit_env, the remaining map/record nil-returners) are not in this batch. The Cranelift CLI div-by-zero behaviour for the always-num inline path noted in batch 3 is still tracked separately.