Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use MoarVM's optimized mutli-dispatch path.
This avoids the creation of many CallCapture objects during QAST to
MAST compilation, again knocking some more allocations (one per QAST
node) off.
  • Loading branch information
jnthn committed Mar 9, 2016
1 parent 5cbce49 commit d257c27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/NQP/Actions.nqp
Expand Up @@ -863,8 +863,10 @@ class NQP::Actions is HLL::Actions {
# If it's just got * as a body, make a multi-dispatch enterer.
# Otherwise, need to build a sub.
my $ast;
my int $onlystar;
if $<onlystar> {
$ast := only_star_block();
$onlystar := 1;
}
else {
$ast := $<blockoid>.ast;
Expand Down Expand Up @@ -932,7 +934,7 @@ class NQP::Actions is HLL::Actions {
# this proto will work over, and install them along
# with the proto.
if $*SCOPE eq 'our' { nqp::die('our-scoped protos not yet implemented') }
my $code := $*W.create_code($ast, $name, 1);
my $code := $*W.create_code($ast, $name, 1, :$onlystar);
my $BLOCK := $*W.cur_lexpad();
$BLOCK[0].push(QAST::Op.new(
:op('bind'),
Expand Down Expand Up @@ -1014,8 +1016,10 @@ class NQP::Actions is HLL::Actions {
# If it's just got * as a body, make a multi-dispatch enterer.
# Otherwise, build method block QAST.
my $ast;
my int $onlystar;
if $<onlystar> {
$ast := only_star_block();
$onlystar := 1;
}
else {
$ast := $<blockoid>.ast;
Expand Down Expand Up @@ -1052,7 +1056,7 @@ class NQP::Actions is HLL::Actions {
# Insert it into the method table.
my $meta_meth := $*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method';
my $is_dispatcher := $*MULTINESS eq 'proto';
my $code := $*W.create_code($ast, $name, $is_dispatcher);
my $code := $*W.create_code($ast, $name, $is_dispatcher, :$onlystar);
if $*MULTINESS eq 'multi' { attach_multi_signature($code, $ast); }
$*W.pkg_add_method($*PACKAGE, $meta_meth, $name, $code);
$ast.annotate('code_obj', $code);
Expand Down
11 changes: 8 additions & 3 deletions src/NQP/World.nqp
Expand Up @@ -201,7 +201,8 @@ class NQP::World is HLL::World {

# Registers a code object, and gives it a dynamic compilation thunk.
# Makes a real code object if it's a dispatcher.
method create_code($ast, $name, $is_dispatcher, :$code_type_name = 'NQPRoutine') {
method create_code($ast, $name, $is_dispatcher, :$code_type_name = 'NQPRoutine',
int :$onlystar = 0) {
# See if NQPRoutine is available to wrap this up in.
my $code_type;
my $have_code_type := 0;
Expand Down Expand Up @@ -328,8 +329,12 @@ class NQP::World is HLL::World {
if $have_code_type {
# Create it now.
nqp::bindattr($code_obj, $code_type, '$!do', $dummy);
nqp::bindattr($code_obj, $code_type, '$!dispatchees', compilee_list())
if $is_dispatcher;
if $is_dispatcher {
nqp::bindattr($code_obj, $code_type, '$!dispatchees', compilee_list());
if $onlystar {
nqp::bindattr_i($code_obj, $code_type, '$!onlystar', 1);
}
}
my $slot := self.add_object($code_obj);

# Associate QAST block with code object, which will ensure it is
Expand Down
4 changes: 4 additions & 0 deletions src/core/NQPRoutine.nqp
Expand Up @@ -5,6 +5,7 @@ my knowhow NQPRoutine {
has $!dispatch_cache;
has $!dispatch_order;
has $!clone_callback;
has int $!onlystar;

# Adds a multi-dispatch candidate.
method add_dispatchee($code) {
Expand Down Expand Up @@ -352,6 +353,9 @@ my knowhow NQPRoutine {
method signature() { $!signature }
}
nqp::setinvokespec(NQPRoutine, NQPRoutine, '$!do', nqp::null);
#?if moar
nqp::setmultispec(NQPRoutine, NQPRoutine, '$!onlystar', '$!dispatch_cache');
#?endif
nqp::setboolspec(NQPRoutine, 5, nqp::null());

my knowhow NQPSignature {
Expand Down

0 comments on commit d257c27

Please sign in to comment.