[Ecls-list] with-accessors && declare

Matthew Mondor mm_lists at pulsar-zone.net
Sun Mar 28 05:17:36 UTC 2010


Hello,

In the following test case:

(defstruct foo
  (bar 0 :type fixnum))

(defun bar (foo)
  (declare (type foo foo))
  (with-accessors ((bar foo-bar)) foo
    (declare (type fixnum bar))
    (the fixnum bar)))

;;; Compiling (DEFUN BAR ...).
;;; Note:
;;;   in file ecl-swank-tmpfile-16306q, position 0
;;;   at (DEFUN BAR ...)
;;;   In function BAR, checking types of arguments FOO.
;;; Warning:
;;;   in file ecl-swank-tmpfile-16306q, position 0
;;;   at (DEFUN BAR ...)
;;;   ! Declaration of type
;;; FIXNUM
;;; was found for not bound variable BAR.

The note seems fine, but what I was wondering was about the warning.  I
know that observation of DECLARE is implementation-dependent, but
SBCL didn't warn for such cases (I guess that it considers
WITH-ACCESSORS binding symbols as being bound, wheareas ECL doesn't)?
The above test code still works fine however.  But I'm not sure if the
warning causes ECL to perhaps produce less optimized code than it could?

Another thing which I am wondering in relation to DECLARE and
structures on ECL: Is using DECLARE there to remind the compiler that
BAR is of type FIXNUM redundant with the :type fixnum in the structure
definition?  I know that SBCL appears to need the extra DECLARE to
optimize the code properly.  However when checking the C generated code
the system seems to know that fixnum is wanted; I see ecl_to_fixnum()
calls in the non-declare case.  In fact with all the declares added,
additional checks are added and the code is slightly slower for the
extra safety (i.e. checking FOO type in the above case).

Thanks again,
-- 
Matt




More information about the ecl-devel mailing list