scope problems with inlined local closures
on Armed Bear Common Lisp 1.6.0 Java 11.0.6 Debian OpenJDK 64-Bit Server VM
(defun foo ()
(let ((b 123))
(flet ((set-b (x)
(setf b x)))
(declare (inline set-b))
(format t "outer b = ~s~%" b)
(let ((b 345))
(format t "inner b = ~s~%" b)
(set-b 0)
(format t "inner b = ~s~%" b))
(format t "outer b = ~s~%" b))))
FOO
CL-USER(2): (foo) ;;; expected results
outer b = 123
inner b = 345
inner b = 345
outer b = 0
NIL
CL-USER(3): (compile 'foo)
FOO
NIL
NIL
CL-USER(4): (foo) ;;; unexpected results
outer b = 123
inner b = 345
inner b = 0
outer b = 123
NIL
SBCL and CCL agree with interpreted answer, where inlined function properly closes over outer binding. ECL behaves like ABCL, where inlined function affects inner binding when compiled. (i assume lw, allegro, cmucl, and clisp agree with sbcl/ccl since they run the original code without problems, though i haven't tried the reduced case on them)
I can't find anything specific in the spec saying it is wrong, but it is at least unexpected to me that inlining affects semantics of a closure like that.
Thanks for the analysis.
In general in lieu of the something explicitly in the ANSI spec, I agree with SBCL and CCL here that that the compiled behavior should reflect the interpreted behavior.
I'll look at this the next time I go through the compiler but right now am trying to get abcl-1.6.1 out for ELS 2020.