Skip to content
Permalink
Browse files

Empty the unused QAST::Block if { ... } is a hash

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 31c8fda2878d091f54247f034fba3f63b0942e75
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/Perl6/Actions.nqp
@@ -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(
@@ -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');

0 comments on commit 31c8fda

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