Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only add the return exception handler when there's a return statement…

… in a routine. On Parrot, adding one to a sub that doesn't use it makes the invocation over 3 times more costly; since EXPR and so forth are now wrapped in NQP subs, we really need to save on this.
  • Loading branch information...
commit 910fcac241d39254da0a5e9453cfc54c852bb3f2 1 parent 125d4ab
@jnthn jnthn authored
Showing with 12 additions and 9 deletions.
  1. +6 −6 src/NQP/Actions.pm
  2. +6 −3 src/NQP/Grammar.pm
View
12 src/NQP/Actions.pm
@@ -206,10 +206,6 @@ method statement_control:sym<for>($/) {
make $past;
}
-method statement_control:sym<return>($/) {
- make PAST::Op.new( $<EXPR>.ast, :pasttype('return'), :node($/) );
-}
-
method statement_control:sym<CATCH>($/) {
my $block := $<block>.ast;
push_block_handler($/, $block);
@@ -553,7 +549,9 @@ method routine_def($/) {
else {
$past := $<blockoid>.ast;
$past.blocktype('declaration');
- $past.control('return_pir');
+ if $*RETURN_USED {
+ $past.control('return_pir');
+ }
}
my $block := $past;
@@ -676,7 +674,9 @@ method method_def($/) {
else {
$past := $<blockoid>.ast;
$past.blocktype('declaration');
- $past.control('return_pir');
+ if $*RETURN_USED {
+ $past.control('return_pir');
+ }
}
# Always need an invocant.
View
9 src/NQP/Grammar.pm
@@ -11,9 +11,9 @@ method TOP() {
# Package declarator to meta-package mapping.
my %*HOW;
%*HOW<knowhow> := 'KnowHOW';
- %*HOW<class> := 'NQPClassHOW';
+ %*HOW<class> := 'NQPClassHOW';
%*HOW<grammar> := 'NQPClassHOW';
- %*HOW<role> := 'NQPRoleHOW';
+ %*HOW<role> := 'NQPRoleHOW';
# What attribute class to use with what HOW, plus a default.
my $*DEFAULT-METAATTR := 'NQPAttribute';
@@ -23,6 +23,7 @@ method TOP() {
my $*SCOPE := '';
my $*MULTINESS := '';
my $*INVOCANT_OK := 0;
+ my $*RETURN_USED := 0;
my $*PACKAGE-SETUP;
self.comp_unit;
}
@@ -333,6 +334,7 @@ token routine_declarator:sym<sub> { <sym> <routine_def> }
token routine_declarator:sym<method> { <sym> <method_def> }
rule routine_def {
+ :my $*RETURN_USED := 0;
[ $<sigil>=['&'?]<deflongname> ]?
<.newpad>
[ '(' <signature> ')'
@@ -345,6 +347,7 @@ rule routine_def {
}
rule method_def {
+ :my $*RETURN_USED := 0;
:my $*INVOCANT_OK := 1;
$<private>=['!'?]
<deflongname>?
@@ -627,7 +630,7 @@ token infix:sym<::=> { <sym> <O('%assignment, :pasttype<bind>')> }
token infix:sym<,> { <sym> <O('%comma, :pasttype<list>')> }
-token prefix:sym<return> { <sym> \s <O('%list_prefix, :pasttype<return>')> }
+token prefix:sym<return> { <sym> \s <O('%list_prefix, :pasttype<return>')> { $*RETURN_USED := 1 } }
token prefix:sym<make> { <sym> \s <O('%list_prefix')> }
token term:sym<last> { <sym> }
token term:sym<next> { <sym> }
Please sign in to comment.
Something went wrong with that request. Please try again.