#276 flet/labels local functions lack implicit block (return-from misses)

open
Opened by atgreen

On build/funcl (real binary), ANSI data-and-control-flow/flet.lsp:

Fix is cold-path (flet is a special form with lift machinery in src/cold/compiler.lisp ~4817-4939); wrap each flet/labels function body in (block FNAME ...) like emit-ir-defun does for cave#148.

Comments (2)

atgreen3992746387

PARTIALLY FIXED (2026-07-11):

  • flet.5 (return-from local function) FIXED — commit 83a03ba wraps each flet lambda body in (block NAME ...) in the stdlib flet macro. Verified: (flet ((%f () (return-from %f 15) 35)) (%f)) -> 15; multi-binding return-from -> 16.
  • labels implicit block FIXED — commit b7d34ad, same for %labels-sets. Verified return-from + recursion + mutual recursion.
  • flet.lsp 39->41 PASS on build/funcl; both self-host validated.

STILL OPEN:

  • flet.4 / flet.4a / flet.6: return-from to an OUTER block from an &optional/&key/&aux DEFAULT form (the defaults are NOT in the function's implicit block per CLHS, and the return-from targets the enclosing block). Currently RETURN-FROM-MISS. This is a separate escapify gap (return-from inside a lifted lambda's param-default reaching an enclosing block), not the implicit-block issue.
  • flet.7: nested shadowing flet where inner body references outer same-named fn -> 'The value %F is not a LIST'. Separate bug.

NOTE: these only manifest on build/funcl (the real binary). build/funcl-stage2 lacks mini-clos and mis-handles CLOS fixtures — use FUNCL=build/funcl to reproduce.

atgreen3992785850

ASSESSMENT 2026-07-11: unchanged — flet/labels locals lack their implicit block, so (return-from NAME …) inside a local misses. The fix shape is known and the device exists: the cave#219 escapify pre-pass already rewrites cross-frame return-from via escape tokens; extending it means wrapping each flet/labels local body in a synthetic (block NAME …) BEFORE lifting so escapify sees the pair. Moderate; touches ag-escapify + the lift path. Related recent win: the same machinery family fixed cave#269 (closed today).