JIT nil-sweep batch 4: text + format helpers#287
Merged
Conversation
Group B of the JIT nil-sweep: jit_fmt2, jit_trm, jit_upr, jit_lwr, jit_cap, jit_padl, jit_padr, jit_ord, jit_chr, jit_chars, jit_unq, jit_frq. Each helper grows a packed span_bits parameter and routes its type-error paths (and the empty-string / invalid-codepoint / non-finite element edge cases for ord/chr/frq) through jit_set_runtime_error_with_span so the JIT raises an ILO-R009-shaped runtime error matching tree and VM. Both helper registries (AOT in compile_cranelift.rs and in-process JIT in jit_cranelift.rs) bump the arity to match the new helper signatures and pack the source span at every call site. Without the second registry the JIT would call the helper with one fewer argument and read a garbage span_bits from an uninitialised register, which only matters on the error path but is still UB. The jit_fmt2 digits-clamping branches (non-finite / negative / >20) stay correct-by-design: they coerce to 0 / 20 to mirror tree, not error. Likewise jit_chr's char::from_u32 returning None now errors rather than silently nil-ing, again matching tree.
Pins the happy-path output of jit_fmt2, jit_trm, jit_upr, jit_lwr, jit_cap, jit_padl, jit_padr, jit_ord, jit_chr, jit_chars, jit_unq, and jit_frq across tree, VM, and Cranelift JIT. The verifier rejects programs that statically mix types so most of the error paths are not reachable from a single CLI program; per-helper error-path coverage already lives as unit tests next to the helpers in src/vm/mod.rs. The padl/padr happy-path assertions use a sibling helper that strips just the trailing newline, since the default check_stdout would trim() the very pad whitespace we want to verify. Also updates regression_ord_chr.rs: the existing test pinned the silent-nil behaviour on empty input for Cranelift specifically while tree and VM errored. With the JIT now joining tree/VM, that split goes away. The test is consolidated into ord_empty_string_errors_on_every_engine and the obsolete cranelift-nil pin is removed.
A single-file ilo example that exercises trm, upr, lwr, cap, padl, padr, ord, chr, chars, unq, fmt2, and unq-on-list. The harness in tests/examples_engines.rs runs every -- run: / -- out: pair through every available engine, so dropping the file here gives us a higher-level regression test on top of the unit + integration tests. It also serves as an in-context learning example for agents: a future agent reading this file sees the now-correct behaviour without having to chase the helper through three different engines.
6f8b8a4 to
8ed1be8
Compare
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
Batch 4 of the JIT-helper permissive-nil sweep, picking up Group B from where #282 (batch 3) left off: the text helpers and fmt2.
Twelve helpers (
jit_fmt2,jit_trm,jit_upr,jit_lwr,jit_cap,jit_padl,jit_padr,jit_ord,jit_chr,jit_chars,jit_unq,jit_frq) all silently returnedTAG_NILon type-error, empty-string, invalid-codepoint, and non-finite-element paths where tree and VM both raise anILO-R009runtime error. Each helper now carries a packedspan_bitsimmediate and routes its failure paths throughjit_set_runtime_error_with_span(the TLS primitive from #254), so the JIT raises the same diagnostic as tree/VM with a caret matching the source span.(
jit_len/jit_str/jit_numfrom the original batch-4 plan were already routed in batch 3 and intentionally not in scope here.)Repro before/after
What's in the diff
route text + format JIT helpers through JIT_RUNTIME_ERROR— helper bodies insrc/vm/mod.rsgrow aspan_bitsparameter and route every error path that previously fell through toTAG_NILviajit_set_runtime_error_with_span. Both helper registries (the AOT one incompile_cranelift.rsand the in-process JIT one injit_cranelift.rs) bump the declared arity and pack the source span at every call site. The second registry is the load-bearing bit: without it the JIT would call the helper with one fewer arg and read garbage from an uninit register on the error path.add cross-engine regression suite for batch-4 helpers— newtests/regression_jit_nil_sweep_batch4.rspins happy-path output of every batch-4 helper across tree, VM, and Cranelift. Per-helper error-path coverage lives next to the helpers as unit tests insrc/vm/mod.rs(driving them directly, since the verifier rejects mixed-type programs that would surface these errors via the CLI).tests/regression_ord_chr.rsis consolidated: the previous test that pinned silent-nil-on-empty for Cranelift while tree/VM errored is folded into a singleord_empty_string_errors_on_every_enginenow that all three engines agree.add example pinning batch-4 helper happy paths through examples_engines—examples/text-helpers-jit-parity.iloexercises every helper through the existingtests/examples_engines.rsharness, which runs each-- run:/-- out:pair through every available engine. Doubles as in-context learning material for future agents.Test plan
cargo build --release --features craneliftcargo test --release --features cranelift— 123 test binaries, 0 failurescargo fmt --all -- --checkcargo clippy --release --features cranelift --all-targets -- -D warningsexamples/text-helpers-jit-parity.iloruns identically on every engine viaexamples_engines.rsFollow-ups
jit_fmt2digits-clamping branches (non-finite / negative / >20) stay correct-by-design: they coerce to 0 / 20 to mirror tree, not error.