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

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



    Date: Tue, 20 Sep 88  19:04:46 CDT
    From: David N Gray <Gray@DSG.csc.ti.com>

    >   (if (and (typep x 'fixnum) (typep y 'fixnum))
    >       (locally (declare (fixnum x y))
    >         ...algorithm using x and y...)
    >       ...similar algorithm using x and y...)
    > 
    > Proposal (DECLARE-TYPE-FREE:ALLOW):
    > 
    > 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.  

You're right.  I cribbed that phrase from the preceding page or two in CLtL,
but here I was making the mistake of talking about what CLtL should say
rather than about what Common Lisp should be.  I also think the word
"binding" should never be used when discussing Lisp, since some people
think it relates to LET (i.e. refers to creating a new variable), some
people think it relates to SYMBOL-VALUE (i.e. refers to the value associated
with a special variable), and some people think it relates to EVAL (i.e.
refers to the value associated with any kind of variable).  How about
"concerns the values that a variable may take on"?  The point is that
it is an error for the value of the variable to be not a member of the
declared type, within the scope of the declaration; all else is editorial.

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

True.  Does the proposal really need to say this?  It's a pretty obvious
consequence.

								       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.

    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.

I don't understand why you think local declarations forbid specialized
representations (within the scope of the declaration) and I don't understand
why you think a local declaration is somehow inferior to a binding declaration.
It seems to me that a type declaration provides some information to the compiler,
and what the compiler does with it is not really the business of the Common Lisp
language specification, and is also rather difficult to discuss without referring
to a specific compiler.

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

I'd rather that the compiler make this transformation, given the information
it needs to be able to do so, than that the users be required to do it by
hand.  Of course, I'd rather that no one ever need to do type declarations
by hand in the first place.