From 4dde8ba6847a85ac366e597392516f76abae10a1 Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 29 Mar 2026 19:37:12 +0000 Subject: [PATCH] Fix JIT infinite recompile loop for closure functions When a JIT-compiled function failed on first call, the function name was added to _jit_warned but this was never checked before recompiling. Closures like parse-loop create new lambda instances on each call, each with l_compiled=None, triggering fresh compilation + failure in an infinite loop. Fix: check _jit_warned before attempting compilation, and mark the lambda with jit_failed_sentinel on first-call failure so the same instance also stops retrying. Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/bin/sx_server.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hosts/ocaml/bin/sx_server.ml b/hosts/ocaml/bin/sx_server.ml index b7690320..4afe29c1 100644 --- a/hosts/ocaml/bin/sx_server.ml +++ b/hosts/ocaml/bin/sx_server.ml @@ -727,7 +727,7 @@ let register_jit_hook env = None) | Some _ -> None (* compile failed or disabled — CEK handles *) | None -> - if !_jit_compiling then None + if !_jit_compiling || Hashtbl.mem _jit_warned fn_name then None else begin _jit_compiling := true; let t0 = Unix.gettimeofday () in @@ -742,6 +742,7 @@ let register_jit_hook env = (try Some (Sx_vm.call_closure cl args cl.vm_env_ref) with e -> Printf.eprintf "[jit] %s first-call fallback to CEK: %s\n%!" fn_name (Printexc.to_string e); + l.l_compiled <- Some Sx_vm.jit_failed_sentinel; Hashtbl.replace _jit_warned fn_name true; None) | None -> None