Commit 9768ff47 authored by verwaest's avatar verwaest Committed by Commit bot

Move should_eager_compile and is_lazily_parsed to DeclarationScope

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2423883002
Cr-Commit-Position: refs/heads/master@{#40343}
parent 3c6bbe07
......@@ -294,7 +294,7 @@ bool FunctionLiteral::ShouldEagerCompile() const {
void FunctionLiteral::SetShouldEagerCompile() {
if (body_ == nullptr) return;
scope()->SetShouldEagerCompile();
scope()->set_should_eager_compile();
}
bool FunctionLiteral::AllowsLazyCompilation() {
......
......@@ -271,6 +271,8 @@ void DeclarationScope::SetDefaults() {
function_ = nullptr;
arguments_ = nullptr;
this_function_ = nullptr;
should_eager_compile_ = false;
is_lazily_parsed_ = false;
}
void Scope::SetDefaults() {
......@@ -300,9 +302,6 @@ void Scope::SetDefaults() {
force_context_allocation_ = false;
is_declaration_scope_ = false;
is_lazily_parsed_ = false;
should_eager_compile_ = false;
}
bool Scope::HasSimpleParameters() {
......@@ -310,20 +309,13 @@ bool Scope::HasSimpleParameters() {
return !scope->is_function_scope() || scope->has_simple_parameters();
}
bool Scope::ShouldEagerCompile() const {
if (is_declaration_scope() &&
!AsDeclarationScope()->AllowsLazyCompilation()) {
return true;
}
bool DeclarationScope::ShouldEagerCompile() const {
if (!AllowsLazyCompilation()) return true;
return !is_lazily_parsed_ && should_eager_compile_;
}
void Scope::SetShouldEagerCompile() {
void DeclarationScope::set_should_eager_compile() {
should_eager_compile_ = true;
for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) {
if (inner->is_function_scope()) continue;
inner->SetShouldEagerCompile();
}
}
void DeclarationScope::set_asm_module() {
......@@ -569,7 +561,7 @@ void DeclarationScope::Analyze(ParseInfo* info, AnalyzeMode mode) {
scope->outer_scope()->already_resolved_);
// The outer scope is never lazy.
scope->SetShouldEagerCompile();
scope->set_should_eager_compile();
scope->AllocateVariables(info, mode);
......@@ -1184,6 +1176,14 @@ DeclarationScope* Scope::GetDeclarationScope() {
return scope->AsDeclarationScope();
}
const DeclarationScope* Scope::GetClosureScope() const {
const Scope* scope = this;
while (!scope->is_declaration_scope() || scope->is_block_scope()) {
scope = scope->outer_scope();
}
return scope->AsDeclarationScope();
}
DeclarationScope* Scope::GetClosureScope() {
Scope* scope = this;
while (!scope->is_declaration_scope() || scope->is_block_scope()) {
......@@ -1192,6 +1192,17 @@ DeclarationScope* Scope::GetClosureScope() {
return scope->AsDeclarationScope();
}
bool Scope::NeedsScopeInfo() const {
DCHECK(!already_resolved_);
// A lazily parsed scope doesn't contain enough information to create a
// ScopeInfo from it.
if (!GetClosureScope()->ShouldEagerCompile()) return false;
// The debugger expects all functions to have scope infos.
// TODO(jochen|yangguo): Remove this requirement.
if (is_function_scope()) return true;
return NeedsContext();
}
ModuleScope* Scope::GetModuleScope() {
Scope* scope = this;
DCHECK(!scope->is_script_scope());
......@@ -1446,8 +1457,11 @@ void Scope::Print(int n) {
Indent(n1, "// scope uses 'super' property\n");
}
if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
if (is_lazily_parsed_) Indent(n1, "// lazily parsed\n");
if (should_eager_compile_) Indent(n1, "// will be compiled\n");
if (is_declaration_scope()) {
DeclarationScope* scope = AsDeclarationScope();
if (scope->is_lazily_parsed()) Indent(n1, "// lazily parsed\n");
if (scope->ShouldEagerCompile()) Indent(n1, "// will be compiled\n");
}
if (num_stack_slots_ > 0) {
Indent(n1, "// ");
PrintF("%d stack slots\n", num_stack_slots_);
......@@ -1872,7 +1886,9 @@ void Scope::AllocateVariablesRecursively() {
DCHECK(!already_resolved_);
DCHECK_EQ(0, num_stack_slots_);
// Don't allocate variables of preparsed scopes.
if (is_lazily_parsed_) return;
if (is_declaration_scope() && AsDeclarationScope()->is_lazily_parsed()) {
return;
}
// Allocate variables for inner scopes.
for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
......@@ -1927,20 +1943,11 @@ void Scope::AllocateScopeInfosRecursively(Isolate* isolate, AnalyzeMode mode,
// Allocate ScopeInfos for inner scopes.
for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
AnalyzeMode next_mode = mode;
bool next_eager = should_eager_compile_;
if (scope->is_function_scope()) {
// Make sure all inner scopes have are consistently marked: we can't
// eager compile inner functions of lazy functions, but if a function
// should be eagerly compiled, all its inner scopes are compiled as well.
next_eager = should_eager_compile_ ? scope->ShouldEagerCompile() : false;
// The ScopeIterator which uses the AnalyzeMode::kDebugger only expects
// to find ScopeInfos for the current function and all its inner
// non-function scopes (see ScopeIterator::GetNestedScopeChain).
next_mode = AnalyzeMode::kRegular;
}
scope->should_eager_compile_ = next_eager;
// The ScopeIterator which uses the AnalyzeMode::kDebugger only expects
// to find ScopeInfos for the current function and all its inner
// non-function scopes (see ScopeIterator::GetNestedScopeChain).
AnalyzeMode next_mode =
scope->is_function_scope() ? AnalyzeMode::kRegular : mode;
scope->AllocateScopeInfosRecursively(isolate, next_mode, next_outer_scope);
}
}
......
......@@ -369,6 +369,7 @@ class Scope: public ZoneObject {
// the scope for which a function prologue allocates a context) or declaring
// temporaries.
DeclarationScope* GetClosureScope();
const DeclarationScope* GetClosureScope() const;
// Find the first (non-arrow) function or script scope. This is where
// 'this' is bound, and what determines the function kind.
......@@ -417,14 +418,6 @@ class Scope: public ZoneObject {
void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; }
bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; }
bool is_lazily_parsed() const { return is_lazily_parsed_; }
bool ShouldEagerCompile() const;
// Marks this scope and all inner scopes (except for inner function scopes)
// such that they get eagerly compiled.
void SetShouldEagerCompile();
protected:
explicit Scope(Zone* zone);
......@@ -449,16 +442,7 @@ class Scope: public ZoneObject {
// not deserialized from a context). Also, since NeedsContext() is only
// returning a valid result after variables are resolved, NeedsScopeInfo()
// should also be invoked after resolution.
bool NeedsScopeInfo() const {
DCHECK(!already_resolved_);
// A lazily parsed scope doesn't contain enough information to create a
// ScopeInfo from it.
if (!ShouldEagerCompile()) return false;
// The debugger expects all functions to have scope infos.
// TODO(jochen|yangguo): Remove this requirement.
if (is_function_scope()) return true;
return NeedsContext();
}
bool NeedsScopeInfo() const;
Zone* zone_;
......@@ -528,9 +512,6 @@ class Scope: public ZoneObject {
// True if it holds 'var' declarations.
bool is_declaration_scope_ : 1;
bool is_lazily_parsed_ : 1;
bool should_eager_compile_ : 1;
// Create a non-local variable with a given name.
// These variables are looked up dynamically at runtime.
Variable* NonLocal(const AstRawString* name, VariableMode mode);
......@@ -636,6 +617,10 @@ class DeclarationScope : public Scope {
IsClassConstructor(function_kind())));
}
bool is_lazily_parsed() const { return is_lazily_parsed_; }
bool ShouldEagerCompile() const;
void set_should_eager_compile();
void SetScriptScopeInfo(Handle<ScopeInfo> scope_info) {
DCHECK(is_script_scope());
DCHECK(scope_info_.is_null());
......@@ -839,6 +824,8 @@ class DeclarationScope : public Scope {
bool has_arguments_parameter_ : 1;
// This scope uses "super" property ('super.foo').
bool scope_uses_super_property_ : 1;
bool should_eager_compile_ : 1;
bool is_lazily_parsed_ : 1;
// Parameter list in source order.
ZoneList<Variable*> params_;
......
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