Skip to content

Commit

Permalink
Do a lot less work upon a redeclaration
Browse files Browse the repository at this point in the history
The variable is already there, so we don't need to go and do all of
the things we would were it not. This also avoids scribbling over the
things the optimizer uses to tell the difference between a parameter
or declared variable, fixing an issue introduced by the lexical to
local lowering.
  • Loading branch information
jnthn committed Jan 2, 2019
1 parent 5bbaabb commit 4202453
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Perl6/Actions.nqp
Expand Up @@ -3554,7 +3554,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
}

method variable_declarator($/) {
my $past := $<variable>.ast;
my $qast := $<variable>.ast;
my $sigil := $<variable><sigil>;
my $twigil := $<variable><twigil>;
my $desigilname := ~$<variable><desigilname>;
Expand All @@ -3566,14 +3566,15 @@ class Perl6::Actions is HLL::Actions does STDActions {
$desigilname := nqp::substr($name, nqp::chars($sigil ~ $twigil));
}

my @post;
for $<post_constraint> {
@post.push($_.ast);
}
if $<variable><desigilname> {
my $lex := $*W.cur_lexpad();
if $lex.symbol($name) {
$/.typed_worry('X::Redeclaration', symbol => $name);
unless $name eq '$_' {
$qast.scope('lexical') if nqp::istype($qast, QAST::Var) && !$qast.scope;
make $qast;
return;
}
}
else {
ensure_unused_in_scope($/, $name, $twigil);
Expand All @@ -3582,7 +3583,11 @@ class Perl6::Actions is HLL::Actions does STDActions {
if nqp::elems($<semilist>) > 1 {
$/.panic('Multiple shapes not yet understood');
}
make declare_variable($/, $past, ~$sigil, ~$twigil, $desigilname, $<trait>, $<semilist>, :@post);
my @post;
for $<post_constraint> {
@post.push($_.ast);
}
make declare_variable($/, $qast, ~$sigil, ~$twigil, $desigilname, $<trait>, $<semilist>, :@post);
}

sub ensure_unused_in_scope($/, $name, $twigil) {
Expand Down

0 comments on commit 4202453

Please sign in to comment.