[CM] [PATCH] s7: fix stale opt1_lambda cache for a thunk parameter in recursion
jinser
aimer at purejs.icu
Wed Aug 5 03:18:32 PDT 2026
Deal all,
Found an s7 bug at commit 915300e: an immediate lambda application
whose argument
closes over the caller's parameter loops forever
(define (f form)
((lambda (recurse) (recurse))
(lambda () (if (pair? form) (f (car form)) form))))
(f '(a)) ; expected 'a, actually never terminates
For better debugging, I made a repro that output correct or wrong
message instead of loops forever
(define *calls* 0)
(define *limit* 20)
(define (guard! who)
(set! *calls* (+ *calls* 1))
(when (> *calls* *limit*)
(error (string-append "s7 bug: unbounded re-invocation in " who))))
(define f (lambda (form)
(guard! "f")
((lambda (recurse) (recurse))
(lambda () (if (pair? form) (f (car form)) form)))))
(display "bug-pattern: ") (display (f '(a))) (newline)
(display "calls (expected 2): ") (display *calls*) (newline)
(display "done") (newline)
And s7 got "s7 bug: unbounded re-invocation in f", while Guile and
Chez got the correct answer "2".
I've attached a patch that is trying to fix the issue. I found the
issue caused by the closure_is_* fast-path shortcut.
I hope I handled it correctly and that it helps.
--
regards,
Jinser Kafka.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-s7-thunk-in-recursion-used-stale-opt1_lambda-cache.patch
Type: text/x-patch
Size: 2169 bytes
Desc: not available
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20260805/0a0a63c3/attachment.bin>
More information about the Cmdist
mailing list