lumbda/c
russell@unturf.com 45a90b84e9
c: vm restores cur_code across CALL/RETURN, fixing JIT named-let hang
Five-line fix that ends the F1 hang in foxhop.net
ecdsa/tests/unit/probe-c-confirm.lsp.

Symptom — under --fast, a defined function whose body is a
tail-recursive named-let that calls another user-defined function
per iteration loops forever at 100 percent CPU. Trace pins the
bytecode dispatch:

  walk1.body: PUSHE MKCLO DUP BIND LOOKUP TCALL ->loop
  loop:       LOOKUP NULL? JIF LOOKUP CALL ->always-true
  always-true: CONST RET (returns #t)
  always-true (!): JIF LOOKUP CDR STAIL -> ip=0 of always-true (!)
  loop forever

cur_code was the call-frame-local register holding the currently
executing CodeObj. OP_CALL updated it on entry but neither OP_RETURN
nor the builtin-fallback restore path in OP_TAIL_CALL put it back
on return. Subsequent OP_SELF_TAIL_CALL read cur_code->self_params
from the still-stale callee proc (NULL for always-true since it has
no named-let), guard skipped the env rebind, then set ip=0 — without
ever updating the loop variable. Loop variable stayed pinned at the
initial list and our walk never reached its base case.

Fix — VMFrame gains a cur_code field. Three frame-push sites save
it on entry (OP_CALL, OP_TAIL_CALL builtin fallback frame-restore,
OP_CALL_CC compiled-proc entry); two frame-pop sites restore it on
return (OP_RETURN, OP_TAIL_CALL builtin fallback).

Verified inside foxhop.net's ecdsa QEMU guest:

- foxhop.net/ecdsa/tests/unit/probe-c-confirm.lsp F1..F4 — all pass
- foxhop.net/ecdsa/tests/unit/test-sim.lsp under --fast — 21/21 pass
- foxhop.net/ecdsa/lumbda/main.lsp under --fast — 6 shots, score 18,
  byte-identical with our Python tier
- make functional-test — 205/205 on Python and C tiers
- make regression-named-let-leak — 4/4 across Python, tree-walker,
  and --fast JIT

c/TODO-named-let-bytecode.md can stop applying its `(define (iter ...))`
workaround once this lands.
2026-06-04 01:11:18 -04:00
..
.gitignore rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
bench.c rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
builtins.c c: enable Boehm GC by default, GC_INIT, file ops, regression test 2026-06-04 00:55:31 -04:00
eval.c rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
jit.c rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
jit.h rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
lumbda.h c: vm restores cur_code across CALL/RETURN, fixing JIT named-let hang 2026-06-04 01:11:18 -04:00
main.c c: enable Boehm GC by default, GC_INIT, file ops, regression test 2026-06-04 00:55:31 -04:00
Makefile c: enable Boehm GC by default, GC_INIT, file ops, regression test 2026-06-04 00:55:31 -04:00
portal.c portal-rng: add (random-seed-from-os!) across all three tiers 2026-04-20 15:50:26 -04:00
printer.c rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
reader.c rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
test.c rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
TODO-named-let-bytecode.md rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
types.c cl-compat: run Zoë Trout's favorites unchanged (ticket 0004) 2026-04-24 07:02:21 -04:00
vm.c c: vm restores cur_code across CALL/RETURN, fixing JIT named-let hang 2026-06-04 01:11:18 -04:00