From 1cc3e761a299b842e0b85c4a95b62f5e12f259ae Mon Sep 17 00:00:00 2001 From: giles Date: Mon, 23 Mar 2026 10:20:13 +0000 Subject: [PATCH] Fix get nil-safety in sx_runtime.ml + reduce VM failure log noise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The second get implementation in sx_runtime.ml (used by transpiled code) was still raising on type mismatches. Now returns nil like sx_primitives. Remove per-call [vm-call-closure] FAIL logging — the jit-hook already logs failures at the right level. Reduces 70K log lines to ~5. Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/lib/sx_runtime.ml | 3 ++- hosts/ocaml/lib/sx_vm.ml | 8 +------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/hosts/ocaml/lib/sx_runtime.ml b/hosts/ocaml/lib/sx_runtime.ml index 5468e17..bce3212 100644 --- a/hosts/ocaml/lib/sx_runtime.ml +++ b/hosts/ocaml/lib/sx_runtime.ml @@ -102,7 +102,8 @@ let get_val container key = | Dict d, Keyword k -> dict_get d k | (List l | ListRef { contents = l }), Number n -> (try List.nth l (int_of_float n) with _ -> Nil) - | _ -> raise (Eval_error ("get: unsupported " ^ type_of container ^ " / " ^ type_of key)) + | Nil, _ -> Nil (* nil.anything → nil *) + | _, _ -> Nil (* type mismatch → nil (matches JS/Python behavior) *) (** Register get as a primitive override — transpiled code calls (get d k). *) let () = diff --git a/hosts/ocaml/lib/sx_vm.ml b/hosts/ocaml/lib/sx_vm.ml index c6f1f85..0161553 100644 --- a/hosts/ocaml/lib/sx_vm.ml +++ b/hosts/ocaml/lib/sx_vm.ml @@ -381,13 +381,7 @@ and call_closure cl args globals = List.iter (fun a -> push vm a) args; for _ = List.length args to cl.vm_code.vc_locals - 1 do push vm Nil done; vm.frames <- [frame]; - (try run vm - with e -> - Printf.eprintf "[vm-call-closure] FAIL in %s: %s (bc_len=%d args=%d sp=%d)\n%!" - (match cl.vm_name with Some n -> n | None -> "?") - (Printexc.to_string e) - (Array.length cl.vm_code.vc_bytecode) (List.length args) vm.sp; - raise e); + (try run vm with e -> raise e); pop vm (** Execute a compiled module (top-level bytecode). *)