Commit 72b78442 authored by verwaest's avatar verwaest Committed by Commit bot

Simplify Scope::AllowsLazyCompilationWithoutContext

Now it just relies on NeedsContext and hence is guaranteed to be in sync.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2262133002
Cr-Commit-Position: refs/heads/master@{#38771}
parent 038be517
...@@ -880,30 +880,6 @@ void DeclarationScope::AllocateVariables(ParseInfo* info, ...@@ -880,30 +880,6 @@ void DeclarationScope::AllocateVariables(ParseInfo* info,
} }
bool Scope::HasTrivialContext() const {
// A function scope has a trivial context if it always is the global
// context. We iteratively scan out the context chain to see if
// there is anything that makes this scope non-trivial; otherwise we
// return true.
for (const Scope* scope = this; scope != NULL; scope = scope->outer_scope_) {
if (scope->is_eval_scope()) return false;
if (scope->InsideWithScope()) return false;
if (scope->ContextLocalCount() > 0) return false;
if (scope->ContextGlobalCount() > 0) return false;
}
return true;
}
bool Scope::HasTrivialOuterContext() const {
if (outer_scope_ == nullptr) return true;
// Note that the outer context may be trivial in general, but the current
// scope may be inside a 'with' statement in which case the outer context
// for this scope is not trivial.
return !is_with_scope() && outer_scope_->HasTrivialContext();
}
bool Scope::AllowsLazyParsing() const { bool Scope::AllowsLazyParsing() const {
// If we are inside a block scope, we must parse eagerly to find out how // If we are inside a block scope, we must parse eagerly to find out how
// to allocate variables on the block scope. At this point, declarations may // to allocate variables on the block scope. At this point, declarations may
...@@ -919,7 +895,14 @@ bool Scope::AllowsLazyCompilation() const { return !force_eager_compilation_; } ...@@ -919,7 +895,14 @@ bool Scope::AllowsLazyCompilation() const { return !force_eager_compilation_; }
bool Scope::AllowsLazyCompilationWithoutContext() const { bool Scope::AllowsLazyCompilationWithoutContext() const {
return !force_eager_compilation_ && HasTrivialOuterContext(); if (force_eager_compilation_) return false;
// Disallow lazy compilation without context if any outer scope needs a
// context.
for (const Scope* scope = outer_scope_; scope != nullptr;
scope = scope->outer_scope_) {
if (scope->NeedsContext()) return false;
}
return true;
} }
...@@ -1163,9 +1146,6 @@ void Scope::Print(int n) { ...@@ -1163,9 +1146,6 @@ void Scope::Print(int n) {
} }
// Scope info. // Scope info.
if (HasTrivialOuterContext()) {
Indent(n1, "// scope has trivial outer context\n");
}
if (is_strict(language_mode())) { if (is_strict(language_mode())) {
Indent(n1, "// strict mode scope\n"); Indent(n1, "// strict mode scope\n");
} }
......
...@@ -382,9 +382,6 @@ class Scope: public ZoneObject { ...@@ -382,9 +382,6 @@ class Scope: public ZoneObject {
// Determine if we can use lazy compilation for this scope without a context. // Determine if we can use lazy compilation for this scope without a context.
bool AllowsLazyCompilationWithoutContext() const; bool AllowsLazyCompilationWithoutContext() const;
// True if the outer context of this scope is always the native context.
bool HasTrivialOuterContext() const;
// The number of contexts between this and scope; zero if this == scope. // The number of contexts between this and scope; zero if this == scope.
int ContextChainLength(Scope* scope); int ContextChainLength(Scope* scope);
...@@ -593,17 +590,8 @@ class Scope: public ZoneObject { ...@@ -593,17 +590,8 @@ class Scope: public ZoneObject {
ParseInfo* info = nullptr, ParseInfo* info = nullptr,
VariableProxy* stack = nullptr); VariableProxy* stack = nullptr);
bool InsideWithScope() const {
for (const Scope* scope = this; scope != nullptr;
scope = scope->outer_scope()) {
if (scope->is_with_scope()) return true;
}
return false;
}
// Scope analysis. // Scope analysis.
void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
bool HasTrivialContext() const;
// Predicates. // Predicates.
bool MustAllocate(Variable* var); bool MustAllocate(Variable* var);
......
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