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

Side by Side Diff: src/compiler/ast-graph-builder.cc

Issue 2237933002: [turbofan] Re-separate logic for LET and CONST in BuildVariableAssignment (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 | « 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/compiler/ast-graph-builder.h" 5 #include "src/compiler/ast-graph-builder.h"
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/compiler/ast-loop-assignment-analyzer.h" 9 #include "src/compiler/ast-loop-assignment-analyzer.h"
10 #include "src/compiler/control-builders.h" 10 #include "src/compiler/control-builders.h"
(...skipping 3435 matching lines...) Expand 10 before | Expand all | Expand 10 after
3446 if (is_strict(language_mode())) { 3446 if (is_strict(language_mode())) {
3447 return BuildThrowConstAssignError(bailout_id); 3447 return BuildThrowConstAssignError(bailout_id);
3448 } 3448 }
3449 return value; 3449 return value;
3450 } else if (mode == LET && op == Token::INIT) { 3450 } else if (mode == LET && op == Token::INIT) {
3451 // No initialization check needed because scoping guarantees it. Note 3451 // No initialization check needed because scoping guarantees it. Note
3452 // that we still perform a lookup to keep the variable live, because 3452 // that we still perform a lookup to keep the variable live, because
3453 // baseline code might contain debug code that inspects the variable. 3453 // baseline code might contain debug code that inspects the variable.
3454 Node* current = environment()->Lookup(variable); 3454 Node* current = environment()->Lookup(variable);
3455 CHECK_NOT_NULL(current); 3455 CHECK_NOT_NULL(current);
3456 } else if (mode == LET && op != Token::INIT &&
3457 variable->binding_needs_init()) {
3458 // Perform an initialization check for let declared variables.
3459 Node* current = environment()->Lookup(variable);
3460 if (current->op() == the_hole->op()) {
3461 return BuildThrowReferenceError(variable, bailout_id);
3462 } else if (current->opcode() == IrOpcode::kPhi) {
3463 BuildHoleCheckThenThrow(current, variable, value, bailout_id);
3464 }
3456 } else if (mode == CONST && op == Token::INIT) { 3465 } else if (mode == CONST && op == Token::INIT) {
3457 // Perform an initialization check for const {this} variables. 3466 // Perform an initialization check for const {this} variables.
3458 // Note that the {this} variable is the only const variable being able 3467 // Note that the {this} variable is the only const variable being able
3459 // to trigger bind operations outside the TDZ, via {super} calls. 3468 // to trigger bind operations outside the TDZ, via {super} calls.
3460 Node* current = environment()->Lookup(variable); 3469 Node* current = environment()->Lookup(variable);
3461 if (current->op() != the_hole->op() && variable->is_this()) { 3470 if (current->op() != the_hole->op() && variable->is_this()) {
3462 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); 3471 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id);
3463 } 3472 }
3464 } else if (IsLexicalVariableMode(mode) && op != Token::INIT) { 3473 } else if (mode == CONST && op != Token::INIT) {
3465 // Perform an initialization check for lexically declared variables.
3466 Node* current = environment()->Lookup(variable);
3467 if (variable->binding_needs_init()) { 3474 if (variable->binding_needs_init()) {
3475 Node* current = environment()->Lookup(variable);
3468 if (current->op() == the_hole->op()) { 3476 if (current->op() == the_hole->op()) {
3469 return BuildThrowReferenceError(variable, bailout_id); 3477 return BuildThrowReferenceError(variable, bailout_id);
3470 } else if (current->opcode() == IrOpcode::kPhi) { 3478 } else if (current->opcode() == IrOpcode::kPhi) {
3471 BuildHoleCheckThenThrow(current, variable, value, bailout_id); 3479 BuildHoleCheckThenThrow(current, variable, value, bailout_id);
3472 } 3480 }
3473 } 3481 }
3474 if (mode == CONST) { 3482 // Assignment to const is exception in all modes.
3475 return BuildThrowConstAssignError(bailout_id); 3483 return BuildThrowConstAssignError(bailout_id);
3476 }
3477 } 3484 }
3478 environment()->Bind(variable, value); 3485 environment()->Bind(variable, value);
3479 return value; 3486 return value;
3480 case VariableLocation::CONTEXT: { 3487 case VariableLocation::CONTEXT: {
3481 // Context variable (potentially up the context chain). 3488 // Context variable (potentially up the context chain).
3482 int depth = current_scope()->ContextChainLength(variable->scope()); 3489 int depth = current_scope()->ContextChainLength(variable->scope());
3483 if (mode == CONST_LEGACY && op != Token::INIT) { 3490 if (mode == CONST_LEGACY && op != Token::INIT) {
3484 // Non-initializing assignment to legacy const is 3491 // Non-initializing assignment to legacy const is
3485 // - exception in strict mode. 3492 // - exception in strict mode.
3486 // - ignored in sloppy mode. 3493 // - ignored in sloppy mode.
3487 if (is_strict(language_mode())) { 3494 if (is_strict(language_mode())) {
3488 return BuildThrowConstAssignError(bailout_id); 3495 return BuildThrowConstAssignError(bailout_id);
3489 } 3496 }
3490 return value; 3497 return value;
3498 } else if (mode == LET && op != Token::INIT &&
3499 variable->binding_needs_init()) {
3500 // Perform an initialization check for let declared variables.
3501 const Operator* op =
3502 javascript()->LoadContext(depth, variable->index(), false);
3503 Node* current = NewNode(op, current_context());
3504 value = BuildHoleCheckThenThrow(current, variable, value, bailout_id);
3491 } else if (mode == CONST && op == Token::INIT) { 3505 } else if (mode == CONST && op == Token::INIT) {
3492 // Perform an initialization check for const {this} variables. 3506 // Perform an initialization check for const {this} variables.
3493 // Note that the {this} variable is the only const variable being able 3507 // Note that the {this} variable is the only const variable being able
3494 // to trigger bind operations outside the TDZ, via {super} calls. 3508 // to trigger bind operations outside the TDZ, via {super} calls.
3495 if (variable->is_this()) { 3509 if (variable->is_this()) {
3496 const Operator* op = 3510 const Operator* op =
3497 javascript()->LoadContext(depth, variable->index(), false); 3511 javascript()->LoadContext(depth, variable->index(), false);
3498 Node* current = NewNode(op, current_context()); 3512 Node* current = NewNode(op, current_context());
3499 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); 3513 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id);
3500 } 3514 }
3501 } else if (IsLexicalVariableMode(mode) && op != Token::INIT) { 3515 } else if (mode == CONST && op != Token::INIT) {
3502 // Perform an initialization check for lexically declared variables.
3503 if (variable->binding_needs_init()) { 3516 if (variable->binding_needs_init()) {
3504 const Operator* op = 3517 const Operator* op =
3505 javascript()->LoadContext(depth, variable->index(), false); 3518 javascript()->LoadContext(depth, variable->index(), false);
3506 Node* current = NewNode(op, current_context()); 3519 Node* current = NewNode(op, current_context());
3507 value = BuildHoleCheckThenThrow(current, variable, value, bailout_id); 3520 BuildHoleCheckThenThrow(current, variable, value, bailout_id);
3508 } 3521 }
3509 if (mode == CONST) { 3522 // Assignment to const is exception in all modes.
3510 // Assignment to const is exception in all modes. 3523 return BuildThrowConstAssignError(bailout_id);
3511 return BuildThrowConstAssignError(bailout_id);
3512 }
3513 } 3524 }
3514 const Operator* op = javascript()->StoreContext(depth, variable->index()); 3525 const Operator* op = javascript()->StoreContext(depth, variable->index());
3515 return NewNode(op, current_context(), value); 3526 return NewNode(op, current_context(), value);
3516 } 3527 }
3517 case VariableLocation::LOOKUP: { 3528 case VariableLocation::LOOKUP: {
3518 // Dynamic lookup of context variable (anywhere in the chain). 3529 // Dynamic lookup of context variable (anywhere in the chain).
3519 Handle<Name> name = variable->name(); 3530 Handle<Name> name = variable->name();
3520 Node* store = BuildDynamicStore(name, value); 3531 Node* store = BuildDynamicStore(name, value);
3521 PrepareFrameState(store, bailout_id, combine); 3532 PrepareFrameState(store, bailout_id, combine);
3522 return store; 3533 return store;
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
4320 // Phi does not exist yet, introduce one. 4331 // Phi does not exist yet, introduce one.
4321 value = NewPhi(inputs, value, control); 4332 value = NewPhi(inputs, value, control);
4322 value->ReplaceInput(inputs - 1, other); 4333 value->ReplaceInput(inputs - 1, other);
4323 } 4334 }
4324 return value; 4335 return value;
4325 } 4336 }
4326 4337
4327 } // namespace compiler 4338 } // namespace compiler
4328 } // namespace internal 4339 } // namespace internal
4329 } // namespace v8 4340 } // 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