Skip to content
Permalink
Browse files

We need to cache on name

nqp::objectid is different for each call (not sure why), so that meant
that the cache was filled with stale data.  Now, if an op requests an
META_ASSIGN, and it has no name, then it will take a slower path very
close to what it originally was.  If it *does* have a name, then it will
be cached on the name of the original op.
  • Loading branch information...
lizmat committed Nov 15, 2018
1 parent b83179f commit e8285c01279397966ee0f8dc9dfcf1c5e5420579
Showing with 13 additions and 14 deletions.
  1. +13 −14 src/core/metaops.pm6
@@ -2,24 +2,23 @@
my $METAOP_ASSIGN := nqp::hash;
sub METAOP_ASSIGN(\op) {
nqp::ifnull(
nqp::atkey($METAOP_ASSIGN,nqp::objectid(op)),
nqp::atkey($METAOP_ASSIGN,op.name),
METAOP_ASSIGN_NEW(op)
)
}
sub METAOP_ASSIGN_NEW(\op) {
nqp::bindkey($METAOP_ASSIGN,nqp::objectid(op),nqp::stmts(
(my \metaop := -> Mu \a, Mu \b {
a = op.((a.DEFINITE ?? a !! op.()), b)
}),
metaop.set_name(
nqp::if(
(my \name := op.name),
name.substr(0,*-1) ~ "=>",
"infix:<unnamed-op=>"
)
),
metaop
))
# Fast path the case where there is *no* name for the op. If we *do* have
# a name, then we'll only be here once for that op, so it doesn't matter
# that we call op.name multiple times.
op.name
?? nqp::bindkey($METAOP_ASSIGN,op.name,nqp::stmts(
(my \metaop :=
-> Mu \a, Mu \b { a = op.((a.DEFINITE ?? a !! op.()), b) }
),
metaop.set_name(op.name.substr(0,*-1) ~ "=>"),
metaop
))
!! -> Mu \a, Mu \b { a = op.((a.DEFINITE ?? a !! op.()), b) }
}

sub METAOP_TEST_ASSIGN:<//>(\lhs, $rhs) is raw { lhs // (lhs = $rhs()) }

0 comments on commit e8285c0

Please sign in to comment.
You can’t perform that action at this time.