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

Re: Sealed as Source Annotation



Maury Markowitz maury@remove_this.sympatico.ca.invalid on  2000-07-14 12:45
wrote:

>> In the case of Dylan, a large part of the reason for having "sealing" is
>> to enable more static, faster, code to be generated.
> 
> Why is this? I understand a little of the reasoning in Java, but much of
> this is foreign to my Obj-C experience - the only language/runtime I feel I
> have any basic grasp on it's inner workings. This information does what to
> the compiler's output exactly?  Does it increase dispatch times?

As an extreme example:

define class <foo> () end;

define method frob(x :: <foo>) ... end;

define variable y :: <foo> ...;

frob(y);

will not do any dispatching at all.  Because classes and methods are sealed
by default, and the compiler knows y is a <foo> and it knows there is only
one method for the generic function frob that applies to <foo>s, it can
compile the generic function call directly into a call to the method.

The reasoning in the compiler is more complex for classes with multiple
inheritance, open subclasses, generics with multiple dispatched arguments,
etc., but this gives you an idea of what optimization can be done with
sealed declarations (or conversely, the cost of an open declaration).

[Shameless plug:  there is more information on this subject in the
Performance chapter of _Dylan_Programming_, available at
http://www.fun-o.com/products/books.phtml#dp.]



Follow-Ups: References: