Can compiler macros make use of type declarations?

Chaitanya Gupta mail at chaitanyagupta.com
Tue Nov 7 19:04:36 UTC 2017


On 7 November 2017 at 13:56, Antoniotti Marco
<antoniotti.marco at disco.unimib.it> wrote:
> There is a portable (*) re-implementation of the Environment API (including the re-normalization of Franz return values switch) in CLAST.
>
> http://clast.sf.net

Thanks, CLAST looks like a very useful library.

Chaitanya

>
> Cheers
> --
>
> MA
>
>
>
>
>> On Nov 7, 2017, at 06:00 , Steve Haflich <shaflich at gmail.com> wrote:
>>
>> A compiler-macro, just like a regular macro, receives an &environment
>> argument which is supposed to contain (amongst other things) the
>> lexical and global properties of bindings in the environment in which
>> the macro is expanded.  In the original language definition proposed
>> by CLtL  there was  an environment access interface with functions
>> like variablle-information which could return (for instance) what is
>> known about the type of A in the lexical environment in which FOO is
>> expanded.
>>
>> Unfortunately, the environment access system in CLtL was
>> underspecified, there were no existing implementations, and no one was
>> sure an implementation was even possible without imposing large
>> efficiency hits at compile time.  So we of X3J13 removed it from the
>> standard.
>>
>> Duane Rettig of Franz later implemented a portable open-source sane
>> environment module inspired by the original CLtL specification.  This
>> can be used to write a portable CL code walker of any kind, but it
>> won't do you any good unless the code walker that is your favorite
>> implementation's compiler happens to use it.  But fortunately, several
>> implementations provide documented environment access interfaces built
>> into their compilers.  Unfortunately, these interfaces are not defined
>> by the standard, so their use generally makes code nonportable.
>>
>> BTW, a plain INTEGER type declaration is often not as effective as
>> you'd expect because INTEGER type is the union of FIXNUM and BIGNUM.
>> Arithmetic on the  former can generally be inlined in a few machine
>> instructions (particularly if the integer range can be narrowed
>> further) but if  any arguments or the result could be bignums, further
>> runtime type tests and/or callouts will be generated.
>>
>>
>> On Mon, Nov 6, 2017 at 12:43 PM, Chaitanya Gupta
>> <mail at chaitanyagupta.com> wrote:
>>> Let's say I have created a function called `FOO`:
>>>
>>> (defun foo (x)
>>>  ...)
>>>
>>> To optimize this function, I write a compiler macro. Can I make use of
>>> type declarations that users of `FOO` might have made for the argument
>>> `X` that is passed in to it?
>>>
>>> That is, let's say `FOO` is used like this:
>>>
>>> (let ((a (something-that-returns-an-integer)))
>>>  (declare (integer a))
>>>  (foo a))
>>>
>>> The compiler macro for `FOO` cannot make any optimizations on the
>>> value of `A`, but can it take advantage of the fact that `A` is
>>> declared as in `INTEGER` here?
>>>
>>> Chaitanya
>>>
>>
>
> --
> Marco Antoniotti, Associate Professor           tel.    +39 - 02 64 48 79 01
> DISCo, Università Milano Bicocca U14 2043               http://bimib.disco.unimib.it
> Viale Sarca 336
> I-20126 Milan (MI) ITALY
>
> Please check: http://troncopackage.org
>
> Please note that I am not checking my Spam-box anymore.
> Please do not forward this email without asking me first (cum grano salis).
>
>
>
>
>



More information about the pro mailing list