REDUCE type warning, ignores :INITIAL-VALUE
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
SBCL version 2.0.4.
In some circumstances REDUCE type inference appears to ignore INITIAL-VALUE and assumes that the sequence elements are always passed as the first argument to the lambda. If it has sufficient knowledge of the sequence's type it may issue a warning if the lambda declares something diffent. Don't know if it actually affects code generation.
In the test cases below, the sequence is a vector of STRING, but :INITIAL-VALUE is a fixnum, and the lambda declares it so.
In the first case we define two arrays and declare their types, and then select one of the two to pass to the reduction. The selection appears to be crucial in generating the warning, and it makes no difference whether it appears in the REDUCE form or in the LET assignments.
In the second case, ignoring T2 makes the warning go away; this is done by placing T1 on both sides of the IF: '(if choose t1 t1)'
In the third case, omitting the type declarations for T1 and T2 make the warning go away.
Finally, the first case is repeated to verify it wasn't a one-time problem.
sbcl --no-userinit
This is SBCL 2.0.4, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (defun xbar (choose)
(let* ((t1 (make-array 0 :element-type 'string :initial-contents nil))
(t2 (make-array 0 :element-type 'string :initial-contents nil)))
(declare (type (simple-array string 1) t1 t2))
(reduce (lambda (r x) (declare (type fixnum r) (type t x))
(+ r (sxhash x)))
(the (simple-array string 1) (if choose t1 t2))
; in: DEFUN XBAR
; (REDUCE
; (LAMBDA (R X)
; (DECLARE (TYPE FIXNUM R)
; (TYPE T X))
; (+ R (SXHASH X)))
; (THE (SIMPLE-ARRAY STRING 1)
; (IF CHOOSE
; T1
; T2))
; :INITIAL-VALUE 0)
;
; caught WARNING:
; The function (LAMBDA (R X) :IN XBAR) is called by REDUCE with (STRING STRING) but it accepts (FIXNUM
; T).
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
XBAR
* (defun xbar (choose)
(let* ((t1 (make-array 0 :element-type 'string :initial-contents nil))
(t2 (make-array 0 :element-type 'string :initial-contents nil)))
(declare (type (simple-array string 1) t1 t2) (ignorable t2))
(reduce (lambda (r x) (declare (type fixnum r) (type t x))
(+ r (sxhash x)))
(the (simple-array string 1) (if choose t1 t1))
WARNING: redefining COMMON-
XBAR
* (defun xbar (choose)
(let* ((t1 (make-array 0 :element-type 'string :initial-contents nil))
(t2 (make-array 0 :element-type 'string :initial-contents nil)))
(reduce (lambda (r x) (declare (type fixnum r) (type t x))
(+ r (sxhash x)))
(the (simple-array string 1) (if choose t1 t2))
WARNING: redefining COMMON-
XBAR
* ;; And back to the original case...
(defun xbar (choose)
(let* ((t1 (make-array 0 :element-type 'string :initial-contents nil))
(t2 (make-array 0 :element-type 'string :initial-contents nil)))
(declare (type (simple-array string 1) t1 t2))
(reduce (lambda (r x) (declare (type fixnum r) (type t x))
(+ r (sxhash x)))
(the (simple-array string 1) (if choose t1 t2))
; in: DEFUN XBAR
; (REDUCE
; (LAMBDA (R X)
; (DECLARE (TYPE FIXNUM R)
; (TYPE T X))
; (+ R (SXHASH X)))
; (THE (SIMPLE-ARRAY STRING 1)
; (IF CHOOSE
; T1
; T2))
; :INITIAL-VALUE 0)
;
; caught WARNING:
; The function (LAMBDA (R X) :IN XBAR) is called by REDUCE with (STRING STRING) but it accepts (FIXNUM
; T).
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
WARNING: redefining COMMON-
XBAR
*
Happens on both Linux and OSX.
~ $ uname -a
Linux speedy 5.4.0-20200222a
This is SBCL 2.0.4, an implementation of ANSI Common Lisp.
*features*
(:ASDF-
:NON-BASE-
:COMMON-LISP :ELF :IEEE-FLOATING-
:PACKAGE-
:SB-THREAD :SB-UNICODE :SBCL :UNIX)
$ uname -a
Darwin msouth-
This is SBCL 2.0.4, an implementation of ANSI Common Lisp.
*features*
(:QUICKLISP :SB-BSD-
:ASDF :OS-MACOSX :OS-UNIX :NON-BASE-
:GENCGC :64-BIT :ANSI-CL :BSD :COMMON-LISP :DARWIN :IEEE-FLOATING-
:LITTLE-ENDIAN :MACH-O :PACKAGE-
:SB-PACKAGE-LOCKS :SB-THREAD :SB-UNICODE :SBCL :UNIX)
Changed in sbcl: | |
status: | New → Confirmed |
Changed in sbcl: | |
status: | Confirmed → Fix Committed |
Changed in sbcl: | |
status: | Fix Committed → Fix Released |