Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Constants lists in array slices

by haukex (Archbishop)
on Jul 20, 2018 at 13:04 UTC ( #1218903=note: print w/replies, xml ) Need Help??

in reply to Constants lists in array slices

I get a warning for FL2 Scalar value @row[FL2] better written as $row[FL2] (ignoring that its a constant _list_)
$ ./Porting/ --target=miniperl --start=v5.16.3 --end=v5.26.0 +--expect-fail -e 'use warnings FATAL=>"all"; sub X () {2,3}; my @a=(" +a".."z"); print @a[X]' ... commit 429a25554a608b64c0ee46c1ffe19bab3718a3c8 Author: Father Chrysostomos <> Date: Sat Sep 14 17:23:11 2013 -0700 Reduce false positives for @hsh{$s} and @ary[$s] warnings This resolves tickets #28380 and #114024. Commit 95a31aad5 did something similar to this for the new %hash{. +..} syntax. This commit extends it to @ slices and combines the two code paths. The heuristics in toke.c can easily produce false positives. So t +he op is flagged as being a candidate for the warning. Then when op. +c has the op tree available, it examines it to see whether the heuri +stic may have been a false positive. This avoids bugs with qw "foo bar baz" and sub calls triggering the warning. The source code is no longer available for the warning, so we reco +n- struct it from the op tree, skipping the subscript if it is anythi +ng other than a const op. This means that @hash{$foo} comes out as @hash{...} and @hash{foo} + as @hash{"foo"}. It also meeans that @hash{"]"} is displayed correct +ly instead of as @hash{"]. Commit 95a31aad5 also modified the heuristic for %hash{...} to exe +mpt qw altogether. But it did not exempt it if it was preceded by a t +ab. So this commit rectifies that. This commit also improves the false positive detection by exemptin +g any ops returning lists that can get past toke.cís heuristic. I w +ent through the entire list of ops, but I may have missed some. Also, @ slices on the lhs of = are exempt, as they change the cont +ext and are hence actually useful. $ git tag --contains 429a25554a608b6 ... v5.20.0 ...
Deparsing the code shows that FL and FL2 are called as functions @a[FL()] = @row[FL2()];
$ ./Porting/ --start=v5.16.3 --end=v5.26.0 -e '`$^X -Ilib -MO +=Deparse -e "use constant X=>3,4; \@x[X]"`=~/\@x\[3, 4\]/ and die' ... commit f815dc14d7c5540dfb5d02d001e0101c6266f281 Author: Father Chrysostomos <> Date: Sun Jun 30 00:20:33 2013 -0700 Inline list constants These are inlined the same way as 1..5. We have two ops: rv2av | `-- const The const op returns an AV, which is stored in the op tree, and th +en rv2av flattens it. $ git tag --contains f815dc14d7c5540d ... v5.20.0 ... # *Update:* making sure it's not just the Deparse output that changed. +.. $ ./Porting/ --start=v5.19.0 --end=v5.21.0 -e '`$^X -Ilib -MO +=Concise -e "use constant X=>3,4; \@x[X]"`=~/entersub/ or die' ... commit f815dc14d7c5540dfb5d02d001e0101c6266f281

Replies are listed 'Best First'.
Re^2: Constants lists in array slices
by LanX (Sage) on Jul 20, 2018 at 13:22 UTC
    Thanks, bookmarked to learn more about bisect! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1218903]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2022-11-29 07:23 GMT
Find Nodes?
    Voting Booth?