Brock wrote:
> The idea is simple, insert into the parse tree wherever possible a dealloc
> call for variables that we know (at compile time) are going out of scope /
> no longer referenced.

You probably suspected this, but most great ideas have already been
thought of... ;)

Many languages try to do this, but they do it a little backwards from your
way. If the compiler can figure out if something will not live past the
current block, it can be allocated on the stack. That's a big win because
the stack has a *very* simple allocation model. When the block exits, all
the stack values are destroyed -- there isn't any growth in the ops tree
because the interpreter already knows about block boundaries.

> This, as I said in theory, would take tons of effort
> off of the GC, even a simple reference counting one

Yeah, major wins are possible. The catch however is that it takes a
pretty smart compiler to optimize stack allocations (or a really simple
language like C or Pascal). In perl I think this optimization could
turn on if a block doesn't create a closure (sub {}), doesn't use
a string eval, doesn't call another sub (it's leaf sub), only uses
lexical variables and never takes a ref to a local variable. We can
figure this out almost for free during a parse. If any of these things
do appear, it doesn't mean that variables can't go on the stack, it
just means that it takes a lot more effort to figure out if it's safe.

- Ken

Reply via email to