develooper Front page | perl.perl5.porters | Postings from September 2012

[perl #22073] B::Deparse and scoping

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
September 27, 2012 19:04
Subject:
[perl #22073] B::Deparse and scoping
Message ID:
rt-3.6.HEAD-11172-1348797856-1900.22073-15-0@perl.org
On Thu May 01 23:12:03 2003, smcc wrote:
> >>>>> "Juerd" == Juerd  (via RT) writes:
> 
> Juerd> This is a bug report for perl from juerd@cpan.org, generated
> Juerd> with the help of perlbug 1.34 running under perl v5.8.0.
> 
> 
> Juerd> -----------------------------------------------------------------
> Juerd> [Please enter your report here]
> 
> Juerd> Deparse simplifies the loop, but gets scoping wrong when it
> Juerd> does that:
> 
> Juerd> $ perl -MO=Deparse -le'for(my $i = 5;0;1) { } print $i'       
> Juerd> BEGIN { $/ = "\n"; $\ = "\n"; }
> Juerd> my $i = 5;
> Juerd> print $i;
> Juerd> -e syntax OK
> 
> The simplifying is actually being done by perl before B::Deparse sees
> the program, but the simplification is what causes Deparse to miss the
> scoping.
> 
> Looking at the OP tree, you can see that almost nothing remains of the
> original for loop structure:
> 
> % perl -MO=Concise -e 'for (my $i = 5;0;) {} exit'
> 9  <@> leave[$i:1,3] vKP/REFC ->(end)
> 1     <0> enter ->2
> 2     <;> nextstate(main 3 -e:1) v ->3
> 5     <2> sassign vKS/2 ->6
> 3        <$> const[IV 5] s ->4
> 4        <0> padsv[$i:1,3] sRM*/LVINTRO ->5
> 6     <;> nextstate(main 3 -e:1) v ->7
> 7     <;> nextstate(main 4 -e:1) v ->8
> 8     <0> exit v ->9
> 
> For comparison,
> 
> % perl -MO=Concise -e 'my $i = 5; exit'
> 8  <@> leave[$i:1,2] vKP/REFC ->(end)
> 1     <0> enter ->2
> 2     <;> nextstate(main 1 -e:1) v ->3
> 5     <2> sassign vKS/2 ->6
> 3        <$> const[IV 5] s ->4
> 4        <0> padsv[$i:1,2] sRM*/LVINTRO ->5
> 6     <;> nextstate(main 2 -e:1) v ->7
> 7     <0> exit v ->8
> 
> The only differences are the extra nextstate in the ex-for case, and
> the COP sequence numbers which represent the scope information (the
> 1,2 or 1,3 in the padsv OP, corresponding to numbers in the nextstate
> OPs; note that the [$i:1,2] in the leave is a bug in Concise). Most of
> the time, B::Concise gets away without looking at the COP sequence
> numbers, since if you just print the declarations in the same places
> they occurred in the original code, they'll get the right scope. That
> doesn't work here because the scope has been optimized away without
> leaving any structural trace (e.g., no OP_SCOPE).
> 
> This could probably be fixed by another special case in lineseq(),
> perhaps right next to the check that connects the initializations of
> real for(;;) loops with their bodies. Of hand, I can't think of
> another way you'd get consecutive nextstates, so that might be a good
> thing to check for.
> 
>  -- Stephen
> 

Do people believe that there is a problem here which needs fixing?

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=22073

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