Skip to content

Commit

Permalink
Preliminary faster literal postconstraint codegen
Browse files Browse the repository at this point in the history
Makes `sub foo(42) {}; for ^5000_000 {foo 42}` 8.8x faster, but
currently blows up with subsets.

Stash the work for a later time.
  • Loading branch information
zoffixznet committed Jan 12, 2018
1 parent 5dd9ed1 commit fefb86b
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/Perl6/Actions.nqp
Expand Up @@ -8889,18 +8889,37 @@ 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($_);
$var.push: QAST::ParamTypeCheck.new:
nqp::istype($_, $wInt)
?? QAST::Op.new(:op<if>,
QAST::Op.new(:op<isconcrete>, $var-qast),
QAST::Op.new(:op<iseq_I>, $wval, $var-qast))
!! nqp::istype($_, $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::istype($_, $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 fefb86b

Please sign in to comment.