Commit 696ae1ee authored by marja's avatar marja Committed by Commit bot

Scopes: Clean up temporaries handling.

There was a weird check in AllocateNonParameterLocal which looked
like ".result" was treated differently from other
temporaries. This couldn't be generalized to other temporaries,
since some temporaries were both in temps_ and params_ (and some,
like ".result" would be only in params_).

Side product: Don't use AstValueFactory in scope analysis. It's
unnecessary (was only used for some DCHECKs which can be replaced
with more general checks). This change also ensures we don't
create new values during scope analysis.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2242783002
Cr-Commit-Position: refs/heads/master@{#38655}
parent 38de91a5
...@@ -853,7 +853,7 @@ void DeclarationScope::AllocateVariables(ParseInfo* info, ...@@ -853,7 +853,7 @@ void DeclarationScope::AllocateVariables(ParseInfo* info,
ResolveVariablesRecursively(info, factory); ResolveVariablesRecursively(info, factory);
// 3) Allocate variables. // 3) Allocate variables.
AllocateVariablesRecursively(info->ast_value_factory()); AllocateVariablesRecursively();
} }
...@@ -1610,11 +1610,8 @@ void DeclarationScope::AllocateReceiver() { ...@@ -1610,11 +1610,8 @@ void DeclarationScope::AllocateReceiver() {
AllocateParameter(receiver(), -1); AllocateParameter(receiver(), -1);
} }
void Scope::AllocateNonParameterLocal(Variable* var, void Scope::AllocateNonParameterLocal(Variable* var) {
AstValueFactory* ast_value_factory) {
DCHECK(var->scope() == this); DCHECK(var->scope() == this);
DCHECK(var->raw_name() != ast_value_factory->dot_result_string() ||
!var->IsStackLocal());
if (var->IsUnallocated() && MustAllocate(var)) { if (var->IsUnallocated() && MustAllocate(var)) {
if (MustAllocateInContext(var)) { if (MustAllocateInContext(var)) {
AllocateHeapSlot(var); AllocateHeapSlot(var);
...@@ -1624,11 +1621,8 @@ void Scope::AllocateNonParameterLocal(Variable* var, ...@@ -1624,11 +1621,8 @@ void Scope::AllocateNonParameterLocal(Variable* var,
} }
} }
void Scope::AllocateDeclaredGlobal(Variable* var, void Scope::AllocateDeclaredGlobal(Variable* var) {
AstValueFactory* ast_value_factory) {
DCHECK(var->scope() == this); DCHECK(var->scope() == this);
DCHECK(var->raw_name() != ast_value_factory->dot_result_string() ||
!var->IsStackLocal());
if (var->IsUnallocated()) { if (var->IsUnallocated()) {
if (var->IsStaticGlobalObjectProperty()) { if (var->IsStaticGlobalObjectProperty()) {
DCHECK_EQ(-1, var->index()); DCHECK_EQ(-1, var->index());
...@@ -1642,13 +1636,12 @@ void Scope::AllocateDeclaredGlobal(Variable* var, ...@@ -1642,13 +1636,12 @@ void Scope::AllocateDeclaredGlobal(Variable* var,
} }
} }
void Scope::AllocateNonParameterLocalsAndDeclaredGlobals( void Scope::AllocateNonParameterLocalsAndDeclaredGlobals() {
AstValueFactory* ast_value_factory) {
// All variables that have no rewrite yet are non-parameter locals. // All variables that have no rewrite yet are non-parameter locals.
if (is_declaration_scope()) { if (is_declaration_scope()) {
ZoneList<Variable*>* temps = AsDeclarationScope()->temps(); ZoneList<Variable*>* temps = AsDeclarationScope()->temps();
for (int i = 0; i < temps->length(); i++) { for (int i = 0; i < temps->length(); i++) {
AllocateNonParameterLocal((*temps)[i], ast_value_factory); AllocateNonParameterLocal((*temps)[i]);
} }
} }
...@@ -1662,31 +1655,31 @@ void Scope::AllocateNonParameterLocalsAndDeclaredGlobals( ...@@ -1662,31 +1655,31 @@ void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(
vars.Sort(VarAndOrder::Compare); vars.Sort(VarAndOrder::Compare);
int var_count = vars.length(); int var_count = vars.length();
for (int i = 0; i < var_count; i++) { for (int i = 0; i < var_count; i++) {
AllocateNonParameterLocal(vars[i].var(), ast_value_factory); AllocateNonParameterLocal(vars[i].var());
} }
if (FLAG_global_var_shortcuts) { if (FLAG_global_var_shortcuts) {
for (int i = 0; i < var_count; i++) { for (int i = 0; i < var_count; i++) {
AllocateDeclaredGlobal(vars[i].var(), ast_value_factory); AllocateDeclaredGlobal(vars[i].var());
} }
} }
if (is_declaration_scope()) { if (is_declaration_scope()) {
AsDeclarationScope()->AllocateLocals(ast_value_factory); AsDeclarationScope()->AllocateLocals();
} }
} }
void DeclarationScope::AllocateLocals(AstValueFactory* ast_value_factory) { void DeclarationScope::AllocateLocals() {
// For now, function_ must be allocated at the very end. If it gets // For now, function_ must be allocated at the very end. If it gets
// allocated in the context, it must be the last slot in the context, // allocated in the context, it must be the last slot in the context,
// because of the current ScopeInfo implementation (see // because of the current ScopeInfo implementation (see
// ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
if (function_ != nullptr) { if (function_ != nullptr) {
AllocateNonParameterLocal(function_, ast_value_factory); AllocateNonParameterLocal(function_);
} }
if (rest_parameter_ != nullptr) { if (rest_parameter_ != nullptr) {
AllocateNonParameterLocal(rest_parameter_, ast_value_factory); AllocateNonParameterLocal(rest_parameter_);
} }
if (new_target_ != nullptr && !MustAllocate(new_target_)) { if (new_target_ != nullptr && !MustAllocate(new_target_)) {
...@@ -1713,13 +1706,13 @@ void DeclarationScope::AllocateModuleVariables() { ...@@ -1713,13 +1706,13 @@ void DeclarationScope::AllocateModuleVariables() {
} }
} }
void Scope::AllocateVariablesRecursively(AstValueFactory* ast_value_factory) { void Scope::AllocateVariablesRecursively() {
if (!already_resolved()) { if (!already_resolved()) {
num_stack_slots_ = 0; num_stack_slots_ = 0;
} }
// Allocate variables for inner scopes. // Allocate variables for inner scopes.
for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
scope->AllocateVariablesRecursively(ast_value_factory); scope->AllocateVariablesRecursively();
} }
// If scope is already resolved, we still need to allocate // If scope is already resolved, we still need to allocate
...@@ -1738,7 +1731,7 @@ void Scope::AllocateVariablesRecursively(AstValueFactory* ast_value_factory) { ...@@ -1738,7 +1731,7 @@ void Scope::AllocateVariablesRecursively(AstValueFactory* ast_value_factory) {
} }
AsDeclarationScope()->AllocateReceiver(); AsDeclarationScope()->AllocateReceiver();
} }
AllocateNonParameterLocalsAndDeclaredGlobals(ast_value_factory); AllocateNonParameterLocalsAndDeclaredGlobals();
// Force allocation of a context for this scope if necessary. For a 'with' // Force allocation of a context for this scope if necessary. For a 'with'
// scope and for a function scope that makes an 'eval' call we need a context, // scope and for a function scope that makes an 'eval' call we need a context,
......
...@@ -604,13 +604,10 @@ class Scope: public ZoneObject { ...@@ -604,13 +604,10 @@ class Scope: public ZoneObject {
// Variable allocation. // Variable allocation.
void AllocateStackSlot(Variable* var); void AllocateStackSlot(Variable* var);
void AllocateHeapSlot(Variable* var); void AllocateHeapSlot(Variable* var);
void AllocateNonParameterLocal(Variable* var, void AllocateNonParameterLocal(Variable* var);
AstValueFactory* ast_value_factory); void AllocateDeclaredGlobal(Variable* var);
void AllocateDeclaredGlobal(Variable* var, void AllocateNonParameterLocalsAndDeclaredGlobals();
AstValueFactory* ast_value_factory); void AllocateVariablesRecursively();
void AllocateNonParameterLocalsAndDeclaredGlobals(
AstValueFactory* ast_value_factory);
void AllocateVariablesRecursively(AstValueFactory* ast_value_factory);
// Construct a scope based on the scope info. // Construct a scope based on the scope info.
Scope(Zone* zone, Scope* inner_scope, ScopeType type, Scope(Zone* zone, Scope* inner_scope, ScopeType type,
...@@ -848,7 +845,7 @@ class DeclarationScope : public Scope { ...@@ -848,7 +845,7 @@ class DeclarationScope : public Scope {
void PrintParameters(); void PrintParameters();
#endif #endif
void AllocateLocals(AstValueFactory* ast_value_factory); void AllocateLocals();
void AllocateParameterLocals(); void AllocateParameterLocals();
void AllocateReceiver(); void AllocateReceiver();
// Set MODULE as VariableLocation for all variables that will live in some // Set MODULE as VariableLocation for all variables that will live in some
......
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