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

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

Issue 2399833002: Teach Scopes whether they will end up being lazily compiled or not (Closed)
Patch Set: Created 4 years, 2 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
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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 scope_nonlinear_ = false; 296 scope_nonlinear_ = false;
297 is_hidden_ = false; 297 is_hidden_ = false;
298 is_debug_evaluate_scope_ = false; 298 is_debug_evaluate_scope_ = false;
299 299
300 inner_scope_calls_eval_ = false; 300 inner_scope_calls_eval_ = false;
301 force_context_allocation_ = false; 301 force_context_allocation_ = false;
302 302
303 is_declaration_scope_ = false; 303 is_declaration_scope_ = false;
304 304
305 is_lazily_parsed_ = false; 305 is_lazily_parsed_ = false;
306 should_compile_lazily_ = false;
306 } 307 }
307 308
308 bool Scope::HasSimpleParameters() { 309 bool Scope::HasSimpleParameters() {
309 DeclarationScope* scope = GetClosureScope(); 310 DeclarationScope* scope = GetClosureScope();
310 return !scope->is_function_scope() || scope->has_simple_parameters(); 311 return !scope->is_function_scope() || scope->has_simple_parameters();
311 } 312 }
312 313
314 void Scope::SetShouldCompileLazily(bool compile_lazily) {
315 should_compile_lazily_ = compile_lazily;
316 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) {
317 if (inner->is_function_scope()) continue;
318 inner->SetShouldCompileLazily(compile_lazily);
319 }
320 }
321
313 void DeclarationScope::set_asm_module() { 322 void DeclarationScope::set_asm_module() {
314 asm_module_ = true; 323 asm_module_ = true;
315 // Mark any existing inner function scopes as asm function scopes. 324 // Mark any existing inner function scopes as asm function scopes.
316 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) { 325 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) {
317 if (inner->is_function_scope()) { 326 if (inner->is_function_scope()) {
318 inner->AsDeclarationScope()->set_asm_function(); 327 inner->AsDeclarationScope()->set_asm_function();
319 } 328 }
320 } 329 }
321 } 330 }
322 331
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 554 }
546 555
547 // We are compiling one of three cases: 556 // We are compiling one of three cases:
548 // 1) top-level code, 557 // 1) top-level code,
549 // 2) a function/eval/module on the top-level 558 // 2) a function/eval/module on the top-level
550 // 3) a function/eval in a scope that was already resolved. 559 // 3) a function/eval in a scope that was already resolved.
551 DCHECK(scope->scope_type() == SCRIPT_SCOPE || 560 DCHECK(scope->scope_type() == SCRIPT_SCOPE ||
552 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || 561 scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
553 scope->outer_scope()->already_resolved_); 562 scope->outer_scope()->already_resolved_);
554 563
564 // The outer scope is never lazy.
565 scope->SetShouldCompileLazily(false);
566
555 scope->AllocateVariables(info, mode); 567 scope->AllocateVariables(info, mode);
556 568
557 // Ensuring that the outer script scope has a scope info avoids having 569 // Ensuring that the outer script scope has a scope info avoids having
558 // special case for native contexts vs other contexts. 570 // special case for native contexts vs other contexts.
559 if (info->script_scope()->scope_info_.is_null()) { 571 if (info->script_scope()->scope_info_.is_null()) {
560 info->script_scope()->scope_info_ = 572 info->script_scope()->scope_info_ =
561 handle(ScopeInfo::Empty(info->isolate())); 573 handle(ScopeInfo::Empty(info->isolate()));
562 } 574 }
563 575
564 #ifdef DEBUG 576 #ifdef DEBUG
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 Indent(n1, "// strict mode scope\n"); 1431 Indent(n1, "// strict mode scope\n");
1420 } 1432 }
1421 if (IsAsmModule()) Indent(n1, "// scope is an asm module\n"); 1433 if (IsAsmModule()) Indent(n1, "// scope is an asm module\n");
1422 if (IsAsmFunction()) Indent(n1, "// scope is an asm function\n"); 1434 if (IsAsmFunction()) Indent(n1, "// scope is an asm function\n");
1423 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); 1435 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
1424 if (is_declaration_scope() && AsDeclarationScope()->uses_super_property()) { 1436 if (is_declaration_scope() && AsDeclarationScope()->uses_super_property()) {
1425 Indent(n1, "// scope uses 'super' property\n"); 1437 Indent(n1, "// scope uses 'super' property\n");
1426 } 1438 }
1427 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); 1439 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
1428 if (is_lazily_parsed_) Indent(n1, "// lazily parsed\n"); 1440 if (is_lazily_parsed_) Indent(n1, "// lazily parsed\n");
1441 if (should_compile_lazily_) Indent(n1, "// should compile lazily\n");
1429 if (num_stack_slots_ > 0) { 1442 if (num_stack_slots_ > 0) {
1430 Indent(n1, "// "); 1443 Indent(n1, "// ");
1431 PrintF("%d stack slots\n", num_stack_slots_); 1444 PrintF("%d stack slots\n", num_stack_slots_);
1432 } 1445 }
1433 if (num_heap_slots_ > 0) { 1446 if (num_heap_slots_ > 0) {
1434 Indent(n1, "// "); 1447 Indent(n1, "// ");
1435 PrintF("%d heap slots\n", num_heap_slots_); 1448 PrintF("%d heap slots\n", num_heap_slots_);
1436 } 1449 }
1437 1450
1438 // Print locals. 1451 // Print locals.
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 scope_info_ = ScopeInfo::Create(isolate, zone(), this, outer_scope); 1912 scope_info_ = ScopeInfo::Create(isolate, zone(), this, outer_scope);
1900 } 1913 }
1901 1914
1902 // The ScopeInfo chain should mirror the context chain, so we only link to 1915 // The ScopeInfo chain should mirror the context chain, so we only link to
1903 // the next outer scope that needs a context. 1916 // the next outer scope that needs a context.
1904 MaybeHandle<ScopeInfo> next_outer_scope = outer_scope; 1917 MaybeHandle<ScopeInfo> next_outer_scope = outer_scope;
1905 if (NeedsContext()) next_outer_scope = scope_info_; 1918 if (NeedsContext()) next_outer_scope = scope_info_;
1906 1919
1907 // Allocate ScopeInfos for inner scopes. 1920 // Allocate ScopeInfos for inner scopes.
1908 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { 1921 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
1909 scope->AllocateScopeInfosRecursively(isolate, mode, next_outer_scope); 1922 if (should_compile_lazily_) scope->should_compile_lazily_ = true;
1923 scope->AllocateScopeInfosRecursively(
1924 isolate, scope->is_function_scope() ? AnalyzeMode::kRegular : mode,
marja 2016/10/06 11:53:06 Why is dropping to kRegular correct here?
jochen (gone - plz use gerrit) 2016/10/06 15:05:04 because the scope iterator that uses the AnalyzeMo
1925 next_outer_scope);
1910 } 1926 }
1911 } 1927 }
1912 1928
1913 int Scope::StackLocalCount() const { 1929 int Scope::StackLocalCount() const {
1914 Variable* function = 1930 Variable* function =
1915 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1931 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1916 return num_stack_slots() - 1932 return num_stack_slots() -
1917 (function != nullptr && function->IsStackLocal() ? 1 : 0); 1933 (function != nullptr && function->IsStackLocal() ? 1 : 0);
1918 } 1934 }
1919 1935
1920 1936
1921 int Scope::ContextLocalCount() const { 1937 int Scope::ContextLocalCount() const {
1922 if (num_heap_slots() == 0) return 0; 1938 if (num_heap_slots() == 0) return 0;
1923 Variable* function = 1939 Variable* function =
1924 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1940 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1925 bool is_function_var_in_context = 1941 bool is_function_var_in_context =
1926 function != nullptr && function->IsContextSlot(); 1942 function != nullptr && function->IsContextSlot();
1927 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1943 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1928 (is_function_var_in_context ? 1 : 0); 1944 (is_function_var_in_context ? 1 : 0);
1929 } 1945 }
1930 1946
1931 } // namespace internal 1947 } // namespace internal
1932 } // namespace v8 1948 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698