sbcl removes optimizes too aggressively

Bug #1558695 reported by Jim Newton
This bug report is a duplicate of:  Bug #309475: FTYPE declaration badness. Edit Remove
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
New
Undecided
Unassigned

Bug Description

In the code below, I've compiled will high debug and high safely and low speed.
Nevertheless, sbcl seems to have too aggressively optimized.

I've defined the local variable f of type (function (B) B), but I've passed a function which
returns. The function, explicitly asserts that the value if of type B when in fact is
the value 12 (not an instance of class B).

I would expect the format to print that (typep ret-val 'B) =nil,
and I would expect the assertion to fail.
But alas, neither of my expectations are met.

(in-package :cl-user)

(defclass B ()
  ())

;; test-function-subtype takes an argument which is a
;; unary function B->B
(defun test-function-subtype (f)
  (declare (type (function (B) B) f)
    (optimize (debug 3) (speed 0) (safety 3)))
  (let ((ret-val (funcall f (make-instance 'B))))
    (format t "ret-val = ~A (typep ret-val 'B)=~A~%" ret-val (typep ret-val 'B))
    (assert (typep ret-val 'B))))

;; But I cannot make the return less specific
(test-function-subtype #'(lambda (b)
      (declare (type B b))
      12))

----------------------------

Here is the version information.

This is SBCL 1.3.0, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

CL-USER> *FEATURES*
(:LISP-UNIT :SWANK :QUICKLISP :ASDF-PACKAGE-SYSTEM :ASDF3.1 :ASDF3 :ASDF2 :ASDF
 :OS-MACOSX :OS-UNIX :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :64-BIT
 :ALIEN-CALLBACKS :ANSI-CL :ASH-RIGHT-VOPS :BSD :C-STACK-IS-CONTROL-STACK
 :COMMON-LISP :COMPARE-AND-SWAP-VOPS :COMPLEX-FLOAT-VOPS :CYCLE-COUNTER :DARWIN
 :DARWIN9-OR-BETTER :FLOAT-EQL-VOPS :FP-AND-PC-STANDARD-SAVE :GENCGC
 :IEEE-FLOATING-POINT :INLINE-CONSTANTS :INODE64 :INTEGER-EQL-VOP
 :INTERLEAVED-RAW-SLOTS :LINKAGE-TABLE :LITTLE-ENDIAN :MACH-EXCEPTION-HANDLER
 :MACH-O :MEMORY-BARRIER-VOPS :MULTIPLY-HIGH-VOPS :OS-PROVIDES-BLKSIZE-T
 :OS-PROVIDES-DLADDR :OS-PROVIDES-DLOPEN :OS-PROVIDES-PUTWC
 :OS-PROVIDES-SUSECONDS-T :PACKAGE-LOCAL-NICKNAMES :PRECISE-ARG-COUNT-ERROR
 :RAW-INSTANCE-INIT-VOPS :SB-DOC :SB-EVAL :SB-LDB :SB-PACKAGE-LOCKS
 :SB-SIMD-PACK :SB-SOURCE-LOCATIONS :SB-TEST :SB-THREAD :SB-UNICODE :SBCL
 :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-FIXED-OBJECTS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-VECTORS
 :STACK-GROWS-DOWNWARD-NOT-UPWARD :SYMBOL-INFO-VOPS :UD2-BREAKPOINTS :UNIX
 :UNWIND-TO-FRAME-AND-CALL-VOP :X86-64)

[sofia:/var] jnewton% uname -a
Darwin sofia.lrde.epita.fr 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
[sofia:/var] jnewton% sbcl --version
SBCL 1.3.0

Revision history for this message
Jim Newton (jimka-issy) wrote : Re: [Bug 1558695] Re: sbcl removes optimizes too aggressively
Download full text (3.6 KiB)

Thanks, can my test case be added to the test case for
https://bugs.launchpad.net/bugs/309475
or has that been done automatically?

I've added myself to the notification list..

Thanks again.

On Thu, Mar 17, 2016 at 6:51 PM, Stas Boukarev <email address hidden> wrote:

> *** This bug is a duplicate of bug 309475 ***
> https://bugs.launchpad.net/bugs/309475
>
> ** This bug has been marked a duplicate of bug 309475
> FTYPE declaration badness
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1558695
>
> Title:
> sbcl removes optimizes too aggressively
>
> Status in SBCL:
> New
>
> Bug description:
> In the code below, I've compiled will high debug and high safely and low
> speed.
> Nevertheless, sbcl seems to have too aggressively optimized.
>
> I've defined the local variable f of type (function (B) B), but I've
> passed a function which
> returns. The function, explicitly asserts that the value if of type B
> when in fact is
> the value 12 (not an instance of class B).
>
> I would expect the format to print that (typep ret-val 'B) =nil,
> and I would expect the assertion to fail.
> But alas, neither of my expectations are met.
>
> (in-package :cl-user)
>
> (defclass B ()
> ())
>
> ;; test-function-subtype takes an argument which is a
> ;; unary function B->B
> (defun test-function-subtype (f)
> (declare (type (function (B) B) f)
> (optimize (debug 3) (speed 0) (safety 3)))
> (let ((ret-val (funcall f (make-instance 'B))))
> (format t "ret-val = ~A (typep ret-val 'B)=~A~%" ret-val (typep
> ret-val 'B))
> (assert (typep ret-val 'B))))
>
> ;; But I cannot make the return less specific
> (test-function-subtype #'(lambda (b)
> (declare (type B b))
> 12))
>
>
> ----------------------------
>
> Here is the version information.
>
> This is SBCL 1.3.0, an implementation of ANSI Common Lisp.
> More information about SBCL is available at <http://www.sbcl.org/>.
>
> CL-USER> *FEATURES*
> (:LISP-UNIT :SWANK :QUICKLISP :ASDF-PACKAGE-SYSTEM :ASDF3.1 :ASDF3
> :ASDF2 :ASDF
> :OS-MACOSX :OS-UNIX :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :64-BIT
> :ALIEN-CALLBACKS :ANSI-CL :ASH-RIGHT-VOPS :BSD :C-STACK-IS-CONTROL-STACK
> :COMMON-LISP :COMPARE-AND-SWAP-VOPS :COMPLEX-FLOAT-VOPS :CYCLE-COUNTER
> :DARWIN
> :DARWIN9-OR-BETTER :FLOAT-EQL-VOPS :FP-AND-PC-STANDARD-SAVE :GENCGC
> :IEEE-FLOATING-POINT :INLINE-CONSTANTS :INODE64 :INTEGER-EQL-VOP
> :INTERLEAVED-RAW-SLOTS :LINKAGE-TABLE :LITTLE-ENDIAN
> :MACH-EXCEPTION-HANDLER
> :MACH-O :MEMORY-BARRIER-VOPS :MULTIPLY-HIGH-VOPS :OS-PROVIDES-BLKSIZE-T
> :OS-PROVIDES-DLADDR :OS-PROVIDES-DLOPEN :OS-PROVIDES-PUTWC
> :OS-PROVIDES-SUSECONDS-T :PACKAGE-LOCAL-NICKNAMES
> :PRECISE-ARG-COUNT-ERROR
> :RAW-INSTANCE-INIT-VOPS :SB-DOC :SB-EVAL :SB-LDB :SB-PACKAGE-LOCKS
> :SB-SIMD-PACK :SB-SOURCE-LOCATIONS :SB-TEST :SB-THREAD :SB-UNICODE :SBCL
> :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-FIXED-OBJECTS
> :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-VECTORS
> :STACK-GROWS-DOWNWARD-NOT...

Read more...

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.