Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: src/ast/scopes.cc

Issue 2275573002: Remove rest_parameter_ cache on DeclarationScope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Could be we shouldn't allocate Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 asm_module_ = false; 198 asm_module_ = false;
199 asm_function_ = false; 199 asm_function_ = false;
200 force_eager_compilation_ = false; 200 force_eager_compilation_ = false;
201 has_arguments_parameter_ = false; 201 has_arguments_parameter_ = false;
202 receiver_ = nullptr; 202 receiver_ = nullptr;
203 new_target_ = nullptr; 203 new_target_ = nullptr;
204 function_ = nullptr; 204 function_ = nullptr;
205 arguments_ = nullptr; 205 arguments_ = nullptr;
206 this_function_ = nullptr; 206 this_function_ = nullptr;
207 arity_ = 0; 207 arity_ = 0;
208 rest_parameter_ = nullptr;
209 rest_index_ = -1; 208 rest_index_ = -1;
210 } 209 }
211 210
212 void Scope::SetDefaults() { 211 void Scope::SetDefaults() {
213 #ifdef DEBUG 212 #ifdef DEBUG
214 scope_name_ = nullptr; 213 scope_name_ = nullptr;
215 already_resolved_ = false; 214 already_resolved_ = false;
216 #endif 215 #endif
217 inner_scope_ = nullptr; 216 inner_scope_ = nullptr;
218 sibling_ = nullptr; 217 sibling_ = nullptr;
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 var = NewTemporary(name); 687 var = NewTemporary(name);
689 } else { 688 } else {
690 var = Declare(zone(), this, name, mode, Variable::NORMAL, 689 var = Declare(zone(), this, name, mode, Variable::NORMAL,
691 kCreatedInitialized); 690 kCreatedInitialized);
692 // TODO(wingo): Avoid O(n^2) check. 691 // TODO(wingo): Avoid O(n^2) check.
693 *is_duplicate = IsDeclaredParameter(name); 692 *is_duplicate = IsDeclaredParameter(name);
694 } 693 }
695 if (!is_optional && !is_rest && arity_ == params_.length()) { 694 if (!is_optional && !is_rest && arity_ == params_.length()) {
696 ++arity_; 695 ++arity_;
697 } 696 }
698 if (is_rest) { 697 if (is_rest) rest_index_ = num_parameters();
699 DCHECK_NULL(rest_parameter_);
700 rest_parameter_ = var;
701 rest_index_ = num_parameters();
702 }
703 params_.Add(var, zone()); 698 params_.Add(var, zone());
704 if (name == ast_value_factory->arguments_string()) { 699 if (name == ast_value_factory->arguments_string()) {
705 has_arguments_parameter_ = true; 700 has_arguments_parameter_ = true;
706 } 701 }
707 return var; 702 return var;
708 } 703 }
709 704
710 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, 705 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode,
711 InitializationFlag init_flag, Variable::Kind kind, 706 InitializationFlag init_flag, Variable::Kind kind,
712 MaybeAssignedFlag maybe_assigned_flag) { 707 MaybeAssignedFlag maybe_assigned_flag) {
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 } else { 1532 } else {
1538 // 'arguments' is unused. Tell the code generator that it does not need to 1533 // 'arguments' is unused. Tell the code generator that it does not need to
1539 // allocate the arguments object by nulling out arguments_. 1534 // allocate the arguments object by nulling out arguments_.
1540 arguments_ = nullptr; 1535 arguments_ = nullptr;
1541 } 1536 }
1542 1537
1543 } else { 1538 } else {
1544 DCHECK(is_arrow_scope()); 1539 DCHECK(is_arrow_scope());
1545 } 1540 }
1546 1541
1547 if (rest_parameter_ && !MustAllocate(rest_parameter_)) {
1548 rest_parameter_ = nullptr;
1549 }
1550
1551 // The same parameter may occur multiple times in the parameters_ list. 1542 // The same parameter may occur multiple times in the parameters_ list.
1552 // If it does, and if it is not copied into the context object, it must 1543 // If it does, and if it is not copied into the context object, it must
1553 // receive the highest parameter index for that parameter; thus iteration 1544 // receive the highest parameter index for that parameter; thus iteration
1554 // order is relevant! 1545 // order is relevant!
1555 for (int i = params_.length() - 1; i >= 0; --i) { 1546 for (int i = params_.length() - 1; i >= 0; --i) {
1547 if (i == rest_index_) continue;
1556 Variable* var = params_[i]; 1548 Variable* var = params_[i];
1557 if (var == rest_parameter_) continue;
1558 1549
1559 DCHECK(var->scope() == this); 1550 DCHECK(var->scope() == this);
1560 if (uses_sloppy_arguments) { 1551 if (uses_sloppy_arguments) {
1561 var->ForceContextAllocation(); 1552 var->ForceContextAllocation();
1562 } 1553 }
1563 AllocateParameter(var, i); 1554 AllocateParameter(var, i);
1564 } 1555 }
1565 } 1556 }
1566 1557
1567 void DeclarationScope::AllocateParameter(Variable* var, int index) { 1558 void DeclarationScope::AllocateParameter(Variable* var, int index) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 1632
1642 void DeclarationScope::AllocateLocals() { 1633 void DeclarationScope::AllocateLocals() {
1643 // For now, function_ must be allocated at the very end. If it gets 1634 // For now, function_ must be allocated at the very end. If it gets
1644 // allocated in the context, it must be the last slot in the context, 1635 // allocated in the context, it must be the last slot in the context,
1645 // because of the current ScopeInfo implementation (see 1636 // because of the current ScopeInfo implementation (see
1646 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). 1637 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
1647 if (function_ != nullptr) { 1638 if (function_ != nullptr) {
1648 AllocateNonParameterLocal(function_); 1639 AllocateNonParameterLocal(function_);
1649 } 1640 }
1650 1641
1651 DCHECK(rest_parameter_ == nullptr || !rest_parameter_->IsUnallocated()); 1642 DCHECK(!has_rest_parameter() || !MustAllocate(params_[rest_index_]) ||
1643 !params_[rest_index_]->IsUnallocated());
1652 1644
1653 if (new_target_ != nullptr && !MustAllocate(new_target_)) { 1645 if (new_target_ != nullptr && !MustAllocate(new_target_)) {
1654 new_target_ = nullptr; 1646 new_target_ = nullptr;
1655 } 1647 }
1656 1648
1657 if (this_function_ != nullptr && !MustAllocate(this_function_)) { 1649 if (this_function_ != nullptr && !MustAllocate(this_function_)) {
1658 this_function_ = nullptr; 1650 this_function_ = nullptr;
1659 } 1651 }
1660 } 1652 }
1661 1653
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 function != nullptr && function->IsContextSlot(); 1726 function != nullptr && function->IsContextSlot();
1735 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1727 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1736 (is_function_var_in_context ? 1 : 0); 1728 (is_function_var_in_context ? 1 : 0);
1737 } 1729 }
1738 1730
1739 1731
1740 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1732 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1741 1733
1742 } // namespace internal 1734 } // namespace internal
1743 } // namespace v8 1735 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698