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

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

Issue 2269603002: Always immediately propagate flags outwards rather than relying on PropagateScopeInfo (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments 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 | « no previous file | src/ast/scopes.cc » ('j') | 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 #ifndef V8_AST_SCOPES_H_ 5 #ifndef V8_AST_SCOPES_H_
6 #define V8_AST_SCOPES_H_ 6 #define V8_AST_SCOPES_H_
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/base/hashmap.h" 9 #include "src/base/hashmap.h"
10 #include "src/globals.h" 10 #include "src/globals.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // the given list. This is used to catch patterns like 214 // the given list. This is used to catch patterns like
215 // `try{}catch(e){let e;}`, 215 // `try{}catch(e){let e;}`,
216 // which is an error even though the two 'e's are declared in different 216 // which is an error even though the two 'e's are declared in different
217 // scopes. 217 // scopes.
218 Declaration* CheckLexDeclarationsConflictingWith( 218 Declaration* CheckLexDeclarationsConflictingWith(
219 const ZoneList<const AstRawString*>& names); 219 const ZoneList<const AstRawString*>& names);
220 220
221 // --------------------------------------------------------------------------- 221 // ---------------------------------------------------------------------------
222 // Scope-specific info. 222 // Scope-specific info.
223 223
224 // Inform the scope that the corresponding code contains an eval call. 224 // Inform the scope and outer scopes that the corresponding code contains an
225 void RecordEvalCall() { scope_calls_eval_ = true; } 225 // eval call.
226 void RecordEvalCall() {
227 scope_calls_eval_ = true;
228 for (Scope* scope = this; scope != nullptr; scope = scope->outer_scope()) {
229 scope->inner_scope_calls_eval_ = true;
230 }
231 }
226 232
227 // Inform the scope that the corresponding code uses "super". 233 // Inform the scope that the corresponding code uses "super".
228 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } 234 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; }
229 235
230 // Set the language mode flag (unless disabled by a global flag). 236 // Set the language mode flag (unless disabled by a global flag).
231 void SetLanguageMode(LanguageMode language_mode) { 237 void SetLanguageMode(LanguageMode language_mode) {
232 DCHECK(!is_module_scope() || is_strict(language_mode)); 238 DCHECK(!is_module_scope() || is_strict(language_mode));
233 set_language_mode(language_mode); 239 set_language_mode(language_mode);
234 } 240 }
235 241
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 366
361 // Result of variable allocation. 367 // Result of variable allocation.
362 int num_stack_slots() const { return num_stack_slots_; } 368 int num_stack_slots() const { return num_stack_slots_; }
363 int num_heap_slots() const { return num_heap_slots_; } 369 int num_heap_slots() const { return num_heap_slots_; }
364 int num_global_slots() const { return num_global_slots_; } 370 int num_global_slots() const { return num_global_slots_; }
365 371
366 int StackLocalCount() const; 372 int StackLocalCount() const;
367 int ContextLocalCount() const; 373 int ContextLocalCount() const;
368 int ContextGlobalCount() const; 374 int ContextGlobalCount() const;
369 375
370 // Make sure this scope and all outer scopes are eagerly compiled.
371 void ForceEagerCompilation() { force_eager_compilation_ = true; }
372
373 // Determine if we can parse a function literal in this scope lazily. 376 // Determine if we can parse a function literal in this scope lazily.
374 bool AllowsLazyParsing() const; 377 bool AllowsLazyParsing() const;
375 378
376 // Determine if we can use lazy compilation for this scope.
377 bool AllowsLazyCompilation() const;
378
379 // Determine if we can use lazy compilation for this scope without a context.
380 bool AllowsLazyCompilationWithoutContext() const;
381
382 // The number of contexts between this and scope; zero if this == scope. 379 // The number of contexts between this and scope; zero if this == scope.
383 int ContextChainLength(Scope* scope) const; 380 int ContextChainLength(Scope* scope) const;
384 381
385 // The number of contexts between this and the outermost context that has a 382 // The number of contexts between this and the outermost context that has a
386 // sloppy eval call. One if this->calls_sloppy_eval(). 383 // sloppy eval call. One if this->calls_sloppy_eval().
387 int ContextChainLengthUntilOutermostSloppyEval() const; 384 int ContextChainLengthUntilOutermostSloppyEval() const;
388 385
389 // The maximum number of nested contexts required for this scope and any inner 386 // The maximum number of nested contexts required for this scope and any inner
390 // scopes. 387 // scopes.
391 int MaxNestedContextChainLength(); 388 int MaxNestedContextChainLength();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // The scope type. 491 // The scope type.
495 const ScopeType scope_type_; 492 const ScopeType scope_type_;
496 493
497 // Scope-specific information computed during parsing. 494 // Scope-specific information computed during parsing.
498 // 495 //
499 // The language mode of this scope. 496 // The language mode of this scope.
500 STATIC_ASSERT(LANGUAGE_END == 2); 497 STATIC_ASSERT(LANGUAGE_END == 2);
501 bool is_strict_ : 1; 498 bool is_strict_ : 1;
502 // This scope or a nested catch scope or with scope contain an 'eval' call. At 499 // This scope or a nested catch scope or with scope contain an 'eval' call. At
503 // the 'eval' call site this scope is the declaration scope. 500 // the 'eval' call site this scope is the declaration scope.
504 bool scope_calls_eval_ : 1; 501 bool scope_calls_eval_ : 1;
vogelheim 2016/08/22 16:16:30 Is scope_calls_eval_ still used? If so: Does that
505 // This scope uses "super" property ('super.foo'). 502 // This scope uses "super" property ('super.foo').
506 bool scope_uses_super_property_ : 1; 503 bool scope_uses_super_property_ : 1;
507 // This scope has a parameter called "arguments". 504 // This scope has a parameter called "arguments".
508 bool has_arguments_parameter_ : 1; 505 bool has_arguments_parameter_ : 1;
509 // This scope's declarations might not be executed in order (e.g., switch). 506 // This scope's declarations might not be executed in order (e.g., switch).
510 bool scope_nonlinear_ : 1; 507 bool scope_nonlinear_ : 1;
511 bool is_hidden_ : 1; 508 bool is_hidden_ : 1;
512 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. 509 // Temporary workaround that allows masking of 'this' in debug-evalute scopes.
513 bool is_debug_evaluate_scope_ : 1; 510 bool is_debug_evaluate_scope_ : 1;
514 511
515 // Computed via PropagateScopeInfo.
516 bool inner_scope_calls_eval_ : 1; 512 bool inner_scope_calls_eval_ : 1;
517 bool force_eager_compilation_ : 1;
518 bool force_context_allocation_ : 1; 513 bool force_context_allocation_ : 1;
519 514
520 // True if it holds 'var' declarations. 515 // True if it holds 'var' declarations.
521 bool is_declaration_scope_ : 1; 516 bool is_declaration_scope_ : 1;
522 517
523 // Create a non-local variable with a given name. 518 // Create a non-local variable with a given name.
524 // These variables are looked up dynamically at runtime. 519 // These variables are looked up dynamically at runtime.
525 Variable* NonLocal(const AstRawString* name, VariableMode mode); 520 Variable* NonLocal(const AstRawString* name, VariableMode mode);
526 521
527 // Variable resolution. 522 // Variable resolution.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 } 652 }
658 653
659 FunctionKind function_kind() const { return function_kind_; } 654 FunctionKind function_kind() const { return function_kind_; }
660 655
661 bool is_arrow_scope() const { 656 bool is_arrow_scope() const {
662 return is_function_scope() && IsArrowFunction(function_kind_); 657 return is_function_scope() && IsArrowFunction(function_kind_);
663 } 658 }
664 659
665 bool NeedsHomeObject() const { 660 bool NeedsHomeObject() const {
666 return scope_uses_super_property_ || 661 return scope_uses_super_property_ ||
667 ((scope_calls_eval_ || inner_scope_calls_eval_) && 662 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) ||
668 (IsConciseMethod(function_kind()) || 663 IsAccessorFunction(function_kind()) ||
669 IsAccessorFunction(function_kind()) || 664 IsClassConstructor(function_kind())));
670 IsClassConstructor(function_kind())));
671 } 665 }
672 666
673 bool asm_module() const { return asm_module_; } 667 bool asm_module() const { return asm_module_; }
674 void set_asm_module() { asm_module_ = true; } 668 void set_asm_module() { asm_module_ = true; }
675 bool asm_function() const { return asm_function_; } 669 bool asm_function() const { return asm_function_; }
676 void set_asm_function() { asm_module_ = true; } 670 void set_asm_function() { asm_module_ = true; }
677 671
678 void DeclareThis(AstValueFactory* ast_value_factory); 672 void DeclareThis(AstValueFactory* ast_value_factory);
679 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); 673 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory);
680 674
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 // discard the Scope for lazily compiled functions. In particular, this 821 // discard the Scope for lazily compiled functions. In particular, this
828 // records variables which cannot be resolved inside the Scope (we don't yet 822 // records variables which cannot be resolved inside the Scope (we don't yet
829 // know what they will resolve to since the outer Scopes are incomplete) and 823 // know what they will resolve to since the outer Scopes are incomplete) and
830 // migrates them into migrate_to. 824 // migrates them into migrate_to.
831 void AnalyzePartially(DeclarationScope* migrate_to, 825 void AnalyzePartially(DeclarationScope* migrate_to,
832 AstNodeFactory* ast_node_factory); 826 AstNodeFactory* ast_node_factory);
833 827
834 Handle<StringSet> CollectNonLocals(ParseInfo* info, 828 Handle<StringSet> CollectNonLocals(ParseInfo* info,
835 Handle<StringSet> non_locals); 829 Handle<StringSet> non_locals);
836 830
831 // Determine if we can use lazy compilation for this scope.
832 bool AllowsLazyCompilation() const;
833
834 // Determine if we can use lazy compilation for this scope without a context.
835 bool AllowsLazyCompilationWithoutContext() const;
836
837 // Make sure this closure and all outer closures are eagerly compiled.
838 void ForceEagerCompilation() {
839 DCHECK_EQ(this, GetClosureScope());
840 for (DeclarationScope* s = this; !s->is_script_scope();
841 s = s->outer_scope()->GetClosureScope()) {
842 s->force_eager_compilation_ = true;
843 }
844 }
845
837 #ifdef DEBUG 846 #ifdef DEBUG
838 void PrintParameters(); 847 void PrintParameters();
839 #endif 848 #endif
840 849
841 void AllocateLocals(); 850 void AllocateLocals();
842 void AllocateParameterLocals(); 851 void AllocateParameterLocals();
843 void AllocateReceiver(); 852 void AllocateReceiver();
844 853
845 private: 854 private:
846 void AllocateParameter(Variable* var, int index); 855 void AllocateParameter(Variable* var, int index);
847 856
848 void SetDefaults(); 857 void SetDefaults();
849 858
850 // If the scope is a function scope, this is the function kind. 859 // If the scope is a function scope, this is the function kind.
851 const FunctionKind function_kind_; 860 const FunctionKind function_kind_;
852 861
853 bool has_simple_parameters_ : 1; 862 bool has_simple_parameters_ : 1;
854 // This scope contains an "use asm" annotation. 863 // This scope contains an "use asm" annotation.
855 bool asm_module_ : 1; 864 bool asm_module_ : 1;
856 // This scope's outer context is an asm module. 865 // This scope's outer context is an asm module.
857 bool asm_function_ : 1; 866 bool asm_function_ : 1;
867 bool force_eager_compilation_ : 1;
858 868
859 // Info about the parameter list of a function. 869 // Info about the parameter list of a function.
860 int arity_; 870 int arity_;
861 int rest_index_; 871 int rest_index_;
862 Variable* rest_parameter_; 872 Variable* rest_parameter_;
863 // Compiler-allocated (user-invisible) temporaries. 873 // Compiler-allocated (user-invisible) temporaries.
864 ZoneList<Variable*> temps_; 874 ZoneList<Variable*> temps_;
865 // Parameter list in source order. 875 // Parameter list in source order.
866 ZoneList<Variable*> params_; 876 ZoneList<Variable*> params_;
867 // Map of function names to lists of functions defined in sloppy blocks 877 // Map of function names to lists of functions defined in sloppy blocks
(...skipping 25 matching lines...) Expand all
893 void AllocateModuleVariables(); 903 void AllocateModuleVariables();
894 904
895 private: 905 private:
896 ModuleDescriptor* module_descriptor_; 906 ModuleDescriptor* module_descriptor_;
897 }; 907 };
898 908
899 } // namespace internal 909 } // namespace internal
900 } // namespace v8 910 } // namespace v8
901 911
902 #endif // V8_AST_SCOPES_H_ 912 #endif // V8_AST_SCOPES_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698