[Ecls-list] with-accessors && declare

Tobias C. Rittweiler tcr at freebits.de
Sun Mar 28 08:23:28 UTC 2010


Matthew Mondor <mm_lists at pulsar-zone.net>
writes:

> 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?

Sounds like ECL does not correctly handle type declarations in
SYMBOL-MACROLET---there was a recent change regarding SM perhaps it's a
regression; type declaration on symbols macros are like expanding to
(THE <type> <symbol-macro-expansion>) throughout the code.

> 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. 

It shouldn't, and for me it doesn't. Try the latest SBCL version.

It's also able to derive the type when you use WITH-SLOTS rather than
WITH-ACCESSORS. (WITH-SLOTS is not portably guaranteed to work on
structures' slots but it works on SBCL, and also ECL iirc. Just too damn
convenient.)

  -T.





More information about the ecl-devel mailing list