HS tests: SIGALRM + raise timeout for native OCaml loops

The infinite loops in the HS parser are in transpiled native OCaml code,
not in the VM or CEK step loop. Neither step counters (in cek_step_loop,
cek_step, trampoline) nor VM instruction checks caught them because
the loops are in direct OCaml recursion.

Fix: SIGALRM handler raises Eval_error to break out of native loops.
Also sets step_limit flag to catch VM loops. Combined approach handles
both native OCaml recursion (alarm+raise) and VM bytecode (step check).

The alarm+raise can become unreliable after ~13 timeouts in a single
process, but handles the common case well. Reverts the fork-based
approach which lost inter-test state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-14 11:57:33 +00:00
parent 3d7fffe4eb
commit e3eb46d0dc
3 changed files with 69 additions and 59 deletions

View File

@@ -448,6 +448,9 @@ and run vm =
let op = bc.(frame.ip) in
frame.ip <- frame.ip + 1;
incr _vm_insn_count;
(* Check timeout flag set by SIGALRM *)
if !_vm_insn_count land 0xFFFF = 0 && !Sx_ref.step_limit > 0 then
raise (Eval_error "TIMEOUT: step limit exceeded");
(try match op with
(* ---- Constants ---- *)
| 1 (* OP_CONST *) ->