Commit 287a7152 authored by verwaest's avatar verwaest Committed by Commit bot

Move scope_uses_super_property_ to DeclarationScope

This flag was only set on receiver scopes (declaration scopes) already. This makes it statically obvious.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2268333002
Cr-Commit-Position: refs/heads/master@{#38828}
parent 0f4f30a1
...@@ -199,6 +199,7 @@ void DeclarationScope::SetDefaults() { ...@@ -199,6 +199,7 @@ void DeclarationScope::SetDefaults() {
asm_function_ = false; asm_function_ = false;
force_eager_compilation_ = false; force_eager_compilation_ = false;
has_arguments_parameter_ = false; has_arguments_parameter_ = false;
scope_uses_super_property_ = false;
receiver_ = nullptr; receiver_ = nullptr;
new_target_ = nullptr; new_target_ = nullptr;
function_ = nullptr; function_ = nullptr;
...@@ -229,7 +230,6 @@ void Scope::SetDefaults() { ...@@ -229,7 +230,6 @@ void Scope::SetDefaults() {
set_language_mode(SLOPPY); set_language_mode(SLOPPY);
scope_calls_eval_ = false; scope_calls_eval_ = false;
scope_uses_super_property_ = false;
scope_nonlinear_ = false; scope_nonlinear_ = false;
is_hidden_ = false; is_hidden_ = false;
is_debug_evaluate_scope_ = false; is_debug_evaluate_scope_ = false;
...@@ -587,7 +587,6 @@ void Scope::PropagateUsageFlagsToScope(Scope* other) { ...@@ -587,7 +587,6 @@ void Scope::PropagateUsageFlagsToScope(Scope* other) {
DCHECK_NOT_NULL(other); DCHECK_NOT_NULL(other);
DCHECK(!already_resolved_); DCHECK(!already_resolved_);
DCHECK(!other->already_resolved_); DCHECK(!other->already_resolved_);
if (uses_super_property()) other->RecordSuperPropertyUsage();
if (calls_eval()) other->RecordEvalCall(); if (calls_eval()) other->RecordEvalCall();
} }
...@@ -985,9 +984,8 @@ void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to, ...@@ -985,9 +984,8 @@ void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to,
// Push scope data up to migrate_to. Note that migrate_to and this Scope // Push scope data up to migrate_to. Note that migrate_to and this Scope
// describe the same Scope, just in different Zones. // describe the same Scope, just in different Zones.
PropagateUsageFlagsToScope(migrate_to); PropagateUsageFlagsToScope(migrate_to);
if (inner_scope_calls_eval_) { if (scope_uses_super_property_) migrate_to->scope_uses_super_property_ = true;
migrate_to->inner_scope_calls_eval_ = true; if (inner_scope_calls_eval_) migrate_to->inner_scope_calls_eval_ = true;
}
DCHECK(!force_eager_compilation_); DCHECK(!force_eager_compilation_);
migrate_to->set_start_position(start_position_); migrate_to->set_start_position(start_position_);
migrate_to->set_end_position(end_position_); migrate_to->set_end_position(end_position_);
...@@ -1146,8 +1144,9 @@ void Scope::Print(int n) { ...@@ -1146,8 +1144,9 @@ void Scope::Print(int n) {
if (IsAsmModule()) Indent(n1, "// scope is an asm module\n"); if (IsAsmModule()) Indent(n1, "// scope is an asm module\n");
if (IsAsmFunction()) Indent(n1, "// scope is an asm function\n"); if (IsAsmFunction()) Indent(n1, "// scope is an asm function\n");
if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
if (scope_uses_super_property_) if (is_declaration_scope() && AsDeclarationScope()->uses_super_property()) {
Indent(n1, "// scope uses 'super' property\n"); Indent(n1, "// scope uses 'super' property\n");
}
if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
if (num_stack_slots_ > 0) { if (num_stack_slots_ > 0) {
Indent(n1, "// "); Indent(n1, "// ");
......
...@@ -231,9 +231,6 @@ class Scope: public ZoneObject { ...@@ -231,9 +231,6 @@ class Scope: public ZoneObject {
} }
} }
// Inform the scope that the corresponding code uses "super".
void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; }
// Set the language mode flag (unless disabled by a global flag). // Set the language mode flag (unless disabled by a global flag).
void SetLanguageMode(LanguageMode language_mode) { void SetLanguageMode(LanguageMode language_mode) {
DCHECK(!is_module_scope() || is_strict(language_mode)); DCHECK(!is_module_scope() || is_strict(language_mode));
...@@ -319,8 +316,6 @@ class Scope: public ZoneObject { ...@@ -319,8 +316,6 @@ class Scope: public ZoneObject {
} }
bool IsAsmModule() const; bool IsAsmModule() const;
bool IsAsmFunction() const; bool IsAsmFunction() const;
// Does this scope access "super" property (super.foo).
bool uses_super_property() const { return scope_uses_super_property_; }
// Does this scope have the potential to execute declarations non-linearly? // Does this scope have the potential to execute declarations non-linearly?
bool is_nonlinear() const { return scope_nonlinear_; } bool is_nonlinear() const { return scope_nonlinear_; }
...@@ -518,8 +513,6 @@ class Scope: public ZoneObject { ...@@ -518,8 +513,6 @@ class Scope: public ZoneObject {
// This scope or a nested catch scope or with scope contain an 'eval' call. At // This scope or a nested catch scope or with scope contain an 'eval' call. At
// the 'eval' call site this scope is the declaration scope. // the 'eval' call site this scope is the declaration scope.
bool scope_calls_eval_ : 1; bool scope_calls_eval_ : 1;
// This scope uses "super" property ('super.foo').
bool scope_uses_super_property_ : 1;
// This scope's declarations might not be executed in order (e.g., switch). // This scope's declarations might not be executed in order (e.g., switch).
bool scope_nonlinear_ : 1; bool scope_nonlinear_ : 1;
bool is_hidden_ : 1; bool is_hidden_ : 1;
...@@ -676,6 +669,11 @@ class DeclarationScope : public Scope { ...@@ -676,6 +669,11 @@ class DeclarationScope : public Scope {
return is_function_scope() && IsArrowFunction(function_kind_); return is_function_scope() && IsArrowFunction(function_kind_);
} }
// Inform the scope that the corresponding code uses "super".
void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; }
// Does this scope access "super" property (super.foo).
bool uses_super_property() const { return scope_uses_super_property_; }
bool NeedsHomeObject() const { bool NeedsHomeObject() const {
return scope_uses_super_property_ || return scope_uses_super_property_ ||
(inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) ||
...@@ -886,6 +884,8 @@ class DeclarationScope : public Scope { ...@@ -886,6 +884,8 @@ class DeclarationScope : public Scope {
bool force_eager_compilation_ : 1; bool force_eager_compilation_ : 1;
// This scope has a parameter called "arguments". // This scope has a parameter called "arguments".
bool has_arguments_parameter_ : 1; bool has_arguments_parameter_ : 1;
// This scope uses "super" property ('super.foo').
bool scope_uses_super_property_ : 1;
// Info about the parameter list of a function. // Info about the parameter list of a function.
int arity_; int arity_;
......
...@@ -4395,6 +4395,8 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count, ...@@ -4395,6 +4395,8 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
if (produce_cached_parse_data()) CHECK(log_); if (produce_cached_parse_data()) CHECK(log_);
int function_block_pos = position(); int function_block_pos = position();
DeclarationScope* scope = this->scope()->AsDeclarationScope();
DCHECK(scope->is_function_scope());
if (consume_cached_parse_data() && !cached_parse_data_->rejected()) { if (consume_cached_parse_data() && !cached_parse_data_->rejected()) {
// If we have cached data, we use it to skip parsing the function body. The // If we have cached data, we use it to skip parsing the function body. The
// data contains the information we need to construct the lazy function. // data contains the information we need to construct the lazy function.
...@@ -4406,14 +4408,14 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count, ...@@ -4406,14 +4408,14 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
if (entry.is_valid() && entry.end_pos() > function_block_pos) { if (entry.is_valid() && entry.end_pos() > function_block_pos) {
scanner()->SeekForward(entry.end_pos() - 1); scanner()->SeekForward(entry.end_pos() - 1);
scope()->set_end_position(entry.end_pos()); scope->set_end_position(entry.end_pos());
Expect(Token::RBRACE, CHECK_OK_VOID); Expect(Token::RBRACE, CHECK_OK_VOID);
total_preparse_skipped_ += scope()->end_position() - function_block_pos; total_preparse_skipped_ += scope->end_position() - function_block_pos;
*materialized_literal_count = entry.literal_count(); *materialized_literal_count = entry.literal_count();
*expected_property_count = entry.property_count(); *expected_property_count = entry.property_count();
SetLanguageMode(scope(), entry.language_mode()); SetLanguageMode(scope, entry.language_mode());
if (entry.uses_super_property()) scope()->RecordSuperPropertyUsage(); if (entry.uses_super_property()) scope->RecordSuperPropertyUsage();
if (entry.calls_eval()) scope()->RecordEvalCall(); if (entry.calls_eval()) scope->RecordEvalCall();
return; return;
} }
cached_parse_data_->Reject(); cached_parse_data_->Reject();
...@@ -4439,25 +4441,21 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count, ...@@ -4439,25 +4441,21 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
*ok = false; *ok = false;
return; return;
} }
scope()->set_end_position(logger.end()); scope->set_end_position(logger.end());
Expect(Token::RBRACE, CHECK_OK_VOID); Expect(Token::RBRACE, CHECK_OK_VOID);
total_preparse_skipped_ += scope()->end_position() - function_block_pos; total_preparse_skipped_ += scope->end_position() - function_block_pos;
*materialized_literal_count = logger.literals(); *materialized_literal_count = logger.literals();
*expected_property_count = logger.properties(); *expected_property_count = logger.properties();
SetLanguageMode(scope(), logger.language_mode()); SetLanguageMode(scope, logger.language_mode());
if (logger.uses_super_property()) { if (logger.uses_super_property()) scope->RecordSuperPropertyUsage();
scope()->RecordSuperPropertyUsage(); if (logger.calls_eval()) scope->RecordEvalCall();
}
if (logger.calls_eval()) {
scope()->RecordEvalCall();
}
if (produce_cached_parse_data()) { if (produce_cached_parse_data()) {
DCHECK(log_); DCHECK(log_);
// Position right after terminal '}'. // Position right after terminal '}'.
int body_end = scanner()->location().end_pos; int body_end = scanner()->location().end_pos;
log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, log_->LogFunction(function_block_pos, body_end, *materialized_literal_count,
*expected_property_count, language_mode(), *expected_property_count, language_mode(),
scope()->uses_super_property(), scope()->calls_eval()); scope->uses_super_property(), scope->calls_eval());
} }
} }
......
...@@ -1172,10 +1172,12 @@ void PreParser::ParseLazyFunctionLiteralBody(bool* ok, ...@@ -1172,10 +1172,12 @@ void PreParser::ParseLazyFunctionLiteralBody(bool* ok,
// Position right after terminal '}'. // Position right after terminal '}'.
DCHECK_EQ(Token::RBRACE, scanner()->peek()); DCHECK_EQ(Token::RBRACE, scanner()->peek());
int body_end = scanner()->peek_location().end_pos; int body_end = scanner()->peek_location().end_pos;
DeclarationScope* scope = this->scope()->AsDeclarationScope();
DCHECK(scope->is_function_scope());
log_->LogFunction(body_start, body_end, log_->LogFunction(body_start, body_end,
function_state_->materialized_literal_count(), function_state_->materialized_literal_count(),
function_state_->expected_property_count(), language_mode(), function_state_->expected_property_count(), language_mode(),
scope()->uses_super_property(), scope()->calls_eval()); scope->uses_super_property(), scope->calls_eval());
} }
PreParserExpression PreParser::ParseClassLiteral( PreParserExpression PreParser::ParseClassLiteral(
......
...@@ -1067,7 +1067,7 @@ TEST(ScopeUsesArgumentsSuperThis) { ...@@ -1067,7 +1067,7 @@ TEST(ScopeUsesArgumentsSuperThis) {
CHECK_NOT_NULL(scope->AsDeclarationScope()->arguments()); CHECK_NOT_NULL(scope->AsDeclarationScope()->arguments());
} }
CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0,
scope->uses_super_property()); scope->AsDeclarationScope()->uses_super_property());
if ((source_data[i].expected & THIS) != 0) { if ((source_data[i].expected & THIS) != 0) {
// Currently the is_used() flag is conservative; all variables in a // Currently the is_used() flag is conservative; all variables in a
// script scope are marked as used. // script scope are marked as used.
......
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