Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Take care not to attempt to inline blocks inside scopes that were dyn…
…amically compiled during BEGIN time; this reified their lexpads, and thus we should not go fiddling with them. We got away with this before, though it was probably never really right.
  • Loading branch information
jnthn committed Mar 1, 2012
1 parent 13d4b0a commit f173558
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Perl6/Optimizer.pm
Expand Up @@ -30,6 +30,7 @@ class Perl6::Optimizer {
$!pres_topic_counter := 0;
%!deadly := nqp::hash();
%!worrying := nqp::hash();
my $*DYNAMICALLY_COMPILED := 0;

# Work out optimization level.
my $*LEVEL := pir::exists(%adverbs, 'optimize') ??
Expand Down Expand Up @@ -75,14 +76,20 @@ class Perl6::Optimizer {
@!block_stack.push($block);

# Visit children.
self.visit_children($block);
if $block<DYNAMICALLY_COMPILED> {
my $*DYNAMICALLY_COMPILED := 1;
self.visit_children($block);
}
else {
self.visit_children($block);
}

# Pop block from block stack.
@!block_stack.pop();

# If the block is immediate, we may be able to inline it.
my $outer := @!block_stack[+@!block_stack - 1];
if $block.blocktype eq 'immediate' {
if $block.blocktype eq 'immediate' && !$*DYNAMICALLY_COMPILED {
# Scan symbols for any non-interesting ones.
my @sigsyms;
for $block.symtable() {
Expand Down Expand Up @@ -380,7 +387,7 @@ class Perl6::Optimizer {
# Extract interesting parts of block.
my $decls := $block.shift;
my $stmts := $block.shift;

# Turn block into an "optimized out" stub (deserialization
# or fixup will still want it to be there).
$block.blocktype('declaration');
Expand Down
3 changes: 3 additions & 0 deletions src/Perl6/World.pm
Expand Up @@ -840,6 +840,9 @@ class Perl6::World is HLL::World {
$i := $i + 1;
}

# Flag block as dynamically compiled.
$past<DYNAMICALLY_COMPILED> := 1;

# Return the Parrot Sub that maps to the thing we were originally
# asked to compile.
$precomp[1]
Expand Down

0 comments on commit f173558

Please sign in to comment.