Repository navigation
RISC-V: lower a builtin applied to more or fewer arguments than its arity; pin RV refusals; build mere-ruby for RV64 in CI - #96
Conversation
…rity Every builtin lowering in the RISC-V backend matched its exact arity, so `(map_get hooks 0) ()` and `(vec_get fs 0) 5` (more arguments: the result is a function, called on the spot) and `map_get m`, `bit_and 12` or `str_eq "x"` (fewer: a closure over the arguments given) fell through to the refusal, which said the builtin had "no RISC-V lowering" although its exact-arity form was lowered. The typer accepts both shapes and C, LLVM and Wasm lower both. They now take the path a top-level function's have since v0.1.599: fewer arguments are an eta closure around the saturated call, more are the saturated call with the rest applied to its result. This is the last case before the refusal, so no program that compiled before changes: every RV32 and RV64 binary of the parity and test/rv programs is byte-identical. mere-ruby had stopped compiling for RV64 on three such calls; it compiles again. test/parity/builtin_arity_shapes.mere covers over-application (two left-over arguments, tail position, a top-level alias, |> and <|) and partial application; interp, C, LLVM, Wasm, RV32 and RV64 agree. rv_exec_check pins the corpus programs RISC-V refuses at compile time (EXPECTED_REFUSED32: the 20 whose literals do not fit RV32's int; EXPECTED_REFUSED64: none). A refusal used to be only counted, so a parity program RISC-V refused kept the gate green. now_ms, the C runtime's monotonic millisecond clock, is answered on hosted RISC-V (clock_gettime, CLOCK_MONOTONIC); a call aborted before. test/rv/host_services.mere checks it, now at both widths, and the check requires all nine property lines: a run that aborted halfway used to pass. The RISC-V CI group runs scripts/downstream_rv_check.sh --poison, which emits mere-ruby (test/downstream/RV, through its tools/nothreads_tree.sh --coro) with -rv64 --ram 1024. No downstream gate built anything for RISC-V. 203 checks. v0.1.733.
284km
left a comment
There was a problem hiding this comment.
Reviewed exact head b09cd9157a96d517b3a6d04e8a53bee19b4a02a0 against current main bd5e766d6842143cd4f845f194f894cf26386d0c in isolated checkouts. No actionable findings. The fallback preserves saturated builtin lowering, and the typed saturated expression preserves the result information needed by subsequent indirect calls. Pinning compile refusals and requiring every host-service property line close the previous silent-skip/truncated-output gaps.
Independent validation on macOS arm64:
- Fresh base/head builds with OCaml 5.4.1 and Dune 3.23.1.
dune runtest: 3,061 passed, zero failed on each revision. Node is unavailable here, so optional self-host codegen cross-validation was skipped; these are not the full-toolchain CI counts. - Compiled the same 257 original parity fixtures and 20 original RV fixtures with both compilers, at both widths: 533 byte-identical outputs, 21 refused by both, no changed acceptance. The original host-services source was used for this compiler comparison; the updated fixture was tested separately.
- New
builtin_arity_shapesruns match the interpreter exactly on RV32/RV64 with memu7564b424. Both base compiler invocations reproduce the originalmap_getrefusal. Additional focused cases cover one-time argument evaluation/capture, float results, curried function results and nested calls; both widths match the interpreter. - Updated
host_servicesproduces all nine successful property lines at both widths. This tests ordinary clock behavior, not monotonicity across host wall-clock adjustments in memu. - Fresh mere-ruby main
f0f372e7, pinned mgz661a01d8:downstream_rv_check.sh --poisoncatches all three failure classes, then RV64 emission succeeds (89 seconds). The identical downstream with the base compiler fails onmap_getinm_numeric.mere, confirming the repaired regression. Emission success does not establish downstream execution. - RV partition audit passes (1,087 fixture compiler invocations); CI assignment and self-tests pass (203 checks / nine groups); documentation claims/coverage, all 601 RV prelude names, shell syntax and diff whitespace checks pass.
I did not independently rerun the complete emulated corpus or every hosted gate. Hosted build/distribution checks passed, but gate groups are still executing, so the queue-only merge exception does not apply. All jobs of latest main CI were inspected: Mere run 46148138711 has the pre-existing README test-count failure (3,305 claimed versus 3,307 observed); mere-ruby run 46362164472 has the recorded Module timeout failure. Neither is claimed repaired here. The recorded hold_all_merges / new_failure_review_required flags remain active. Already-reviewed mere-ruby #410, #414 and #415 were also considered; no merge attempted.
COMMENT because the authenticated account owns this PR.
…; README: 3307 tests Both escape routes call the stored closure as `(vec_get o 0) ()`, which the RISC-V backend refused until the previous commit, so the table listed rv as unreadable for them; escape_check failed on the stale entries. RISC-V now accepts both (SAFE, as the other backends) and prints the interpreter's answer at both widths. The README claimed 3305 tests; the suite passes 3307 on CI's toolchain (it already did on main, where first_run_check was red).
284km
left a comment
There was a problem hiding this comment.
Follow-up review of 601c1453c3b7625708a6b9531a874521cb4f288f against current main bd5e766d6842143cd4f845f194f894cf26386d0c: no actionable findings. The delta since the previous reviewed head is exactly four documentation/escape-table files; runtime, compiler and build inputs are unchanged.
Independent focused validation on macOS arm64:
- Reused the previous independently built compiler only after checking its checkout is clean and all runtime/build inputs are identical to this head.
escape_check.sh: PASS, all 27 routes, zero open holes.- Both affected original fixtures (
closure_out,closure_captures_container) compile and execute on memu at RV32 and RV64, matching the interpreter exactly (8and42respectively). - The README/language-reference count of 3,307 agrees with the actual full-toolchain count in the inspected main CI log; main's failure was the stale 3,305 claim. I did not rerun the full-toolchain suite locally; the earlier local count was 3,061 with optional Node checks unavailable.
- Diff whitespace check passes. The earlier implementation review and its disclosed coverage/limits remain applicable.
Hosted CI is still executing, rather than merely waiting for unassigned runners. No merge attempted: the queue-only exception does not apply, and the recorded global merge holds remain active. Already-reviewed mere-ruby #410/#414/#415 were considered as well; their reviews/checks do not clear those holds.
COMMENT because the authenticated account owns this PR.
What was wrong
The RISC-V backend refused a builtin applied to a number of arguments other than its own arity:
The interpreter, C and LLVM print 7, and Wasm compiles it too.
-rv/-rv64saidRV64I: `map_get` has no RISC-V lowering yet (host builtin)-- although the two-argumentmap_gethas been lowered all along. The same happened with fewer arguments (let at = vec_get v in at 0,bit_and 12,str_eq "x",char_at s,str_compare "b",float_of_bits, ...), through a top-level alias of the builtin (let g = map_get;then(g m 0) ()), and through() |> map_get m 0andmap_get m 0 <| x.mere-ruby hit it: since 2026-11-17 it keeps callbacks that a later module registers in a Map or a Vec and calls them as
(map_get hook 0) ()/(vec_get hook 0) ()(three places), and its RV64 build has not compiled since. No gate here or there built it for RISC-V, so nothing said so.Why
Every builtin case in
compile_app(lib/codegen_riscv.ml) matches its builtin's exact arity (| Ast.Var "map_get" when List.length args = 2 -> ...). With any other count, the application fell through all of them to the last case, which refuses every builtin it reaches. Top-level functions have had both other shapes since v0.1.599 (k < arityis an eta closure,k > aritythe saturated call plus the rest applied to the result); builtins did not. Builtins used as values already go throughcompile_eta(v0.1.638).The change
lib/codegen_riscv.ml: in the refusing case, before refusing, compare the argument countkwith the arrows in the builtin's type inTyper.initial_env(n).k < n:compile_eta env head n args.k > n: build the saturated application andcompile_indirectthe rest (tail position preserved).k = nrefuses as before. Both re-entercompile_appwith exactlynarguments, so a builtin that really has no lowering is still refused by name from inside the saturated form. As this is the last case before the refusal, only programs that were refused before can change.test/parity/builtin_arity_shapes.mere: over-application (map_get,vec_get, two left-over arguments,owned_vec_get,fst/snd,try_or, tail position, a top-level alias,|>and<|) and partial application (map_get,vec_get,bit_and,str_eq,char_at,str_compare, a partial application passed as a value). README's parity count is 258.scripts/rv_exec_check.sh: compile-time refusals of the corpus are pinned by name. Until now a refusal was only counted and listed, and the gate stayed green -- so the parity program above would not have turned RISC-V red if the backend refused it again.EXPECTED_REFUSED32lists the 20 programs whose literals do not fit RV32's int;EXPECTED_REFUSED64is empty. An unlisted refusal fails, and so does a listed program that now compiles (a name is only checked when its C reference built, so a host that skips a program earlier does not see a stale entry). The RV64 emulator is now built next to the RV32 one, before the contracts.now_mson RISC-V:now_ms, the C runtime's monotonic millisecond clock (extern fn now_ms: unit -> int), joins the externs the RV prelude answers (libm_sigs+__libm_now_ms,clock_gettimewithCLOCK_MONOTONIC; at 32 bits the count wraps and differences under about 24 days stay right). A call used to abort.test/rv/host_services.merechecks it by properties (does not go backwards, moves within a bounded loop, agrees withtimeto within a second). That contract now runs at both widths (it ran at 32 bits only) and requires all nine property lines: it used to pass a run that aborted after a fewoklines, since the abort message does not say FAIL.downstream_rv (mere-ruby still compiles for RV64)runsscripts/downstream_rv_check.sh --poison, which emits each row of the newtest/downstream/RVtable -- today mere-ruby, prepared by its owntools/nothreads_tree.sh --coro-- with-rv64 --ram 1024, using the dogfood clone that group already has. Emission only: whether a program copes with a target that has no C library is the downstream's own contract. The poison leg first requires a refused program, a failed prepare command and a missing checkout to fail, each for its own reason.ci_gate_check.rbexpects 203 checks.test/escape/ROUTES:closure_outandclosure_captures_containerlisted RISC-V as unreadable because both call the stored closure as(vec_get o 0) (). RISC-V reads them now (escape_check fails on a staleunreadableentry, which is how CI found them); both are SAFE as on the other backends and print the interpreter's answer at both widths on memu.mainalready passes 3307 tests on CI's toolchain while the README says 3305, sofirst_run_checkwas red on main (run of bd5e766). This PR adds no unit tests.Checked (macOS arm64)
-rvand-rv64binary of the 257 existing parity programs and the 20test/rvprograms, compiled bymain(bd5e766) and by this branch: 533 identical, 0 different, 21 refused by both (RV32 literal width).dune runtest: 3307 passed, 0 failed (maingives the same 3307, here and on CI).MEMU=<memu 7564b424> sh scripts/rv_exec_check.sh --all: 64 bits 257 passed, 0 failed, 1 known-different, 0 refused; 32 bits 244 passed, 0 failed, 8 known-different, 20 refused (all listed); every contract ok, includinghost_services@32and@64(9 properties). 606 s.main's compiler fails onbuiltin_arity_shapes (-rv refused it, and it is not in EXPECTED_REFUSED32).sh scripts/parity.sh: 258 passed, 0 failed; failing programs 31 passed, 0 failed. Unchecked lists are the same as on main (schema_reflecton LLVM,coro_pingpongon Wasm;int_width_boundarypinned).builtin_arity_shapesalso runs on RV32 and RV64 on memu with the interpreter's output.python3 scripts/rv_exec_partition_check.py,sh scripts/rv_prelude_check.sh(601 names),sh scripts/host_matrix.sh(unchanged: 218 builtins, 0 MISSING),sh scripts/doc_claims_check.sh,sh scripts/doc_coverage_check.sh,ruby scripts/ci_gate_check.rband--self-test(203 checks across 9 groups),sh scripts/tool_preflight_check.sh --poison(17 caught): all ok.sh scripts/first_run_check.sh: PASS (parity count 258, test count 3307).sh scripts/escape_check.sh: PASS, 27 routes.MERE_DOWNSTREAM=<dir with a fresh mere-ruby clone> sh scripts/downstream_check.sh: mere-ruby ok (33 s).MERE_DOWNSTREAM=... sh scripts/downstream_rv_check.sh --poisonwith mere-rubyf0f372e7(its current main): three poisons caught, thenok mere-ruby -rv64 --ram 1024 (main.mere) 46s, peak RSS about 3.1 GB. Withmain's compiler the same row fails:RV64I: `map_get` has no RISC-V lowering yet (host builtin)atm_numeric.mere:2634.CI time
Measured on this PR's first CI run: the
downstream_rvstep took 50 s on ubuntu-24.04 (mere-ruby-rv64emission 50 s; the three poisons under a second), in the RISC-V group, which finished in 14.1 minutes -- not the longest group (containers took 17.3). So the wall-clock time of CI does not grow. Locally the step is 46 s with a peak RSS of about 3.1 GB.host_servicesat 64 bits adds a few seconds torv_exec contracts(19 s in that run). The pinned refusals ran inrv_exec corpus32/corpus64and passed. That first run failed only onescape_check(the two stale rows above, fixed in the second commit) and onfirst_run_check's test count, which was red on main too.Not covered here
try_or); this PR only makes the compile step visible here.-wrow is added.🤖 Generated with Claude Code