Skip to content

Commit

Permalink
Empty the unused QAST::Block if { ... } is a hash
Browse files Browse the repository at this point in the history
We take the contents of the QAST::Block and use it as the hash.
However, we then failed to clear out the entries inside of that
QAST::Block. This means we would compile that part of the tree twice,
which is both a waste of compilation time and a bunch of bytecode we'll
never run. Furthermore, it turns out this tree duplication in separate
blocks could confuse the optimizer (which is how I discovered it).
  • Loading branch information
jnthn committed Jan 4, 2019
1 parent a4c994f commit 31c8fda
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Perl6/Actions.nqp
Expand Up @@ -6759,8 +6759,9 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
}
if $is_hash && $past.ann('past_block').arity == 0 {
migrate_blocks($past.ann('past_block'), $*W.cur_lexpad());
my @children := @($past.ann('past_block')[1]);
my $orig_block := $past.ann('past_block');
migrate_blocks($orig_block, $*W.cur_lexpad());
my @children := @($orig_block[1]);
$past := QAST::Op.new(
:op('call'),
:name(
Expand Down Expand Up @@ -6798,6 +6799,9 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
}
}
# Clear out the now-unused QAST::Block, so we don't leave it behind in
# the AST.
$orig_block.shift() while @($orig_block);
}
else {
my $block := $past.ann('past_block');
Expand Down

0 comments on commit 31c8fda

Please sign in to comment.