[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sbcl-devel
Subject:    Re: [Sbcl-devel] [Sbcl-commits] master: Ignore types when in constant-fold-call-p.
From:       Stas Boukarev <stassats () gmail ! com>
Date:       2020-08-05 14:43:01
Message-ID: CAF63=12iHSuGw+xzDjosaUP=GkNEPyZ467C2kQHXxz_OTQFFtw () mail ! gmail ! com
[Download RAW message or body]

I do plan to implement that, since I already know where to put the
delayed warning info.

On Wed, Aug 5, 2020 at 5:40 PM Douglas Katzman <dougk@google.com> wrote:
> 
> I understand exactly what you're saying, it should do more-or-less the same as the \
> SFINAE principle (https://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error) \
> in C++, which is to not complain even though superficially it would seem that the 0 \
> is plugged in to each branch of the typecase. Do you plan to do the necessary \
> change to make it not complain, or do you want me to? 
> On Tue, Aug 4, 2020 at 9:42 PM Douglas Katzman <dougk@google.com> wrote:
> > 
> > Getting a weird new error now (downgraded to a style-warning because it happens \
> > during constant-folding) Try COMPILE-FILE on this test case. Compiling WHAT2 \
> > calls SAP-INT (at compile-time) on 0, but compiling WHAT1 is fine. 
> > (eval-when (:compile-toplevel) (load "~/quicklisp/setup"))
> > 
> > (eval-when (:compile-toplevel) (ql:quickload "cffi"))
> > 
> > (eval-when (:compile-toplevel) (trace sb-sys:sap-int))
> > 
> > 
> > (declaim (inline cast-to-word))
> > 
> > (defun cast-to-word (thing)
> > 
> > (declare (type (or fixnum cffi-sys:foreign-pointer null) thing))
> > 
> > (etypecase thing
> > 
> > (fixnum thing)
> > 
> > (cffi-sys:foreign-pointer (cffi-sys:pointer-address thing))
> > 
> > (null 0)))
> > 
> > 
> > (declaim (ftype (function ((or sb-vm:word null)) (values &optional)) foof))
> > 
> > (defun what1 ()
> > 
> > (foof (cast-to-word 0))
> > 
> > 0)
> > 
> > (defun what2 (mutex)
> > 
> > (sb-thread:with-mutex (mutex) #| empty |#)
> > 
> > (foof (cast-to-word 0))
> > 
> > 0)
> > 
> > 
> > ->
> > 
> > ; processing (DEFUN WHAT2 ...)  0: (SB-SYS:SAP-INT 0)
> > 
> > 
> > ; file: /tmp/weird.lisp
> > 
> > ; in: DEFUN WHAT2
> > 
> > ;     (CAST-TO-WORD 0)
> > 
> > ; --> BLOCK ETYPECASE LET COND IF IF PROGN CFFI-SYS:POINTER-ADDRESS BLOCK
> > 
> > ; ==>
> > 
> > ;   (SB-SYS:SAP-INT CFFI-SYS::PTR)
> > 
> > ;
> > 
> > ; caught STYLE-WARNING:
> > 
> > ;   Lisp error during constant folding:
> > 
> > ;   The value
> > 
> > ;     0
> > 
> > ;   is not of type
> > 
> > ;     SB-SYS:SYSTEM-AREA-POINTER
> > 
> > ;   when binding SB-IMPL::X
> > 
> > ;
> > 
> > ;
> > 
> > 
> > On Sat, Aug 1, 2020 at 1:19 PM stassats via Sbcl-commits \
> > <sbcl-commits@lists.sourceforge.net> wrote:
> > > 
> > > The branch "master" has been updated in SBCL:
> > > via  fc5dfc64faa2308a0d501e3c33bf34804c141dd1 (commit)
> > > from  bf07def12cc4a0644b3fd626eebe0d364b0a43e8 (commit)
> > > 
> > > - Log -----------------------------------------------------------------
> > > commit fc5dfc64faa2308a0d501e3c33bf34804c141dd1
> > > Author: Stas Boukarev <stassats@gmail.com>
> > > Date:   Sat Aug 1 19:58:29 2020 +0300
> > > 
> > > Ignore types when in constant-fold-call-p.
> > > 
> > > constant-lvar-p punts on type mismatches due to bad interactions with
> > > other transforms, but constant folding doesn't mind bad or unknown
> > > types. Without that some constant calls may find their way into VOPs,
> > > which do not like when all arguments are constant.
> > > 
> > > Fixes lp#1888384
> > > ---
> > > src/compiler/ir1opt.lisp   | 17 ++++++++++++++---
> > > tests/compiler-2.pure.lisp |  8 +++++++-
> > > 2 files changed, 21 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/src/compiler/ir1opt.lisp b/src/compiler/ir1opt.lisp
> > > index 6987e9722..71488104b 100644
> > > --- a/src/compiler/ir1opt.lisp
> > > +++ b/src/compiler/ir1opt.lisp
> > > @@ -38,6 +38,17 @@
> > > ;; check for EQL types and singleton numeric types
> > > (values (type-singleton-p type))))))
> > > 
> > > +(defun constant-lvar-ignore-types-p (thing)
> > > +  (declare (type (or lvar null) thing))
> > > +  (and (lvar-p thing)
> > > +       (let* ((type (lvar-type thing))
> > > +              (principal-lvar (principal-lvar thing))
> > > +              (principal-use (lvar-uses principal-lvar)))
> > > +         (or (and (ref-p principal-use)
> > > +                  (constant-p (ref-leaf principal-use)))
> > > +             ;; check for EQL types and singleton numeric types
> > > +             (values (type-singleton-p type))))))
> > > +
> > > ;;; Are all the uses constant?
> > > (defun constant-lvar-uses-p (thing)
> > > (declare (type (or lvar null) thing))
> > > @@ -1684,11 +1695,11 @@
> > > (declare (ignore type lvars))
> > > (unless (if (eql (car annotation) 'function-designator)
> > > (let ((fun (or (lvar-fun-name arg t)
> > > -                                         (and (constant-lvar-p arg)
> > > +                                         (and (constant-lvar-ignore-types-p \
> > > arg) (lvar-value arg)))))
> > > (and fun
> > > (constant-fold-arg-p fun)))
> > > -                          (constant-lvar-p arg))
> > > +                          (constant-lvar-ignore-types-p arg))
> > > (return-from constant-fold-call-p)))
> > > combination
> > > info
> > > @@ -1696,7 +1707,7 @@
> > > (return-from constant-fold-call-p)))
> > > t)
> > > (t
> > > -           (every #'constant-lvar-p args)))))
> > > +           (every #'constant-lvar-ignore-types-p args)))))
> > > 
> > > ;;; Replace a call to a foldable function of constant arguments with
> > > ;;; the result of evaluating the form. If there is an error during the
> > > diff --git a/tests/compiler-2.pure.lisp b/tests/compiler-2.pure.lisp
> > > index 33eb5ca19..962fd16fc 100644
> > > --- a/tests/compiler-2.pure.lisp
> > > +++ b/tests/compiler-2.pure.lisp
> > > @@ -2943,4 +2943,10 @@
> > > (checked-compile-and-assert
> > > ()
> > > `(lambda () (length (make-sequence '(string *) 10 :initial-element #\a)))
> > > -       (() 10)))
> > > +   (() 10)))
> > > +
> > > +(with-test (:name :constant-fold-unknown-types)
> > > +  (checked-compile-and-assert
> > > +   (:allow-style-warnings t)
> > > +   `(lambda ()
> > > +      (oddp (the (or a b) -1)))))
> > > 
> > > -----------------------------------------------------------------------
> > > 
> > > 
> > > hooks/post-receive
> > > --
> > > SBCL
> > > 
> > > 
> > > _______________________________________________
> > > Sbcl-commits mailing list
> > > Sbcl-commits@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/sbcl-commits


_______________________________________________
Sbcl-devel mailing list
Sbcl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic