Created
March 31, 2016 22:46
-
-
Save timo/d30f9fc08daf9c6aa67f041ff02096f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Perl6/Optimizer.nqp b/src/Perl6/Optimizer.nqp | |
index 04d30f0..cb329af 100644 | |
--- a/src/Perl6/Optimizer.nqp | |
+++ b/src/Perl6/Optimizer.nqp | |
@@ -33,6 +33,7 @@ my class Symbols { | |
has $!Routine; | |
has $!Nil; | |
has $!Failure; | |
+ has $!Empty; | |
# Top routine, for faking it when optimizing post-inline. | |
has $!fake_top_routine; | |
@@ -59,6 +60,7 @@ my class Symbols { | |
$!Routine := self.find_lexical('Routine'); | |
$!Nil := self.find_lexical('Nil'); | |
$!Failure := self.find_lexical('Failure'); | |
+ $!Empty := self.find_lexical('Empty'); | |
nqp::pop(@!block_stack); | |
} | |
@@ -100,6 +102,7 @@ my class Symbols { | |
method PseudoStash() { $!PseudoStash } | |
method Nil() { $!Nil } | |
method Failure() { $!Failure } | |
+ method Empty() { $!Empty } | |
# The following function is a nearly 1:1 copy of World.find_symbol. | |
# Finds a symbol that has a known value at compile time from the | |
@@ -1211,6 +1214,18 @@ class Perl6::Optimizer { | |
} | |
} | |
+ if $optype eq 'p6sink' { | |
+ my $sinktarget := $op[0]; | |
+ if nqp::istype($sinktarget, QAST::Op) && ($sinktarget.op eq 'unless' || $sinktarget.op eq 'if') { | |
+ if +@($sinktarget) == 3 && nqp::istype($sinktarget[2], QAST::WVal) && $sinktarget[2].value =:= $!symbols.Empty { | |
+ #$sinktarget.pop; | |
+ $sinktarget[1] := QAST::Op.new(:op('p6sink'), $sinktarget[1]); | |
+ self.visit_op_children($op); | |
+ return $op[0]; | |
+ } | |
+ } | |
+ } | |
+ | |
# Visit the children. | |
self.visit_op_children($op); | |
@@ -1741,7 +1756,11 @@ class Perl6::Optimizer { | |
# If it's the sink context void node, then only visit the first | |
# child. Otherwise, see all. | |
if +@($want) == 3 && $want[1] eq 'v' { | |
- self.visit_children($want, :first); | |
+ if $!void_context { | |
+ self.visit_children($want, :skip_selectors); | |
+ } else { | |
+ self.visit_children($want, :first); | |
+ } | |
if $want[0].ann('range_optimized') { | |
$want[2] := $want[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment