Skip to content
Permalink
Browse files

For blocks containing regexes, don't lower $_

Since we need to look it up when doing `/foo/` in sink or boolean
contexts. Unfortunately, the current semantics of that rely on some
action at a distance (find the nearest defined `$_`, and update the `$/`
in that block); these probably want revisiting. I did attempt to try,
when we closure-clone a regex, to copy the appropriate `$_` into it;
this mostly works, but the case of `not /foo/` depends on it to skip
over the `not` frame, and there is another test which even further
relies on the current behavior. So for now, just don't optimize those
cases.
  • Loading branch information...
jnthn committed Jan 4, 2019
1 parent 31c8fda commit 17bf7415e4ea9dc071560b6d07e913019542c896
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/Perl6/Optimizer.nqp
@@ -31,6 +31,7 @@ my class Symbols {
has $!Block;
has $!PseudoStash;
has $!Routine;
has $!Regex;
has $!Nil;
has $!Failure;
has $!Seq;
@@ -59,6 +60,7 @@ my class Symbols {
$!Block := self.find_lexical('Block');
$!PseudoStash := self.find_lexical('PseudoStash');
$!Routine := self.find_lexical('Routine');
$!Regex := self.find_lexical('Regex');
$!Nil := self.find_lexical('Nil');
$!Failure := self.find_lexical('Failure');
$!Seq := self.find_lexical('Seq');
@@ -101,6 +103,7 @@ my class Symbols {
method Mu() { $!Mu }
method Any() { $!Any }
method Block() { $!Block }
method Regex() { $!Regex }
method PseudoStash() { $!PseudoStash }
method Nil() { $!Nil }
method Failure() { $!Failure }
@@ -438,6 +441,9 @@ my class BlockVarOptimizer {
# If lowering is, for some reason, poisoned.
has int $!poisoned;

# If topic lowering is, for some reason, poisoned.
has int $!topic_poisoned;

# If p6bindsig is used.
has int $!uses_bindsig;

@@ -490,6 +496,8 @@ my class BlockVarOptimizer {

method poison_lowering() { $!poisoned := 1; }

method poison_topic_lowering() { $!topic_poisoned := 1; }

method uses_bindsig() { $!uses_bindsig := 1; }

method entering_handle_handler() { $!in_handle_handler++; }
@@ -674,7 +682,7 @@ my class BlockVarOptimizer {
next unless $sigil eq '$' || $sigil eq '@' || $sigil eq '%';
next unless nqp::chars($name) >= 2 &&
(nqp::iscclass(nqp::const::CCLASS_ALPHABETIC, $name, 1) ||
$can_lower_topic && nqp::eqat($name, '_', 1));
$can_lower_topic && !$!topic_poisoned && nqp::eqat($name, '_', 1));
}

# Also must not lexicalref it.
@@ -2825,6 +2833,9 @@ class Perl6::Optimizer {
if $visit.value =:= $!symbols.PseudoStash {
self.poison_var_lowering();
}
elsif nqp::istype($visit.value, $!symbols.Regex) {
@!block_var_stack[@!block_var_stack - 1].poison_topic_lowering();
}
}
elsif nqp::istype($visit, QAST::ParamTypeCheck) {
self.optimize-param-typecheck: $visit;

0 comments on commit 17bf741

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