Fix VM reuse_stack lost across stub VM boundary on IO suspension
Root cause: when perform fires inside a VM closure chain (call_closure_reuse), the caller frames are saved to reuse_stack on the ACTIVE VM. But the _cek_io_suspend_hook and _cek_eval_lambda_ref create a NEW stub VM for the VmSuspended exception. On resume, resume_vm runs on the STUB VM which has an empty reuse_stack — the caller frames are orphaned on the original VM. Fix: transfer reuse_stack from _active_vm to the stub VM before raising VmSuspended. This ensures resume_vm -> restore_reuse can find and restore the caller's frames after async resume via _driveAsync/setTimeout. Also restore step_limit/step_count refs dropped by bootstrap.py regeneration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1029,6 +1029,13 @@ let () = _cek_io_suspend_hook := Some (fun suspended_state ->
|
||||
let request = Sx_ref.cek_io_request suspended_state in
|
||||
let vm = create !_default_vm_globals in
|
||||
vm.pending_cek <- Some suspended_state;
|
||||
(* Transfer reuse_stack from the active VM so resume_vm can restore
|
||||
caller frames saved by call_closure_reuse during the suspension chain. *)
|
||||
(match !_active_vm with
|
||||
| Some active when active.reuse_stack <> [] ->
|
||||
vm.reuse_stack <- active.reuse_stack;
|
||||
active.reuse_stack <- []
|
||||
| _ -> ());
|
||||
raise (VmSuspended (request, vm)))
|
||||
|
||||
let () = _cek_eval_lambda_ref := (fun f args ->
|
||||
@@ -1040,6 +1047,12 @@ let () = _cek_eval_lambda_ref := (fun f args ->
|
||||
resume_vm will: cek_resume → push result → run (no-op, no frames) → pop *)
|
||||
let vm = create (Hashtbl.create 0) in
|
||||
vm.pending_cek <- Some final;
|
||||
(* Transfer reuse_stack from active VM *)
|
||||
(match !_active_vm with
|
||||
| Some active when active.reuse_stack <> [] ->
|
||||
vm.reuse_stack <- active.reuse_stack;
|
||||
active.reuse_stack <- []
|
||||
| _ -> ());
|
||||
raise (VmSuspended (Sx_runtime.get_val final (String "request"), vm))
|
||||
| _ -> Sx_ref.cek_value final)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user