Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created July 7, 2014 21:54
Show Gist options
  • Save jnthn/0d83712e55339f1361c2 to your computer and use it in GitHub Desktop.
Save jnthn/0d83712e55339f1361c2 to your computer and use it in GitHub Desktop.
diff --git a/src/Perl6/Optimizer.nqp b/src/Perl6/Optimizer.nqp
index 6632496..7c099bd 100644
--- a/src/Perl6/Optimizer.nqp
+++ b/src/Perl6/Optimizer.nqp
@@ -420,6 +420,9 @@ my class BlockVarOptimizer {
# If lowering is, for some reason, poisoned.
has $!poisoned;
+ # If p6bindsig is used.
+ has int $!uses_bindsig;
+
method add_decl($var) {
if $var.scope eq 'lexical' {
%!decls{$var.name} := $var;
@@ -458,6 +461,8 @@ my class BlockVarOptimizer {
method poison_lowering() { $!poisoned := 1; }
+ method uses_bindsig() { $!uses_bindsig := 1; }
+
method get_decls() { %!decls }
method get_usages_flat() { %!usages_flat }
@@ -509,7 +514,7 @@ my class BlockVarOptimizer {
method delete_unused_magicals($block) {
# Magicals are contextual, so if we call anything when we're done for.
- return 0 if $!calls || $!poisoned;
+ return 0 if $!calls || $!poisoned || $!uses_bindsig;
# Otherwise see if there's any we can kill.
my %kill;
@@ -562,7 +567,8 @@ my class BlockVarOptimizer {
}
method delete_unused_autoslurpy() {
- if !$!poisoned && nqp::existskey(%!decls, '%_') && nqp::elems(@!autoslurpy_setups) == 1
+ if !$!poisoned && !$!uses_bindsig && nqp::existskey(%!decls, '%_')
+ && nqp::elems(@!autoslurpy_setups) == 1
&& nqp::elems(@!autoslurpy_binds) == 1 {
if !nqp::existskey(%!usages_inner, '%_') && nqp::elems(%!usages_flat<%_>) == 1 {
my $to_null := @!autoslurpy_setups[0];
@@ -576,7 +582,7 @@ my class BlockVarOptimizer {
}
method simplify_takedispatcher() {
- unless $!calls {
+ unless $!calls || $!uses_bindsig {
if $!takedispatcher {
$!takedispatcher.op('cleardispatcher');
$!takedispatcher.shift();
@@ -585,7 +591,7 @@ my class BlockVarOptimizer {
}
method lexicals_to_locals() {
- return 0 if $!poisoned;
+ return 0 if $!poisoned || $!uses_bindsig;
for %!decls {
# We're looking for lexical var or param decls.
my $qast := $_.value;
@@ -986,7 +992,7 @@ class Perl6::Optimizer {
}
}
elsif $optype eq 'p6bindsig' {
- self.poison_var_lowering();
+ @!block_var_stack[nqp::elems(@!block_var_stack) - 1].uses_bindsig();
}
elsif $optype eq 'call' || $optype eq 'callmethod' || $optype eq 'chain' {
@!block_var_stack[nqp::elems(@!block_var_stack) - 1].register_call();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment