[Sbcl-devel] symbol-macros and type declarations in PCL

CLHS says (under TYPE declaration): "A type declaration of a symbol
defined by symbol-macrolet is equivalent to wrapping a the expression
around the expansion of that symbol, although the symbol's macro
expansion is not actually affected."
When PCL walks a method body, doing permutation vector optimizations
for SLOT-VALUE forms, this is not accounted for. Therefore assuming
that FOO in:
(symbol-macrolet (x) object
...
(declare (fixnum x))
...
(foo x)
...)
can benefit from knowing the type of its argument, this loses
currently badly inside a DEFMETHOD when compared to a DEFUN. Of
course, it may be that the permutation vector optimization still
trumps the less of efficiency here, but that depends on FOO.
The attached patch fixes this. I plan to commit this early after the freeze.
Cheers,
-- Nikodemus

Thread view

CLHS says (under TYPE declaration): "A type declaration of a symbol
defined by symbol-macrolet is equivalent to wrapping a the expression
around the expansion of that symbol, although the symbol's macro
expansion is not actually affected."
When PCL walks a method body, doing permutation vector optimizations
for SLOT-VALUE forms, this is not accounted for. Therefore assuming
that FOO in:
(symbol-macrolet (x) object
...
(declare (fixnum x))
...
(foo x)
...)
can benefit from knowing the type of its argument, this loses
currently badly inside a DEFMETHOD when compared to a DEFUN. Of
course, it may be that the permutation vector optimization still
trumps the less of efficiency here, but that depends on FOO.
The attached patch fixes this. I plan to commit this early after the freeze.
Cheers,
-- Nikodemus

"Nikodemus Siivola" <nikodemus@...> writes:
> The attached patch fixes this. I plan to commit this early after the
> freeze.
Good stuff. For your amusement, there's more pain dotted around this
general area:
* CLHS "Declaration TYPE" says: "A type declaration of a symbol
defined by symbol-macrolet is equivalent to wrapping a the
expression around the expansion of that symbol, although the
symbol's macro expansion is not actually affected." We don't
actually obey the "although" part of that.
* the walker's notion of what a declaration is is wrong; I saw the
comment "This form was a call to a macro. Maybe it expanded into a
declare? Recurse to find out.", which is not good.
I didn't actively hunt for more bugs; these are just the ones I found
immediately.
Best,
Christophe
--
<jsnell> though it would be even better to just get rid of the walker
in pcl, if at all possible

On Mon, Oct 27, 2008 at 6:47 PM, Christophe Rhodes <csr21@...> wrote:
> * CLHS "Declaration TYPE" says: "A type declaration of a symbol
> defined by symbol-macrolet is equivalent to wrapping a the
> expression around the expansion of that symbol, although the
> symbol's macro expansion is not actually affected." We don't
> actually obey the "although" part of that.
I don't follow. MACROEXPAND and MACROEXPAND-1 are not affected. That is,
(MACROEXPAND 'X <ENV-WHERE-X-IS-SYMBOL-MACRO-AND-HAS-A-DECLARED-TYPE)
is
<EXPASION-OF-X>, T
not
(THE <TYPE-OF-X> <EXPANSION-OF-X>), T
The walker is transforming the body, not just macroexpanding it.
Therefore adding the THE where appropriate seems like a non-issue.
(And even *MACROEXPAND-HOOK* will only see it in case of
(SETF <SYMBOL-MACRO> <VALUE>)
as
(SETF <SYMBOL-MACRO-EXPANSION> (THE <TYPE> <VALUE>))
. Am I missing something?
> * the walker's notion of what a declaration is is wrong; I saw the
> comment "This form was a call to a macro. Maybe it expanded into a
> declare? Recurse to find out.", which is not good.
Ho, fun...
Cheers,
-- Nikodemus

"Nikodemus Siivola" <nikodemus@...> writes:
> . Am I missing something?
Only that the rest of the system (including the proper compiler)
doesn't do what the walker does... see
<http://paste.lisp.org/display/69301&gt; from when Juho and I were
discussing it.
Christophe