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

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

Issue 2521513004: Preparse inner functions: fix maybe_assigned (Closed)
Patch Set: less pessimistic Created 4 years 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 | « no previous file | 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/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 1606
1607 return var; 1607 return var;
1608 } 1608 }
1609 1609
1610 void Scope::ResolveVariable(ParseInfo* info, VariableProxy* proxy) { 1610 void Scope::ResolveVariable(ParseInfo* info, VariableProxy* proxy) {
1611 DCHECK(info->script_scope()->is_script_scope()); 1611 DCHECK(info->script_scope()->is_script_scope());
1612 DCHECK(!proxy->is_resolved()); 1612 DCHECK(!proxy->is_resolved());
1613 Variable* var = LookupRecursive(proxy, nullptr); 1613 Variable* var = LookupRecursive(proxy, nullptr);
1614 ResolveTo(info, proxy, var); 1614 ResolveTo(info, proxy, var);
1615 1615
1616 if (FLAG_lazy_inner_functions) { 1616 // Pessimistically set is_used and maybe_assigned for variables which lazy
1617 if (info != nullptr && info->is_native()) return; 1617 // parsed inner functions refer to.
1618 // Pessimistically force context allocation for all variables to which inner 1618 if (FLAG_lazy_inner_functions && is_declaration_scope() &&
1619 // scope variables could potentially resolve to. 1619 AsDeclarationScope()->is_lazily_parsed()) {
1620 Scope* scope = GetClosureScope()->outer_scope_; 1620 // Since we don't lazy parse inner arrow functions, inner functions
1621 while (scope != nullptr && scope->scope_info_.is_null()) { 1621 // cannot refer to the outer "this".
1622 var = scope->LookupLocal(proxy->raw_name()); 1622 if (!var->is_dynamic() && !var->is_this()) {
1623 if (var != nullptr) { 1623 var->set_is_used();
1624 // Since we don't lazy parse inner arrow functions, inner functions 1624 var->set_maybe_assigned();
Toon Verwaest 2016/11/22 13:11:42 I don't think we need to set is_used here, since R
1625 // cannot refer to the outer "this".
1626 if (!var->is_dynamic() && !var->is_this() &&
1627 !var->has_forced_context_allocation()) {
1628 var->ForceContextAllocation();
1629 var->set_is_used();
1630 // We don't know what the (potentially lazy parsed) inner function
1631 // does with the variable; pessimistically assume that it's assigned.
1632 var->set_maybe_assigned();
1633 }
1634 }
1635 scope = scope->outer_scope_;
1636 } 1625 }
1637 } 1626 }
1638 } 1627 }
1639 1628
1640 namespace { 1629 namespace {
1641 1630
1642 bool AccessNeedsHoleCheck(Variable* var, VariableProxy* proxy, Scope* scope) { 1631 bool AccessNeedsHoleCheck(Variable* var, VariableProxy* proxy, Scope* scope) {
1643 if (!var->binding_needs_init()) { 1632 if (!var->binding_needs_init()) {
1644 return false; 1633 return false;
1645 } 1634 }
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 Variable* function = 2016 Variable* function =
2028 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 2017 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
2029 bool is_function_var_in_context = 2018 bool is_function_var_in_context =
2030 function != nullptr && function->IsContextSlot(); 2019 function != nullptr && function->IsContextSlot();
2031 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 2020 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
2032 (is_function_var_in_context ? 1 : 0); 2021 (is_function_var_in_context ? 1 : 0);
2033 } 2022 }
2034 2023
2035 } // namespace internal 2024 } // namespace internal
2036 } // namespace v8 2025 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698