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

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

Issue 2225683004: [modules] Don't force context allocation of variables declared in module scope. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 1484
1485 1485
1486 bool Scope::MustAllocate(Variable* var) { 1486 bool Scope::MustAllocate(Variable* var) {
1487 DCHECK(var->location() != VariableLocation::MODULE); 1487 DCHECK(var->location() != VariableLocation::MODULE);
1488 // Give var a read/write use if there is a chance it might be accessed 1488 // Give var a read/write use if there is a chance it might be accessed
1489 // via an eval() call. This is only possible if the variable has a 1489 // via an eval() call. This is only possible if the variable has a
1490 // visible name. 1490 // visible name.
1491 if ((var->is_this() || !var->raw_name()->IsEmpty()) && 1491 if ((var->is_this() || !var->raw_name()->IsEmpty()) &&
1492 (var->has_forced_context_allocation() || scope_calls_eval_ || 1492 (var->has_forced_context_allocation() || scope_calls_eval_ ||
1493 inner_scope_calls_eval_ || is_catch_scope() || is_block_scope() || 1493 inner_scope_calls_eval_ || is_catch_scope() || is_block_scope() ||
1494 is_module_scope() || is_script_scope())) { 1494 is_script_scope())) {
1495 var->set_is_used(); 1495 var->set_is_used();
1496 if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned(); 1496 if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned();
1497 } 1497 }
1498 // Global variables do not need to be allocated. 1498 // Global variables do not need to be allocated.
1499 return !var->IsGlobalObjectProperty() && var->is_used(); 1499 return !var->IsGlobalObjectProperty() && var->is_used();
1500 } 1500 }
1501 1501
1502 1502
1503 bool Scope::MustAllocateInContext(Variable* var) { 1503 bool Scope::MustAllocateInContext(Variable* var) {
1504 // If var is accessed from an inner scope, or if there is a possibility 1504 // If var is accessed from an inner scope, or if there is a possibility
1505 // that it might be accessed from the current or an inner scope (through 1505 // that it might be accessed from the current or an inner scope (through
1506 // an eval() call or a runtime with lookup), it must be allocated in the 1506 // an eval() call or a runtime with lookup), it must be allocated in the
1507 // context. 1507 // context.
1508 // 1508 //
1509 // Exceptions: If the scope as a whole has forced context allocation, all 1509 // Exceptions: If the scope as a whole has forced context allocation, all
1510 // variables will have context allocation, even temporaries. Otherwise 1510 // variables will have context allocation, even temporaries. Otherwise
1511 // temporary variables are always stack-allocated. Catch-bound variables are 1511 // temporary variables are always stack-allocated. Catch-bound variables are
1512 // always context-allocated. 1512 // always context-allocated.
1513 if (has_forced_context_allocation()) return true; 1513 if (has_forced_context_allocation()) return true;
1514 if (var->mode() == TEMPORARY) return false; 1514 if (var->mode() == TEMPORARY) return false;
1515 if (is_catch_scope() || is_module_scope()) return true; 1515 if (is_catch_scope()) return true;
1516 if (is_script_scope() && IsLexicalVariableMode(var->mode())) return true; 1516 if (is_script_scope() && IsLexicalVariableMode(var->mode())) return true;
1517 return var->has_forced_context_allocation() || scope_calls_eval_ || 1517 return var->has_forced_context_allocation() || scope_calls_eval_ ||
1518 inner_scope_calls_eval_; 1518 inner_scope_calls_eval_;
1519 } 1519 }
1520 1520
1521 1521
1522 void Scope::AllocateStackSlot(Variable* var) { 1522 void Scope::AllocateStackSlot(Variable* var) {
1523 if (is_block_scope()) { 1523 if (is_block_scope()) {
1524 outer_scope()->GetDeclarationScope()->AllocateStackSlot(var); 1524 outer_scope()->GetDeclarationScope()->AllocateStackSlot(var);
1525 } else { 1525 } else {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 function != NULL && function->proxy()->var()->IsContextSlot(); 1782 function != NULL && function->proxy()->var()->IsContextSlot();
1783 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1783 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1784 (is_function_var_in_context ? 1 : 0); 1784 (is_function_var_in_context ? 1 : 0);
1785 } 1785 }
1786 1786
1787 1787
1788 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1788 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1789 1789
1790 } // namespace internal 1790 } // namespace internal
1791 } // namespace v8 1791 } // 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