develooper Front page | perl.perl5.porters | Postings from July 2001

Re: [PATCH B::Deparse] Make warnings handling more robust

Thread Previous | Thread Next
From:
Mike Guy
Date:
July 5, 2001 14:10
Subject:
Re: [PATCH B::Deparse] Make warnings handling more robust
Message ID:
E15IGOf-000045-00@draco.cus.cam.ac.uk
Graham Barr <gbarr@pobox.com> wrote
> It will be optimized away, because there is nothing else that can reference the
> variable. ie the sub is the only thing holding a reference count on the variable,
> so we know it cannot be changed bu anything else

Sadly, no.   At the time the subroutine is compiled, within the scope
of the lexical variable, there is a second reference, from the pad.
How do you know we aren't going to write

{ my $x = 10;
  sub const_x { $x };
  $x = 11;
};

And we can demonstrate directly:

perl -wMO+Deparse
{ my $y = 17;
sub yyy () { $y }
sub xxx () { 17 }
}
print xxx + yyy
__END__
sub yyy () {
    $y;
}
sub xxx () {
    17;
}
{
    my $y = 17;
}
print 17 + yyy;		# <====  xxx optimised, yyy isn't
- syntax OK


Mike Guy

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About