defmacro compiler notes for List* and Append

Bug #2051401 reported by Robert Brown
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

Somewhere between version 2.3.1 and 2.3.4 I think ... Backquote expressions in macro definitions started producing compiler notes when the macro function is compiled with higher than normal speed. For instance, this form:

(defmacro define-foobar (finalization-rounds double)
  (declare (optimize (debug 2) (safety 0) (speed 3)))
  (let ((finalize (make-list finalization-rounds :initial-element '(sip-round v0 v1 v2 v3))))
    `(defun foobar ()
       (let ()
         ,@finalize
         ,(if (not double)
              '(logxor v0 v1 v2 v3)
              `(let ()
                 ,@finalize
                 (values h0 h1)))))))

Generates notes when compiled with SBCL 2.3.11.167-1ba132815

bob> (compile-file "bug.lisp")
; compiling file "/home/brown/bug.lisp" (written 26 JAN 2024 06:16:13 PM):

; file: /home/brown/bug.lisp
; in: defmacro define-foobar => defun foobar
; `(LET ()
; ,@BOB::FINALIZE
; (VALUES BOB::H0 BOB::H1))
; --> SB-IMPL::|Append|
; ==>
; 1
;
; note: unable to optimize due to type uncertainty: The first argument is a list, not a null.

; in: defmacro define-foobar
; `(DEFUN BOB::FOOBAR ()
; (LET ()
; ,@BOB::FINALIZE
; ,(IF (NOT BOB::DOUBLE)
; '(LOGXOR BOB::V0 BOB::V1 BOB::V2 BOB::V3)
; `(LET ()
; ,@BOB::FINALIZE
; (VALUES BOB::H0 BOB::H1)))))
; --> SB-IMPL::|List*| SB-IMPL::|Append|
; ==>
; 1
;
; note: unable to optimize due to type uncertainty: The first argument is a list, not a null.
;
; compilation unit finished
; printed 2 notes

; wrote /home/brown/bug.fasl
; compilation finished in 0:00:00.036

Revision history for this message
Fedorov Alexander (gleefre) wrote (last edit ):

FWIW

This can be reproduced (at least partly) with a smaller example:

(defun foo (list)
  (declare (optimize speed))
  `(,@list tail))

Generated note:
; in: defun foo
; `(,@LIST TAIL)
; ==>
; 1
;
; note: unable to
; optimize
; due to type uncertainty:
; The first argument is a list, not a null.
;
; compilation unit finished
; printed 1 note

This behavior started in sbcl-2.3.7.

There is a possibly related section in NEWS:
> * optimization: the compiler removes known-NIL arguments from calls to
> APPEND and NCONC, and empty sequences from calls to CONCATENATE.

And it can be reproduced by using APPEND instead of the backquote:

(defun foo (list)
  (declare (optimize speed))
  (append list '(tail)))

Generated note:
; in: defun foo
; (APPEND LIST '(TAIL))
;
; note: unable to
; optimize
; due to type uncertainty:
; The first argument is a list, not a null.
;
; compilation unit finished
; printed 1 note

Stas Boukarev (stassats)
Changed in sbcl:
status: New → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
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.