On Wed, Feb 14, 2001 at 11:26:00AM -0500, Dan Sugalski wrote:
> At 11:03 AM 2/14/2001 -0500, Buddha Buck wrote:
> [Truly profound amount of snippage]
> >I'm sure this idea has flaws. But it's an idea. Tell me what I'm missing.
>
> You've pretty much summed up the current plan.
I have a strong suspicion that this approach will lead to confusing,
hard-to-find bugs in Perl programs. (That is, programs written in
Perl, rather than perl-the-program.) Consider:
sub do_stuff { ... }
{
my $fh = IO::File->new("file");
do_stuff($fh);
}
In this code, the compiler can determine that $fh has no active
references at the end of the block, and $fh->DESTROY will be called.
(The compiler can flag do_stuff() as not preserving any references
to its argument.)
Now consider:
{
my $fh = IO::File->new("file");
do_stuff($fh);
}
sub do_stuff { ... }
In this case, the compiler hasn't seen do_stuff() when it compiles
the block in which $fh is instantiated. Unless it performs multiple
passes, it won't be able to determine that do_stuff() does not
preserve a reference to $fh, and it won't be able to deterministically
call $fh->DESTROY at the end of the block.
This is purest action-at-a-distance. To the programmer, there is
no difference between the two blocks. This can occur in even more
confusing fashions: consider a pair of recursive subs, or autoloaded
subs, or method calls. For example:
sub foo {
my Dog $spot = shift;
my $fh = IO::File->new("file");
$spot->eat_homework($fh);
}
Even with the object type declared, the compiler can make no
assumptions about whether a reference to $fh will be held or not.
Perhaps the Poodle subclass of Dog will hold a reference, and the
Bulldog subclass will not.
I think that there will be few cases when compile-time analysis will
identify places where deterministic finalization can occur. Worse,
any programmer who attempts to code for these cases will leave herself
open for action-at-a-distance code breakage.
Maybe I'm missing something. I hope I am. I think, however, that
Perl will have to decide between deterministic destruction of non-
circular data structures, and a modern garbage collector.
- Damien