Skip to content
Permalink
Browse files

Don't destroy the standard QAST::Block structure

We have an optimization that discards a QAST::Stmts that wraps a single
statement. However, we also rely on the standard structure of every
QAST::Block having two QAST::Stmts nodes within in it, and optimizations
are refused in some places if that isn't found. So, never do this at the
top block level.
  • Loading branch information...
jnthn committed Jan 2, 2019
1 parent d836ca4 commit 401a35476356a5c4a51a6478da5a1d5b8d729c48
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/Perl6/Optimizer.nqp
@@ -1005,10 +1005,12 @@ class Perl6::Optimizer {
# Visit children.
if $block.ann('DYNAMICALLY_COMPILED') {
my $*DYNAMICALLY_COMPILED := 1;
self.visit_children($block, :resultchild(+@($block) - 1),:void_default);
self.visit_children($block, :resultchild(+@($block) - 1),
:void_default, :block_structure);
}
else {
self.visit_children($block, :resultchild(+@($block) - 1),:void_default);
self.visit_children($block, :resultchild(+@($block) - 1),
:void_default, :block_structure);
}

# Pop block from block stack and get computed block var info.
@@ -2693,7 +2695,7 @@ class Perl6::Optimizer {

# Visits all of a node's children, and dispatches appropriately.
method visit_children($node, :$skip_selectors, :$resultchild, :$first, :$void_default,
:$handle) {
:$handle, :$block_structure) {
note("method visit_children $!void_context\n" ~ $node.dump) if $!debug;
my int $r := $resultchild // -1;
my int $i := 0;
@@ -2731,7 +2733,8 @@ class Perl6::Optimizer {
elsif nqp::istype($visit, QAST::Block) {
$node[$i] := self.visit_block($visit);
}
elsif nqp::istype($visit, QAST::Stmts) && nqp::elems($visit.list) == 1 && !$visit.named {
elsif !$block_structure && nqp::istype($visit, QAST::Stmts) &&
nqp::elems($visit.list) == 1 && !$visit.named {
self.visit_children($visit,:void_default);
$node[$i] := $visit[0];
}

0 comments on commit 401a354

Please sign in to comment.
You can’t perform that action at this time.