Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
| (...skipping 2606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2617 // })(); | 2617 // })(); |
| 2618 | 2618 |
| 2619 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume | 2619 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume |
| 2620 // parenthesis before the function means that it will be called | 2620 // parenthesis before the function means that it will be called |
| 2621 // immediately). bar can be parsed lazily, but we need to parse it in a mode | 2621 // immediately). bar can be parsed lazily, but we need to parse it in a mode |
| 2622 // that tracks unresolved variables. | 2622 // that tracks unresolved variables. |
| 2623 DCHECK_IMPLIES(mode() == PARSE_LAZILY, FLAG_lazy); | 2623 DCHECK_IMPLIES(mode() == PARSE_LAZILY, FLAG_lazy); |
| 2624 DCHECK_IMPLIES(mode() == PARSE_LAZILY, allow_lazy()); | 2624 DCHECK_IMPLIES(mode() == PARSE_LAZILY, allow_lazy()); |
| 2625 DCHECK_IMPLIES(mode() == PARSE_LAZILY, extension_ == nullptr); | 2625 DCHECK_IMPLIES(mode() == PARSE_LAZILY, extension_ == nullptr); |
| 2626 | 2626 |
| 2627 bool can_preparse = mode() == PARSE_LAZILY && | |
| 2628 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; | |
| 2629 | |
| 2627 bool is_lazy_top_level_function = | 2630 bool is_lazy_top_level_function = |
| 2628 mode() == PARSE_LAZILY && | 2631 can_preparse && scope()->AllowsLazyParsingWithoutUnresolvedVariables(); |
| 2629 eager_compile_hint == FunctionLiteral::kShouldLazyCompile && | |
| 2630 scope()->AllowsLazyParsingWithoutUnresolvedVariables(); | |
| 2631 | 2632 |
| 2632 // Determine whether we can still lazy parse the inner function. | 2633 // Determine whether we can still lazy parse the inner function. |
| 2633 // The preconditions are: | 2634 // The preconditions are: |
| 2634 // - Lazy compilation has to be enabled. | 2635 // - Lazy compilation has to be enabled. |
| 2635 // - Neither V8 natives nor native function declarations can be allowed, | 2636 // - Neither V8 natives nor native function declarations can be allowed, |
| 2636 // since parsing one would retroactively force the function to be | 2637 // since parsing one would retroactively force the function to be |
| 2637 // eagerly compiled. | 2638 // eagerly compiled. |
| 2638 // - The invoker of this parser can't depend on the AST being eagerly | 2639 // - The invoker of this parser can't depend on the AST being eagerly |
| 2639 // built (either because the function is about to be compiled, or | 2640 // built (either because the function is about to be compiled, or |
| 2640 // because the AST is going to be inspected for some reason). | 2641 // because the AST is going to be inspected for some reason). |
| 2641 // - Because of the above, we can't be attempting to parse a | 2642 // - Because of the above, we can't be attempting to parse a |
| 2642 // FunctionExpression; even without enclosing parentheses it might be | 2643 // FunctionExpression; even without enclosing parentheses it might be |
| 2643 // immediately invoked. | 2644 // immediately invoked. |
| 2644 // - The function literal shouldn't be hinted to eagerly compile. | 2645 // - The function literal shouldn't be hinted to eagerly compile. |
| 2645 // - For asm.js functions the body needs to be available when module | 2646 // - For asm.js functions the body needs to be available when module |
| 2646 // validation is active, because we examine the entire module at once. | 2647 // validation is active, because we examine the entire module at once. |
| 2647 | 2648 |
| 2648 // Inner functions will be parsed using a temporary Zone. After parsing, we | 2649 // Inner functions will be parsed using a temporary Zone. After parsing, we |
| 2649 // will migrate unresolved variable into a Scope in the main Zone. | 2650 // will migrate unresolved variable into a Scope in the main Zone. |
| 2650 // TODO(marja): Refactor parsing modes: simplify this. | 2651 // TODO(marja): Refactor parsing modes: simplify this. |
| 2651 bool use_temp_zone = | 2652 bool use_temp_zone = |
| 2652 allow_lazy() && function_type == FunctionLiteral::kDeclaration && | 2653 (FLAG_lazy_inner_functions |
|
marja
2016/10/11 07:56:47
You're dropping the function_type == FunctionLiter
Toon Verwaest
2016/10/11 10:44:00
I don't see the reason why FunctionLiteral::kDecla
| |
| 2653 eager_compile_hint != FunctionLiteral::kShouldEagerCompile && | 2654 ? can_preparse |
| 2655 : (allow_lazy() && | |
| 2656 eager_compile_hint == FunctionLiteral::kShouldLazyCompile)) && | |
| 2654 !(FLAG_validate_asm && scope()->IsAsmModule()); | 2657 !(FLAG_validate_asm && scope()->IsAsmModule()); |
| 2655 bool is_lazy_inner_function = | 2658 bool is_lazy_inner_function = |
| 2656 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; | 2659 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; |
| 2657 | 2660 |
| 2658 // This Scope lives in the main zone. We'll migrate data into that zone later. | 2661 // This Scope lives in the main zone. We'll migrate data into that zone later. |
| 2659 DeclarationScope* scope = NewFunctionScope(kind); | 2662 DeclarationScope* scope = NewFunctionScope(kind); |
| 2660 SetLanguageMode(scope, language_mode); | 2663 SetLanguageMode(scope, language_mode); |
| 2661 | 2664 |
| 2662 ZoneList<Statement*>* body = nullptr; | 2665 ZoneList<Statement*>* body = nullptr; |
| 2663 int arity = -1; | 2666 int arity = -1; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3143 // caused by calling the .throw method on a generator suspended at the | 3146 // caused by calling the .throw method on a generator suspended at the |
| 3144 // initial yield (i.e. right after generator instantiation). | 3147 // initial yield (i.e. right after generator instantiation). |
| 3145 return factory()->NewYield(get_proxy, assignment, scope()->start_position(), | 3148 return factory()->NewYield(get_proxy, assignment, scope()->start_position(), |
| 3146 Yield::kOnExceptionThrow); | 3149 Yield::kOnExceptionThrow); |
| 3147 } | 3150 } |
| 3148 | 3151 |
| 3149 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 3152 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
| 3150 const AstRawString* function_name, int pos, | 3153 const AstRawString* function_name, int pos, |
| 3151 const ParserFormalParameters& parameters, FunctionKind kind, | 3154 const ParserFormalParameters& parameters, FunctionKind kind, |
| 3152 FunctionLiteral::FunctionType function_type, bool* ok) { | 3155 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 3153 // Everything inside an eagerly parsed function will be parsed eagerly (see | 3156 ParsingModeScope mode(this, allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY); |
| 3154 // comment above). Lazy inner functions are handled separately and they won't | |
| 3155 // require the mode to be PARSE_LAZILY (see ParseFunctionLiteral). | |
| 3156 // TODO(marja): Refactor parsing modes: remove this. | |
| 3157 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | |
| 3158 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); | 3157 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); |
| 3159 | 3158 |
| 3160 static const int kFunctionNameAssignmentIndex = 0; | 3159 static const int kFunctionNameAssignmentIndex = 0; |
| 3161 if (function_type == FunctionLiteral::kNamedExpression) { | 3160 if (function_type == FunctionLiteral::kNamedExpression) { |
| 3162 DCHECK(function_name != NULL); | 3161 DCHECK(function_name != NULL); |
| 3163 // If we have a named function expression, we add a local variable | 3162 // If we have a named function expression, we add a local variable |
| 3164 // declaration to the body of the function with the name of the | 3163 // declaration to the body of the function with the name of the |
| 3165 // function and let it refer to the function itself (closure). | 3164 // function and let it refer to the function itself (closure). |
| 3166 // Not having parsed the function body, the language mode may still change, | 3165 // Not having parsed the function body, the language mode may still change, |
| 3167 // so we reserve a spot and create the actual const assignment later. | 3166 // so we reserve a spot and create the actual const assignment later. |
| (...skipping 2294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5462 | 5461 |
| 5463 return final_loop; | 5462 return final_loop; |
| 5464 } | 5463 } |
| 5465 | 5464 |
| 5466 #undef CHECK_OK | 5465 #undef CHECK_OK |
| 5467 #undef CHECK_OK_VOID | 5466 #undef CHECK_OK_VOID |
| 5468 #undef CHECK_FAILED | 5467 #undef CHECK_FAILED |
| 5469 | 5468 |
| 5470 } // namespace internal | 5469 } // namespace internal |
| 5471 } // namespace v8 | 5470 } // namespace v8 |
| OLD | NEW |