Debug quality doesn't seem to match documentation

Bug #1993039 reported by Fred Gilham
6
This bug affects 1 person
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))
            (SPECIAL N ACC))
   (LET ((TEST-VALUE (EQUALP (SYMBOL-VALUE 'N) 0)))
     (IF (EQ TEST-VALUE 'TRUE)
         (RETURN-FROM FACTT (SYMBOL-VALUE 'ACC))
         (IF (EQ TEST-VALUE 'FALSE)
             (VALUES)
             (THE T
                  (ERROR 'LOGO-TYPE-ERROR :PROCEDURE-NAME "if" :DATUM
                         TEST-VALUE :EXPECTED-TYPE
                         "boolean (true or false)")))))
   (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)
                  8: (LOGO:FACTT 2 1814400)
                    9: (LOGO:FACTT 1 3628800)
                      10: (LOGO:FACTT 0 3628800)
                      10: FACTT returned 3628800
                    9: FACTT returned 3628800
                  8: FACTT returned 3628800
                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))
            (SPECIAL N ACC))
   (LET ((TEST-VALUE (EQUALP (SYMBOL-VALUE 'N) 0)))
     (IF (EQ TEST-VALUE 'TRUE)
         (RETURN-FROM FACTT (SYMBOL-VALUE 'ACC))
         (IF (EQ TEST-VALUE 'FALSE)
             (VALUES)
             (THE T
                  (ERROR 'LOGO-TYPE-ERROR :PROCEDURE-NAME "if" :DATUM
                         TEST-VALUE :EXPECTED-TYPE
                         "boolean (true or false)")))))
   (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).

Revision history for this message
Stas Boukarev (stassats) wrote :

You are binding a special variable for some reason. It has to be unbound before exiting, can't tail call over that.

Changed in sbcl:
status: New → Invalid
Revision history for this message
Fred Gilham (fmgilham) wrote :

Yeah ... I noticed the part about special variables --- in the CMU documentation --- about an hour after I submitted the bug report, right before it was pointed out above. So it ever goes.

So I agree that the special declarations in my code remove any expectation of tail call optimizations.

But the warnings about the (debug 0.5) --- non-integer debug qualities --- seem to be unwarranted. The documentation specifically says that "SBCL allows any real value for optimization qualities."

Perhaps I should open a new bug report for this?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.