Commit ff8cfa9e authored by verwaest's avatar verwaest Committed by Commit bot

Preparse top-level functions in discardable zones

BUG=

Review-Url: https://codereview.chromium.org/2374963002
Cr-Commit-Position: refs/heads/master@{#39809}
parent 632e261a
......@@ -3546,7 +3546,8 @@ class AstNodeFactory final BASE_EMBEDDED {
}
}
~BodyScope() { factory_->zone_ = prev_zone_; }
void Reset() { factory_->zone_ = prev_zone_; }
~BodyScope() { Reset(); }
private:
AstNodeFactory* factory_;
......
......@@ -1196,6 +1196,7 @@ void DeclarationScope::ResetAfterPreparsing(bool aborted) {
variables_.Clear();
// Make sure we won't walk the scope tree from here on.
inner_scope_ = nullptr;
unresolved_ = nullptr;
// TODO(verwaest): We should properly preparse the parameters (no declarations
// should be created), and reparse on abort.
......
......@@ -127,13 +127,15 @@ class DiscardableZoneScope {
}
}
}
~DiscardableZoneScope() {
void Reset() {
parser_->fni_ = prev_fni_;
parser_->zone_ = prev_zone_;
if (parser_->reusable_preparser_ != nullptr) {
parser_->reusable_preparser_->zone_ = prev_zone_;
}
ast_node_factory_scope_.Reset();
}
~DiscardableZoneScope() { Reset(); }
private:
AstNodeFactory::BodyScope ast_node_factory_scope_;
......@@ -2680,11 +2682,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// will migrate unresolved variable into a Scope in the main Zone.
// TODO(marja): Refactor parsing modes: simplify this.
bool use_temp_zone =
!is_lazy_top_level_function && allow_lazy() &&
function_type == FunctionLiteral::kDeclaration &&
allow_lazy() && function_type == FunctionLiteral::kDeclaration &&
eager_compile_hint != FunctionLiteral::kShouldEagerCompile &&
!(FLAG_validate_asm && scope()->IsAsmModule());
bool is_lazy_inner_function = use_temp_zone && FLAG_lazy_inner_functions;
bool is_lazy_inner_function =
use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function;
// This Scope lives in the main zone. We'll migrate data into that zone later.
DeclarationScope* scope = NewFunctionScope(kind);
......@@ -2698,25 +2700,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
bool should_be_used_once_hint = false;
bool has_duplicate_parameters;
{
// Temporary zones can nest. When we migrate free variables (see below), we
// need to recreate them in the previous Zone.
AstNodeFactory previous_zone_ast_node_factory(ast_value_factory());
previous_zone_ast_node_factory.set_zone(zone());
// Open a new zone scope, which sets our AstNodeFactory to allocate in the
// 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 when the function is parsed.
Zone temp_zone(zone()->allocator());
DiscardableZoneScope zone_scope(this, &temp_zone, use_temp_zone);
FunctionState function_state(&function_state_, &scope_state_, scope);
#ifdef DEBUG
scope->SetScopeName(function_name);
if (use_temp_zone) scope->set_needs_migration();
#endif
ExpressionClassifier formals_classifier(this, &duplicate_finder);
if (is_generator) {
......@@ -2751,6 +2739,23 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// which says whether we need to create an arguments adaptor frame).
if (formals.has_rest) arity--;
{
// Temporary zones can nest. When we migrate free variables (see below), we
// need to recreate them in the previous Zone.
AstNodeFactory previous_zone_ast_node_factory(ast_value_factory());
previous_zone_ast_node_factory.set_zone(zone());
// Open a new zone scope, which sets our AstNodeFactory to allocate in the
// 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 when the function is parsed.
Zone temp_zone(zone()->allocator());
DiscardableZoneScope zone_scope(this, &temp_zone, use_temp_zone);
#ifdef DEBUG
if (use_temp_zone) scope->set_needs_migration();
#endif
// Eager or lazy parse? If is_lazy_top_level_function, we'll parse
// lazily. We'll call SkipLazyFunctionBody, which may decide to abort lazy
// parsing if it suspects that wasn't a good idea. If so (in which case the
......@@ -2778,6 +2783,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
eager_compile_hint = FunctionLiteral::kShouldEagerCompile;
should_be_used_once_hint = true;
scope->ResetAfterPreparsing(true);
zone_scope.Reset();
use_temp_zone = false;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment