-
-
Save zoffixznet/f5db2e3a7f197ce556faa630fb5bd680 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 74fbd0a..6b27087 100644 | |
--- a/src/Perl6/Optimizer.nqp | |
+++ b/src/Perl6/Optimizer.nqp | |
@@ -1692,12 +1692,16 @@ class Perl6::Optimizer { | |
} | |
} | |
} | |
- elsif $!level >= 2 && ( | |
- $op.name eq '&prefix:<++>' || $op.name eq '&postfix:<++>' | |
- || $op.name eq '&prefix:<-->' || $op.name eq '&postfix:<-->' | |
- ) && $!symbols.is_from_core($op.name) | |
- && self.optimize-post-pre-inc-dec-ops($op) -> $qast { | |
- return $qast; | |
+ elsif $!symbols.is_from_core($op.name) { | |
+ if $!level >= 2 && ( | |
+ $op.name eq '&prefix:<++>' || $op.name eq '&postfix:<++>' | |
+ || $op.name eq '&prefix:<-->' || $op.name eq '&postfix:<-->' | |
+ ) && self.optimize-post-pre-inc-dec-ops($op) -> $qast { | |
+ return $qast; | |
+ } | |
+ elsif self.optimize-special-core-routine-calls($op, $obj) -> $qast { | |
+ return $qast | |
+ } | |
} | |
# If it's an onlystar proto, we have a couple of options. | |
# The first is that we may be able to work out what to | |
@@ -1781,6 +1785,16 @@ class Perl6::Optimizer { | |
return NQPMu; | |
} | |
+ method optimize-special-core-routine-calls($op, $routine) { | |
+ my $name := $op.name; | |
+ if $op.elems == 0 && ($name eq '&set' || $name eq '&bag' || $name eq '&mix') { | |
+ # argless set/bag/mix return an interned BEGIN-inited object, so we can just | |
+ # execute the call right now and stick that object in place of call | |
+ return QAST::WVal.new: value => $routine() | |
+ } | |
+ NQPMu | |
+ } | |
+ | |
method optimize-post-pre-inc-dec-ops($op) { | |
my $var := $op[0]; | |
my $node := $op.node; | |
diff --git a/src/core/set_operators.pm6 b/src/core/set_operators.pm6 | |
index 7da80a9..891e1a7 100644 | |
--- a/src/core/set_operators.pm6 | |
+++ b/src/core/set_operators.pm6 | |
@@ -1,13 +1,25 @@ | |
proto sub set(|) {*} | |
-multi sub set() { BEGIN nqp::create(Set) } | |
+multi sub set() { | |
+ # Note: static optimizer constant-folds this candidate. If making changes here, ensure that | |
+ # constant-folding it still makes sense or remove constant-folding in static optimizer. | |
+ BEGIN nqp::create(Set) | |
+} | |
multi sub set(*@a --> Set:D) { Set.new(@a) } | |
proto sub bag(|) {*} | |
-multi sub bag() { BEGIN nqp::create(Bag) } | |
+multi sub bag() { | |
+ # Note: static optimizer constant-folds this candidate. If making changes here, ensure that | |
+ # constant-folding it still makes sense or remove constant-folding in static optimizer. | |
+ BEGIN nqp::create(Bag) | |
+} | |
multi sub bag(*@a --> Bag:D) { Bag.new(@a) } | |
proto sub mix(|) {*} | |
-multi sub mix() { BEGIN nqp::create(Mix) } | |
+multi sub mix() { | |
+ # Note: static optimizer constant-folds this candidate. If making changes here, ensure that | |
+ # constant-folding it still makes sense or remove constant-folding in static optimizer. | |
+ BEGIN nqp::create(Mix) | |
+} | |
multi sub mix(*@a --> Mix:D) { Mix.new(@a) } | |
# vim: ft=perl6 expandtab sw=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment