sbcl removes optimizes too aggressively
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-
;; unary function B->B
(defun test-function-
(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-
(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://
CL-USER> *FEATURES*
(:LISP-UNIT :SWANK :QUICKLISP :ASDF-PACKAGE-
:OS-MACOSX :OS-UNIX :NON-BASE-
:ALIEN-CALLBACKS :ANSI-CL :ASH-RIGHT-VOPS :BSD :C-STACK-
:COMMON-LISP :COMPARE-
:DARWIN9-OR-BETTER :FLOAT-EQL-VOPS :FP-AND-
:IEEE-
:INTERLEAVED-
:MACH-O :MEMORY-
:OS-PROVIDES-
:OS-PROVIDES-
:RAW-INSTANCE-
:SB-SIMD-PACK :SB-SOURCE-
:STACK-
:STACK-
:STACK-
:UNWIND-
[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-
[sofia:/var] jnewton% sbcl --version
SBCL 1.3.0
Thanks, can my test case be added to the test case for /bugs.launchpad .net/bugs/ 309475
https:/
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 *** /bugs.launchpad .net/bugs/ 309475 /bugs.launchpad .net/bugs/ 1558695 subtype takes an argument which is a subtype (f) subtype #'(lambda (b) ------- ------- ------- www.sbcl. org/>. SYSTEM :ASDF3.1 :ASDF3 CHARS-EXIST- P :ASDF-UNICODE :64-BIT IS-CONTROL- STACK AND-SWAP- VOPS :COMPLEX-FLOAT-VOPS :CYCLE-COUNTER PC-STANDARD- SAVE :GENCGC POINT :INLINE-CONSTANTS :INODE64 :INTEGER-EQL-VOP RAW-SLOTS :LINKAGE-TABLE :LITTLE-ENDIAN -HANDLER BARRIER- VOPS :MULTIPLY-HIGH-VOPS :OS-PROVIDES- BLKSIZE- T SUSECONDS- T :PACKAGE- LOCAL-NICKNAMES ARG-COUNT- ERROR INIT-VOPS :SB-DOC :SB-EVAL :SB-LDB :SB-PACKAGE-LOCKS LOCATIONS :SB-TEST :SB-THREAD :SB-UNICODE :SBCL ALLOCATABLE- CLOSURES :STACK- ALLOCATABLE- FIXED-OBJECTS ALLOCATABLE- LISTS :STACK- ALLOCATABLE- VECTORS GROWS-DOWNWARD- NOT...
> https:/
>
> ** 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:/
>
> 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-
> ;; unary function B->B
> (defun test-function-
> (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-
> (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://
>
> CL-USER> *FEATURES*
> (:LISP-UNIT :SWANK :QUICKLISP :ASDF-PACKAGE-
> :ASDF2 :ASDF
> :OS-MACOSX :OS-UNIX :NON-BASE-
> :ALIEN-CALLBACKS :ANSI-CL :ASH-RIGHT-VOPS :BSD :C-STACK-
> :COMMON-LISP :COMPARE-
> :DARWIN
> :DARWIN9-OR-BETTER :FLOAT-EQL-VOPS :FP-AND-
> :IEEE-FLOATING-
> :INTERLEAVED-
> :MACH-EXCEPTION
> :MACH-O :MEMORY-
> :OS-PROVIDES-DLADDR :OS-PROVIDES-DLOPEN :OS-PROVIDES-PUTWC
> :OS-PROVIDES-
> :PRECISE-
> :RAW-INSTANCE-
> :SB-SIMD-PACK :SB-SOURCE-
> :STACK-
> :STACK-
> :STACK-