[gclist] Date: Sat, 17 Jul 1999 05:19:44 -0400

Fergus Henderson fjh@cs.mu.OZ.AU
Tue, 20 Jul 1999 14:04:45 +1000


On 17-Jul-1999, Tim Sweeney <tim@epicgames.com> wrote:
> 2. Since I'm defining my own language, I thought of using a new "visitor"
> keyword (that puts constraints on an object-reference variable), that means
> "this local variable (or function parameter) refers to an object, but it's
> not allowed to 'gain roots', so you can't assign it to a global variable,
> instance variable, or static variable".

That sounds like a nice idea.

Note that you must ensure that the "visitor" keyword cannot be used
on function return values.  Likewise, you must ensure that it cannot
be used on "output" mode arguments, if your language has such things.

...
> The idea behind this is that it enables the compiler to detect that I don't
> need to do any garbage collection work on a temporary object.

Yes, local objects whose address is only ever assigned to "visitor" references
can even be allocated on the stack rather than on the heap.

> Is this a theoretically sound technique?

Provided you restrict the use of visitor objects appropriately,
yes, I'm pretty sure it is theoretically sound.

Standard Pascal used a similar technique for procedure parameters.
Procedure parameters could be passed down to subroutines, but
subroutines could not return procedure results, and you couldn't
have variables or fields which were procedure references.
The only thing you could do with a procedure parameter was to
call it, or to pass it down as an argument to another procedure.
This ensured that Pascal compilers could allocate closures
(references to nested procedures) on the stack rather than on the heap.

I think Modula-2 also used the same technique.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.