From 7f08c641e557e7ea5657578f33a3430437642ffc Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 1 Nov 2014 19:08:46 -0700 Subject: =?UTF-8?q?Don=E2=80=99t=20inline=20sub(){0;=20$x}=20if=20$x=20cha?= =?UTF-8?q?nges=20elsewhere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- t/op/const-optree.t | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 't/op') 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: # @@ -54,6 +54,26 @@ push @tests, { method => 0, }; +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} }, -- cgit v1.2.1