[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue: DECLARE-TYPE-FREE (Version 1)

>   (if (and (typep x 'fixnum) (typep y 'fixnum))
>       (locally (declare (fixnum x y))
>         ...algorithm using x and y...)
>       ...similar algorithm using x and y...)
> Change the phrase "affects only variable bindings" to "concerns variable
> bindings."  Clarify that this makes the above program a valid program
> and that this kind of declaration means the same thing as inserting
> THE in every reference to the variable and every setq of the variable.

The phrase "concerns variable bindings" still doesn't seem right.  There
are really two distinct cases:  a declaration associated with a binding
and a local declaration separate from the binding.  The former differs
because it not only describes the type of values which the variable will
assume, but also permits using a specialized representation for the
variable's value cell.

Should add that if there is both a binding declaration and a local
declaration for the type of the same variable, then, within the scope of
the local declaration, it is an error for the variable to contain a value
which is not a member of the intersection of the two types.  (This implies
that it would be desirable for the compiler to complain if the two types
are disjoint.)

> Rationale:
> There is no reason to forbid this usage, and people have often asked
> for it.

I don't feel good about this because I'm afraid it would encourage users
to make the incorrect assumption that a local declaration is just as good
as a binding declaration.  There will also be some performance penalty in
the compiler for looking up type declarations on a local declaration stack
instead of just having it as part of the variable table entry.

> Cost to Implementors:
> None, it is valid to ignore type declarations.

But some implementations will have the (admittedly slight) cost of
removing or updating an error check.  Besides, you really haven't done the
user any favor to allow him to declare types this way if the compiler is
just going to ignore it, so any implementor that uses type declarations
should feel obligated to support this fully if at all.

> Benefits:
> The above example will not have to be written in the following silly way,
> which only works if x and y are used read-only:
>   (if (and (typep x 'fixnum) (typep y 'fixnum))
>       (let ((x x) (y y))
>         (declare (fixnum x y))
>         ...algorithm using x and y...)
>       ...similar algorithm using x and y...)

But there might actually be an advantage to writing it this way.  If you
are compiling for a conventional machine and the declarations are because
you want the most efficient code generated, then it may be worthwhile to
move the value to a fixnum cell rather than to reference it from a cell
that can hold a tagged object.  On a Lisp Machine where all cells are
tagged, the compiler can optimize out the binding.