Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stop the optimizer from using what I assume are old semantics for mul…
…ti dispatch
  • Loading branch information
pmurias committed Jun 8, 2017
1 parent 1ac7996 commit ccfa5e5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
5 changes: 1 addition & 4 deletions src/Perl6/Metamodel/BOOTSTRAP.nqp
Expand Up @@ -2567,7 +2567,6 @@ BEGIN {
my int $BIND_VAL_INT := 1;
my int $BIND_VAL_NUM := 2;
my int $BIND_VAL_STR := 3;
my int $ARG_IS_LITERAL := 32;

# Count arguments.
my int $num_args := nqp::elems(@args);
Expand Down Expand Up @@ -2638,7 +2637,6 @@ BEGIN {
my $type_obj := nqp::atpos(nqp::atkey($cur_candidate, 'types'), $i);
my $type_flags := nqp::atpos_i(nqp::atkey($cur_candidate, 'type_flags'), $i);
my int $got_prim := nqp::atpos(@flags, $i) +& 0xF;
my int $literal := nqp::atpos(@flags, $i) +& $ARG_IS_LITERAL;
if $type_flags +& $TYPE_NATIVE_MASK {
# Looking for a natively typed value. Did we get one?
if $got_prim == $BIND_VAL_OBJ {
Expand All @@ -2648,8 +2646,7 @@ BEGIN {
}
if (($type_flags +& $TYPE_NATIVE_INT) && $got_prim != $BIND_VAL_INT)
|| (($type_flags +& $TYPE_NATIVE_NUM) && $got_prim != $BIND_VAL_NUM)
|| (($type_flags +& $TYPE_NATIVE_STR) && $got_prim != $BIND_VAL_STR)
|| ($literal && nqp::atpos_i(nqp::atkey($cur_candidate, 'rwness'), $i)) {
|| (($type_flags +& $TYPE_NATIVE_STR) && $got_prim != $BIND_VAL_STR) {
# Mismatch.
$type_mismatch := 1;
$type_match_possible := 0;
Expand Down
29 changes: 0 additions & 29 deletions src/Perl6/Optimizer.nqp
Expand Up @@ -1877,16 +1877,10 @@ class Perl6::Optimizer {

# Checks arguments to see if we're going to be able to do compile
# time analysis of the call.
my @allo_map := ['', 'Ii', 'Nn', 'Ss'];
my %allo_rev := nqp::hash('Ii', 1, 'Nn', 2, 'Ss', 3);
my @prim_names := ['', 'int', 'num', 'str'];
my int $ARG_IS_LITERAL := 32;
method analyze_args_for_ct_call($op) {
my @types;
my @flags;
my @allomorphs;
my int $num_prim := 0;
my int $num_allo := 0;

# Initial analysis.
for @($op) {
Expand Down Expand Up @@ -1920,37 +1914,14 @@ class Perl6::Optimizer {
}
if $ok_type {
my $prim := nqp::objprimspec($type);
my str $allo := $_.has_compile_time_value && nqp::istype($_, QAST::Want)
?? $_[1] !! '';
@types.push($type);
@flags.push($prim);
@allomorphs.push($allo);
$num_prim := $num_prim + 1 if $prim;
$num_allo := $num_allo + 1 if $allo;
}
else {
return [];
}
}

# See if we have an allomorphic constant that may allow us to do
# a native dispatch with it; takes at least one declaratively
# native argument to make this happen.
if @types == 2 && $num_prim == 1 && $num_allo == 1 {
my int $prim_flag := @flags[0] || @flags[1];
my int $allo_idx := @allomorphs[0] ?? 0 !! 1;
if @allomorphs[$allo_idx] eq @allo_map[$prim_flag] {
@flags[$allo_idx] := $prim_flag +| $ARG_IS_LITERAL;
}
}

# Alternatively, a single arg that is allomorphic will prefer
# the literal too.
if @types == 1 && $num_allo == 1 {
my $rev := %allo_rev{@allomorphs[0]};
@flags[0] := nqp::defined($rev) ?? $rev +| $ARG_IS_LITERAL !! 0;
}

[@types, @flags]
}

Expand Down

1 comment on commit ccfa5e5

@zoffixznet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case it ever comes up, here's the explanation why native multies aren't supposed to autobox: https://irclog.perlgeek.de/perl6-dev/2016-10-25#i_13462673

(and this is the ticket referred to in the discussion: https://rt.perl.org/Ticket/Display.html?id=129844#txn-1433016 )

Please sign in to comment.