Newsgroups: comp.lang.clos
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news4.ner.bbnplanet.net!news3.near.net!paperboy.wellfleet.com!news-feed-1.peachnet.edu!usenet.eel.ufl.edu!news.mathworks.com!tank.news.pipex.net!pipex!howland.reston.ans.net!news.sprintlink.net!in1.uu.net!harlequin.com!epcot!usenet
From: gray@meteor.harlequin.com (David N Gray)
Subject: Re: SLOT-VALUE/WITH-SLOTS vs. standard accessors?
In-Reply-To: Simon Beaumont's message of 4 Sep 1995 18:21:11 GMT
Message-ID: <GRAY.95Sep5160342@meteor.harlequin.com>
Lines: 49
Sender: usenet@harlequin.com (Usenet Maintainer)
Nntp-Posting-Host: meteor.menlo.harlequin.com
Organization: Harlequin, Inc., Menlo Park, CA
References: <pch-3008951031120001@198.3.157.39> <GRAY.95Aug31113636@meteor.harlequin.com> <42fg2n$81p@xenon.bt-sys.bt.co.uk>
Date: Tue, 5 Sep 1995 23:03:42 GMT

In article <42fg2n$81p@xenon.bt-sys.bt.co.uk> Simon Beaumont <simon.beaumont@bt-sys.bt.co.uk> writes:

> My first thought was that this sounded quite reasonable
> but surely any accessors or with-accessors using a specialized
> method argument in the method could be compiled to be equally
> efficient (as slot-value or with-slots)? 

Yes, the accessor methods would be implemented using the optimized
SLOT-VALUE.  But then you have to do a generic function dispatch to get to
the right method.

> Could they not
> (trivially) expand into slot-values in this case and then be 
> subject to identical treatment?

But then you get into the question of when it is safe to expand functions
inline.  What if at some later time some subclass adds an override
definition?  The meaning of SLOT-VALUE is more permanent.

> Therefore the rationale could not be one of efficiency here
> but one of abstraction.

That's certainly part of it -- it is more appropriate for methods belonging
to the class implementation to know about slots than for outside access to
use slots directly.

> Moreover I wonder what form could such otimizations take?

That relates to the microcoded support for slot access on Lisp Machines.
I don't remember clearly, but I think it had to do with the fact that after
having done a generic function dispatch, the slot mapping tables for the
specialized arguments were already in hand for use by a special addressing
mode. 

Perhaps there wouldn't be a similar advantage for Lisp implementations on
conventional hardware.

> Surely to generate fast low level direct access to the slots
> the compiler would have to be also aware of any extending methods
> on e.g. slot-value-using-class in order to inline Well.

True, the usual optimization could not be done if there was a user-defined
SLOT-VALUE-USING-CLASS method.  But SLOT-VALUE-USING-CLASS is a meta object
protocol function, i.e. it is a method on the metaclass, not the class.  So
that is not something expected to change on the fly.  It never was
officially defined, but the intent at one time (and what I implemented on
the Explorer) was that if the metaclass designer defines a
SLOT-VALUE-USING-CLASS method, he should also provide a corresponding
method defining how optimization of SLOT-VALUE is to be done.
