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

Unified Diff: src/parsing/parser.cc

Issue 2368313002: Don't use different function scopes when parsing with temp zones (Closed)
Patch Set: Created 4 years, 3 months 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
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 4c7733ffea167f498005c02b183c2eb0f9ba5712..f03fb9dce685399c150e357886f9fa67cdf7d49d 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -2741,11 +2741,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
!(FLAG_validate_asm && scope()->IsAsmModule());
bool is_lazy_inner_function = use_temp_zone && FLAG_lazy_inner_functions;
- DeclarationScope* main_scope = nullptr;
- if (use_temp_zone) {
- // This Scope lives in the main Zone; we'll migrate data into it later.
- main_scope = NewFunctionScope(kind);
- }
+ // This Scope lives in the main zone. We'll migrate data into that zone later.
+ DeclarationScope* scope = NewFunctionScope(kind);
+ SetLanguageMode(scope, language_mode);
ZoneList<Statement*>* body = nullptr;
int arity = -1;
@@ -2765,18 +2763,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// new temporary zone if the preconditions are satisfied, and ensures that
// the previous zone is always restored after parsing the body. To be able
// to do scope analysis correctly after full parsing, we migrate needed
- // information from scope into main_scope when the function has been parsed.
+ // information when the function is parsed.
Zone temp_zone(zone()->allocator());
DiscardableZoneScope zone_scope(this, &temp_zone, use_temp_zone);
- DeclarationScope* scope = NewFunctionScope(kind);
- SetLanguageMode(scope, language_mode);
- if (!use_temp_zone) {
- main_scope = scope;
- } else {
- DCHECK(main_scope->zone() != scope->zone());
- }
-
FunctionState function_state(&function_state_, &scope_state_, scope);
#ifdef DEBUG
scope->SetScopeName(function_name);
@@ -2841,24 +2831,23 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// used once.
eager_compile_hint = FunctionLiteral::kShouldEagerCompile;
should_be_used_once_hint = true;
- } else if (is_lazy_inner_function) {
- DCHECK(main_scope != scope);
- scope->AnalyzePartially(main_scope, &previous_zone_ast_node_factory);
+ scope->ResetAfterPreparsing();
}
}
+
if (!is_lazy_top_level_function && !is_lazy_inner_function) {
body = ParseEagerFunctionBody(function_name, pos, formals, kind,
function_type, CHECK_OK);
materialized_literal_count = function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count();
- if (use_temp_zone) {
- // If the preconditions are correct the function body should never be
- // accessed, but do this anyway for better behaviour if they're wrong.
- body = nullptr;
- DCHECK(main_scope != scope);
- scope->AnalyzePartially(main_scope, &previous_zone_ast_node_factory);
- }
+ }
+
+ if (use_temp_zone || is_lazy_top_level_function) {
marja 2016/09/27 07:14:03 This sounds wrong... is_lazy_inner_function maybe?
marja 2016/09/27 11:17:34 .... and I was confused; use_temp_zone contains th
+ // If the preconditions are correct the function body should never be
+ // accessed, but do this anyway for better behaviour if they're wrong.
+ body = nullptr;
+ scope->AnalyzePartially(&previous_zone_ast_node_factory);
}
// Parsing the body may change the language mode in our scope.
@@ -2895,7 +2884,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Note that the FunctionLiteral needs to be created in the main Zone again.
FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
- function_name, main_scope, body, materialized_literal_count,
+ function_name, scope, body, materialized_literal_count,
expected_property_count, arity, duplicate_parameters, function_type,
eager_compile_hint, kind, pos);
function_literal->set_function_token_position(function_token_pos);
@@ -3480,9 +3469,6 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
function_scope, parsing_module_, logger, is_inner_function, may_abort,
use_counts_);
- // Detaching the scopes created by PreParser from the Scope chain must be done
- // above (see ParseFunctionLiteral & AnalyzePartially).
- if (!is_inner_function) function_scope->ResetAfterPreparsing();
if (pre_parse_timer_ != NULL) {
pre_parse_timer_->Stop();
}
« src/ast/scopes.cc ('K') | « src/ast/scopes.cc ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698