Skip to content
Permalink
Browse files

Don't emit unrequired init code for natives

When we assign to them immediately, then we don't need to retain the
initial zeroing out. Shaves a few cycles off all the things that use
natively typed lexicals.
  • Loading branch information...
jnthn committed Apr 9, 2019
1 parent 69c535e commit 2eb93b2d7dfe7bf33865e1c6516452530f24a1eb
Showing with 22 additions and 8 deletions.
  1. +4 −1 src/Perl6/Actions.nqp
  2. +18 −7 src/Perl6/World.nqp
@@ -3374,6 +3374,9 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
}
elsif $<initializer><sym> eq '=' {
if $past.ann('init_removal') -> $remove {
$remove();
}
$past := assign_op($/, $past, $initast, :initialize);
}
elsif $<initializer><sym> eq '.=' {
@@ -3789,7 +3792,7 @@ class Perl6::Actions is HLL::Actions does STDActions {

# Install the container.
my $cont := $*W.install_lexical_container($BLOCK, $name, %cont_info, $descriptor,
:scope($*SCOPE), :package($package));
:scope($*SCOPE), :package($package), :init_removal($past));

# Set scope and type on container, and if needed emit code to
# reify a generic type or create a fresh container.
@@ -1641,7 +1641,9 @@ class Perl6::World is HLL::World {

# Installs a lexical symbol. Takes a QAST::Block object, name and
# the type of container to install.
method install_lexical_container($block, str $name, %cont_info, $descriptor, :$scope, :$package, :$cont = self.build_container_and_add_to_sc(%cont_info, $descriptor)) {
method install_lexical_container($block, str $name, %cont_info, $descriptor,
:$scope, :$package, :$cont = self.build_container_and_add_to_sc(%cont_info, $descriptor),
:$init_removal) {
# Add to block, if needed. Note that it doesn't really have
# a compile time value.
my $var;
@@ -1670,23 +1672,32 @@ class Perl6::World is HLL::World {
my $prim := %cont_info<sigil> eq '$' && nqp::objprimspec($descriptor.of);
if $prim {
if $scope eq 'state' { nqp::die("Natively typed state variables not yet implemented") }
my $init;
if $prim == 1 || $prim == 4 || $prim == 5 {
$block[0].push(QAST::Op.new( :op('bind'),
$init := QAST::Op.new( :op('bind'),
QAST::Var.new( :scope('lexical'), :name($name) ),
QAST::IVal.new( :value(0) ) ))
QAST::IVal.new( :value(0) ) );
}
elsif $prim == 2 {
$block[0].push(QAST::Op.new( :op('bind'),
$init := QAST::Op.new( :op('bind'),
QAST::Var.new( :scope('lexical'), :name($name) ),
$*W.lang-ver-before('d')
?? QAST::Op.new(:op<nan>)
!! QAST::NVal.new(:value(0e0))
));
);
}
elsif $prim == 3 {
$block[0].push(QAST::Op.new( :op('bind'),
$init := QAST::Op.new( :op('bind'),
QAST::Var.new( :scope('lexical'), :name($name) ),
QAST::SVal.new( :value('') ) ))
QAST::SVal.new( :value('') ) );
}
$block[0].push($init);
if $init_removal {
$init_removal.annotate('init_removal', -> {
$init.shift;
$init.shift;
$init.op('null');
});
}
return nqp::null();
}

0 comments on commit 2eb93b2

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