Skip to content

Commit

Permalink
Tests for existing for loop optrees.
Browse files Browse the repository at this point in the history
  • Loading branch information
nwc10 committed Jun 23, 2021
1 parent 69d374a commit df4a859
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -4144,6 +4144,7 @@ ext/B/t/o.t See if O works
ext/B/t/optree_check.t test OptreeCheck apparatus
ext/B/t/optree_concise.t more B::Concise tests
ext/B/t/optree_constants.t B::Concise rendering of optimized constant subs
ext/B/t/optree_for.t for loops
ext/B/t/optree_misc.t misc optree tests
ext/B/t/optree_samples.t various basic codes: if for while
ext/B/t/optree_sort.t inplace sort optimization regression
Expand Down
191 changes: 191 additions & 0 deletions ext/B/t/optree_for.t
@@ -0,0 +1,191 @@
#!perl

BEGIN {
unshift @INC, 't';
require Config;
if (($Config::Config{'extensions'} !~ /\bB\b/) ){
print "1..0 # Skip -- Perl configured without B module\n";
exit 0;
}
if (!$Config::Config{useperlio}) {
print "1..0 # Skip -- need perlio to walk the optree\n";
exit 0;
}
}
use OptreeCheck;
use Config;
plan tests => 11;

pass("FOR LOOPS");

checkOptree ( name => 'for (@a)',
code => sub {for (@a) {}},
bcopts => '-exec',
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 424 optree_for.t:14) v:>,<,%
2 <0> pushmark sM
3 <#> gv[*a] s
4 <1> rv2av[t2] sKRM/1
5 <#> gv[*_] s
6 <{> enteriter(next->8 last->b redo->7) KS/DEF
9 <0> iter s
a <|> and(other->7) K/1
7 <0> stub v
8 <0> unstack s
goto 9
b <2> leaveloop K/2
c <1> leavesub[1 ref] K/REFC,1
EOT_EOT
1 <;> nextstate(main 424 optree_for.t:14) v:>,<,%
2 <0> pushmark sM
3 <$> gv(*a) s
4 <1> rv2av[t1] sKRM/1
5 <$> gv(*_) s
6 <{> enteriter(next->8 last->b redo->7) KS/DEF
9 <0> iter s
a <|> and(other->7) K/1
7 <0> stub v
8 <0> unstack s
goto 9
b <2> leaveloop K/2
c <1> leavesub[1 ref] K/REFC,1
EONT_EONT

my @lexical;

checkOptree ( name => 'for (@lexical)',
code => sub {for (@lexical) {}},
bcopts => '-exec',
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 424 optree_for.t:14) v:>,<,%
2 <0> pushmark sM
3 <0> padav[@lexical:FAKE::7] sRM
4 <#> gv[*_] s
5 <{> enteriter(next->7 last->a redo->6) KS/DEF
8 <0> iter s
9 <|> and(other->6) K/1
6 <0> stub v
7 <0> unstack s
goto 8
a <2> leaveloop K/2
b <1> leavesub[2 refs] K/REFC,1
EOT_EOT
1 <;> nextstate(main 424 optree_for.t:14) v:>,<,%
2 <0> pushmark sM
3 <0> padav[@lexical:FAKE::2] sRM
4 <$> gv(*_) s
5 <{> enteriter(next->7 last->a redo->6) KS/DEF
8 <0> iter s
9 <|> and(other->6) K/1
6 <0> stub v
7 <0> unstack s
goto 8
a <2> leaveloop K/2
b <1> leavesub[2 refs] K/REFC,1
EONT_EONT

checkOptree ( name => 'for $var (@a)',
code => sub {for $var (@a) {}},
bcopts => '-exec',
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 1453 optree_for.t:68) v:{
2 <0> pushmark sM
3 <#> gv[*a] s
4 <1> rv2av[t3] sKRM/1
5 <#> gv[*var] s
6 <1> rv2gv sKRM/1
7 <{> enteriter(next->9 last->c redo->8) KS
a <0> iter s
b <|> and(other->8) K/1
8 <0> stub v
9 <0> unstack s
goto a
c <2> leaveloop KP/2
d <1> leavesub[1 ref] K/REFC,1
EOT_EOT
1 <;> nextstate(main 1453 optree_for.t:67) v:{
2 <0> pushmark sM
3 <$> gv(*a) s
4 <1> rv2av[t1] sKRM/1
5 <$> gv(*var) s
6 <1> rv2gv sKRM/1
7 <{> enteriter(next->9 last->c redo->8) KS
a <0> iter s
b <|> and(other->8) K/1
8 <0> stub v
9 <0> unstack s
goto a
c <2> leaveloop KP/2
d <1> leavesub[1 ref] K/REFC,1
EONT_EONT

checkOptree ( name => 'for my $var (@a)',
code => sub {for my $var (@a) {}},
bcopts => '-exec',
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 1459 optree_for.t:90) v
2 <0> pushmark sM
3 <#> gv[*a] s
4 <1> rv2av[t3] sKRM/1
5 <{> enteriter(next->7 last->a redo->6)[$var:1460,1463] KS/LVINTRO
8 <0> iter s
9 <|> and(other->6) K/1
6 <0> stub v
7 <0> unstack s
goto 8
a <2> leaveloop K/2
b <1> leavesub[1 ref] K/REFC,1
EOT_EOT
1 <;> nextstate(main 424 optree_for.t:14) v:>,<,%
2 <0> pushmark sM
3 <$> gv(*a) s
4 <1> rv2av[t2] sKRM/1
5 <{> enteriter(next->7 last->a redo->6)[$var:1460,1463] KS/LVINTRO
8 <0> iter s
9 <|> and(other->6) K/1
6 <0> stub v
7 <0> unstack s
goto 8
a <2> leaveloop K/2
b <1> leavesub[1 ref] K/REFC,1
EONT_EONT

checkOptree ( name => 'for our $var (@a)',
code => sub {for our $var (@a) {}},
bcopts => '-exec',
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 1466 optree_for.t:100) v
2 <0> pushmark sM
3 <#> gv[*a] s
4 <1> rv2av[t4] sKRM/1
5 <#> gv[*var] s
6 <1> rv2gv sK/FAKE,1
7 <{> enteriter(next->9 last->c redo->8) KS/OURINTR
a <0> iter s
b <|> and(other->8) K/1
8 <0> stub v
9 <0> unstack s
goto a
c <2> leaveloop K/2
d <1> leavesub[1 ref] K/REFC,1
EOT_EOT
1 <;> nextstate(main 424 optree_for.t:111) v:>,<,%
2 <0> pushmark sM
3 <$> gv(*a) s
4 <1> rv2av[t2] sKRM/1
5 <$> gv(*var) s
6 <1> rv2gv sK/FAKE,1
7 <{> enteriter(next->9 last->c redo->8) KS/OURINTR
a <0> iter s
b <|> and(other->8) K/1
8 <0> stub v
9 <0> unstack s
goto a
c <2> leaveloop K/2
d <1> leavesub[1 ref] K/REFC,1
EONT_EONT

0 comments on commit df4a859

Please sign in to comment.