surprising behavior of dynamic-extent in do forms
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Invalid
|
Undecided
|
Unassigned |
Bug Description
I'm seeing some surprising (to me at least) behavior caused by dynamic-extent declarations in do forms. Phoe on #sbcl reduced the issue to, roughly, the following test case:
(defun foo (startr endr)
(let ((acc 0))
(do ((i startr (1+ i))) ((> i endr))
(declare (dynamic-extent i))
(incf acc i))
acc))
[note that this works without the acc stuff, I just used this to convince myself that this wasn't all just optimized away]
When I compile this form I get:
cd /home/sly/
1 compiler notes:
temp.lisp:37:5:
note:
could not stack allocate STARTR in: (DO ((I STARTR (1+ I))) ((> I ENDR)) (DECLARE (DYNAMIC-EXTENT I)) (INCF ACC I))
--> BLOCK LET
==>
STARTR
Why should the dynamic-extent declaration of i affect whether or not startr is stack allocated?
A trivial rewrite of this using loop does not trigger the same compiler note.
Because it's the initial value of I.