Debug quality doesn't seem to match documentation
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Invalid
|
Undecided
|
Unassigned |
Bug Description
sbcl --version SBCL 2.2.9.
uname -a: Linux sparky.homedns.org 5.19.10 #1 SMP PREEMPT_DYNAMIC Tue Sep 20 14:07:05 CDT 2022 x86_64 Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz GenuineIntel GNU/Linux
I have the following code (generated by my application)
(DEFUN FACTT (N ACC)
(DECLARE (OPTIMIZE (SPEED 2) (SAFETY 3) (DEBUG 2))
(LET ((TEST-VALUE (EQUALP (SYMBOL-VALUE 'N) 0)))
(IF (EQ TEST-VALUE 'TRUE)
(IF (EQ TEST-VALUE 'FALSE)
(THE T
(FACTT (DIFFERENCE (SYMBOL-VALUE 'N) 1)
(PRODUCT (SYMBOL-VALUE 'N) (SYMBOL-VALUE 'ACC))))
Tracing I get
(factt 10 1)
0: (LOGO:FACTT 10 1)
1: (LOGO:FACTT 9 10)
2: (LOGO:FACTT 8 90)
3: (LOGO:FACTT 7 720)
4: (LOGO:FACTT 6 5040)
5: (LOGO:FACTT 5 30240)
6: (LOGO:FACTT 4 151200)
7: (LOGO:FACTT 3 604800)
7: FACTT returned 3628800
6: FACTT returned 3628800
5: FACTT returned 3628800
4: FACTT returned 3628800
3: FACTT returned 3628800
2: FACTT returned 3628800
1: FACTT returned 3628800
0: FACTT returned 3628800
3628800
When I change the debug quality to 1 in the above code I get the expected tail-recursion elimination:
(factt 10 1)
0: (LOGO:FACTT 10 1)
0: FACTT returned 3628800
But the info documentation says
"Any level greater than ‘2’ gives level ‘2’ and in addition disables
tail-call optimization, so that the backtrace will contain frames
for all invoked functions, even those in tail positions."
So I expected (debug 2) to allow tail-recursion optimization.
I happened to try a fractional debug quality and got the following:
(DEFUN FACTT (N ACC)
(DECLARE (OPTIMIZE (SPEED 2) (SAFETY 3) (DEBUG 1.5))
(LET ((TEST-VALUE (EQUALP (SYMBOL-VALUE 'N) 0)))
(IF (EQ TEST-VALUE 'TRUE)
(IF (EQ TEST-VALUE 'FALSE)
(THE T
(FACTT (DIFFERENCE (SYMBOL-VALUE 'N) 1)
(PRODUCT (SYMBOL-VALUE 'N) (SYMBOL-VALUE 'ACC))))
; in: DEFUN FACTT
; (OPTIMIZE (SPEED 2) (SAFETY 3) (DEBUG 1.5))
;
; caught WARNING:
; Ignoring bad optimization value 1.5 in:
; (OPTIMIZE (SPEED 2) (SAFETY 3) (DEBUG 1.5))
;
; compilation unit finished
; caught 1 WARNING condition
but the info documentation says, "SBCL allows any real value
for optimization qualities. It may be useful to specify ‘0.5’ to
get backtrace argument display without argument documentation."
(Debug quality 0.5 also gives the same warning FWIW.)
Obviously not a show-stopper but certainly something is wrong somewhere (either the code or the documentation).
You are binding a special variable for some reason. It has to be unbound before exiting, can't tail call over that.