diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-11-01 19:08:46 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-11-13 04:49:38 -0800 |
commit | 7f08c641e557e7ea5657578f33a3430437642ffc (patch) | |
tree | 8721c410290ab1ebb2c100ad4a2d2c59b40326e5 /t/op | |
parent | bbd7756c2420ed595497f5969770114617b5abb2 (diff) | |
download | perl-7f08c641e557e7ea5657578f33a3430437642ffc.tar.gz |
Don’t inline sub(){0; $x} if $x changes elsewhere
Some op trees will turn a sub into a constant even if they
are more than just a simple constant or lexical variable. In
particular, a statement optimised away followed by a lexi-
cal variable is eligible for inlining. As discussed in
<20141101170924.17763.qmail@lists-nntp.develooper.com>, make these
more complex op trees follow closure rules properly. If the outer
lexical is used in lvalue context in places other than its declara-
tion, then we should forego inlining.
Diffstat (limited to 't/op')
-rw-r--r-- | t/op/const-optree.t | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/t/op/const-optree.t b/t/op/const-optree.t index 9ef183efc7..0d5d747cf6 100644 --- a/t/op/const-optree.t +++ b/t/op/const-optree.t @@ -8,7 +8,7 @@ BEGIN { require './test.pl'; @INC = '../lib'; } -plan 16; +plan 26; # @tests is an array of hash refs, each of which can have various keys: # @@ -55,6 +55,26 @@ push @tests, { }; push @tests, { + nickname => 'sub () { 0; $x } with $x modified elsewhere', + generator => sub { my $x = 5; my $ret = sub(){0;$x}; $x = 8; $ret }, + retval => 8, + same_retval => 0, + inlinable => 0, + deprecated => 0, + method => 0, +}; + +push @tests, { + nickname => 'sub () { 0; $x } with $x unmodified elsewhere', + generator => sub { my $x = 5; my $y = $x; sub(){0;$x} }, + retval => 5, + same_retval => 0, + inlinable => 1, + deprecated => 0, + method => 0, +}; + +push @tests, { nickname => 'sub:method with simple lexical', generator => sub { my $y; sub():method{$y} }, retval => undef, |