Using MULTIPLE-VALUE-CALL as a conditional in IF can lead to unnecessary STYLE-WARNINGs due to type propagation

Bug #750797 reported by Jean-Philippe Paradis on 2011-04-04
This bug report is a duplicate of:  Bug #309115: inline-expansion and type-inference. Edit Remove
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Undecided
Unassigned

Bug Description

What I do:
(let ((cachep :empty))
  (+
   (if (multiple-value-call #'(lambda (flag)
                                (ecase flag
                                  (:full t)
                                  (:empty nil)))
         cachep)
       'not-a-number
       0)
   10))

What happens:
SBCL reports a STYLE-WARNING:
"This is not a NUMBER: NOT-A-NUMBER"

What I expected to happen:
Since the branch that would eventually result in an error is never actually taken, I shouldn't get a warning.

Note that replacing the MULTIPLE-VALUE-CALL with FUNCALL solves the problem, which hints that this really is a bug and that MULTIPLE-VALUE-CALL is the culprit.

SBCL version: 1.0.42
uname -a: Linux dynamorph 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 2011 i686 GNU/Linux

*features*:
(:SWANK :QUICKLISP :SB-BSD-SOCKETS-ADDRINFO :ASDF2 :ASDF :ANSI-CL :COMMON-LISP
 :SBCL :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE :SB-EVAL
 :SB-SOURCE-LOCATIONS :IEEE-FLOATING-POINT :X86 :UNIX :ELF :LINUX :SB-THREAD
 :LARGEFILE :GENCGC :STACK-GROWS-DOWNWARD-NOT-UPWARD :C-STACK-IS-CONTROL-STACK
 :COMPARE-AND-SWAP-VOPS :UNWIND-TO-FRAME-AND-CALL-VOP :RAW-INSTANCE-INIT-VOPS
 :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-VECTORS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-FIXED-OBJECTS :ALIEN-CALLBACKS
 :CYCLE-COUNTER :INLINE-CONSTANTS :MEMORY-BARRIER-VOPS :LINKAGE-TABLE
 :OS-PROVIDES-DLOPEN :OS-PROVIDES-PUTWC :OS-PROVIDES-SUSECONDS-T)

Nikodemus Siivola (nikodemus) wrote :

Not a MULTIPLE-VALUE-CALL issue, really -- just plain old type inference.

CL-USER> (compile nil `(lambda (x) (+ 1 (if x 1 :not-a-number))))
; in: LAMBDA (X)
; (+ 1
; (IF X
; 1
; :NOT-A-NUMBER))
;
; note: deleting unreachable code
;
; caught WARNING:
; Asserted type NUMBER conflicts with derived type
; (VALUES (MEMBER :NOT-A-NUMBER) &OPTIONAL).
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
; printed 1 note
#<FUNCTION (LAMBDA (X)) {1002C8F649}>
T
T

In your example the difference between MULTIPLE-VALUE-CALL and FUNCALL is due to SBCL's current inability to use type inference with MULTIPLE-VALUE-CALL -- so the IF is not eliminated as it cannot prove that the NOT-A-NUMBER case never happens.

For clarity's sake I'm marking this a duplicate of

Nikodemus Siivola (nikodemus) wrote :

Um, duplicate of bug 309115. See also bug 309113.

Nikodemus Siivola (nikodemus) wrote :

Also pulled the non-optimization of MVC into its own bug 753803.

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

Other bug subscribers