Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1470)

Unified Diff: src/parsing/parser-base.h

Issue 2509143003: Treat a '!' preceding a function literal as eager-compile hint. (Closed)
Patch Set: Rebase + drop now obsolete FLAG_min_preparse_length. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | test/cctest/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 686c53b51a40487b2fd587458118e7253a5122aa..3d486b88857fb003ec07c63f76701d8c97afec29 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -458,16 +458,12 @@ class ParserBase {
return &non_patterns_to_rewrite_;
}
- bool next_function_is_parenthesized() const {
- return next_function_is_parenthesized_;
+ bool next_function_is_likely_called() const {
+ return next_function_is_likely_called_;
}
- void set_next_function_is_parenthesized(bool parenthesized) {
- next_function_is_parenthesized_ = parenthesized;
- }
-
- bool this_function_is_parenthesized() const {
- return this_function_is_parenthesized_;
+ void set_next_function_is_likely_called() {
+ next_function_is_likely_called_ = true;
}
private:
@@ -508,13 +504,12 @@ class ParserBase {
ZoneList<typename ExpressionClassifier::Error> reported_errors_;
- // If true, the next (and immediately following) function literal is
- // preceded by a parenthesis.
- bool next_function_is_parenthesized_;
-
- // The value of the parents' next_function_is_parenthesized_, as it applies
- // to this function. Filled in by constructor.
- bool this_function_is_parenthesized_;
+ // Record whether the next (=== immediately following) function literal is
+ // preceded by a parenthesis / exclamation mark.
+ // The FunctionState constructor will reset a parents'
+ // next_function_is_likely_called_ to prevent it from being 'reused' in the
+ // next function literal.
+ bool next_function_is_likely_called_;
friend Impl;
friend class Checkpoint;
@@ -1466,13 +1461,10 @@ ParserBase<Impl>::FunctionState::FunctionState(
return_expr_context_(ReturnExprContext::kInsideValidBlock),
non_patterns_to_rewrite_(0, scope->zone()),
reported_errors_(16, scope->zone()),
- next_function_is_parenthesized_(false),
- this_function_is_parenthesized_(false) {
+ next_function_is_likely_called_(false) {
*function_state_stack = this;
if (outer_function_state_) {
- this_function_is_parenthesized_ =
- outer_function_state_->next_function_is_parenthesized_;
- outer_function_state_->next_function_is_parenthesized_ = false;
+ outer_function_state_->next_function_is_likely_called_ = false;
}
}
@@ -1789,8 +1781,9 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
}
// Heuristically try to detect immediately called functions before
// seeing the call parentheses.
- function_state_->set_next_function_is_parenthesized(peek() ==
- Token::FUNCTION);
+ if (peek() == Token::FUNCTION) {
+ function_state_->set_next_function_is_likely_called();
+ }
ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
return expr;
@@ -2944,6 +2937,12 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression(
op = Next();
int pos = position();
+
+ // Assume "! function ..." indicates the function is likely to be called.
+ if (op == Token::NOT && peek() == Token::FUNCTION) {
+ function_state_->set_next_function_is_likely_called();
+ }
+
ExpressionT expression = ParseUnaryExpression(CHECK_OK);
impl()->RewriteNonPattern(CHECK_OK);
« no previous file with comments | « src/parsing/parser.cc ('k') | test/cctest/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698