Skip to content

Commit

Permalink
Make constraint checks Num/Int/Str literals 1.1x-10x faster
Browse files Browse the repository at this point in the history
Str is 1.1x / Int is 7.7x / Num is 10x

When code-genning ParamTypeCheck for Num/Int/Str literals
in sigs (e.g. `-> 42 {}`), don't go through .ACCEPTS call
and instead gen pure-nqp-op concreteness and equality check
(nqp::iseq_I needs an explicit decont too; tho others don't)
  • Loading branch information
zoffixznet committed Jan 12, 2018
1 parent 5dd9ed1 commit 65d4876
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/Perl6/Actions.nqp
Expand Up @@ -8889,18 +8889,39 @@ class Perl6::Actions is HLL::Actions does STDActions {
# Apply post-constraints (must come after variable bind, as constraints can
# refer to the var).
if %info<post_constraints> {
my $wInt := $*W.find_symbol: ['Int'], :setting-only;
my $wStr := $*W.find_symbol: ['Str'], :setting-only;
my $wNum := $*W.find_symbol: ['Num'], :setting-only;

for %info<post_constraints> {
my $wval := QAST::WVal.new( :value($_) );
$var.push(QAST::ParamTypeCheck.new(QAST::Op.new(
:op('istrue'),
QAST::Op.new(
:op('callmethod'), :name('ACCEPTS'),
nqp::istype($_, $*W.find_symbol(['Code'], :setting-only))
?? QAST::Op.new( :op('p6capturelex'),
QAST::Op.new( :op('callmethod'), :name('clone'), $wval ) )
!! $wval,
QAST::Var.new( :name($name), :scope('local') )
))));
my $var-qast := QAST::Var.new: :$name, :scope<local>;
my $wval := QAST::WVal.new: :value($_);
my $what := nqp::what($_);
$var.push: QAST::ParamTypeCheck.new:
nqp::eqaddr($what, $wInt)
?? QAST::Op.new(:op<if>,
QAST::Op.new(:op<isconcrete>, $var-qast),
QAST::Op.new(:op<iseq_I>, $wval,
QAST::Op.new: :op<decont>, $var-qast))
!! nqp::eqaddr($what, $wNum)
?? QAST::Op.new(:op<if>,
QAST::Op.new(:op<isconcrete>, $var-qast),
QAST::Op.new(:op<unless>,
QAST::Op.new(:op<iseq_n>, $wval, $var-qast), # equal
QAST::Op.new(:op<if>, # or both are NaNs
QAST::Op.new(:op<isne_n>, $wval, $wval),
QAST::Op.new(:op<isne_n>, $var-qast, $var-qast))))
!! nqp::eqaddr($what, $wStr)
?? QAST::Op.new(:op<if>,
QAST::Op.new(:op<isconcrete>, $var-qast),
QAST::Op.new(:op<iseq_s>, $wval, $var-qast))
!! QAST::Op.new: :op<istrue>, QAST::Op.new: :op<callmethod>,
:name<ACCEPTS>,
nqp::istype($_, $*W.find_symbol: ['Code'], :setting-only)
?? QAST::Op.new(:op<p6capturelex>,
QAST::Op.new: :op<callmethod>, :name<clone>, $wval)
!! $wval,
$var-qast
}
}

Expand Down

0 comments on commit 65d4876

Please sign in to comment.