OLD | NEW |
---|---|
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 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1076 expr->Accept(this); | 1076 expr->Accept(this); |
1077 } else { | 1077 } else { |
1078 ast_context()->ProduceValue(jsgraph()->UndefinedConstant()); | 1078 ast_context()->ProduceValue(jsgraph()->UndefinedConstant()); |
1079 } | 1079 } |
1080 } | 1080 } |
1081 | 1081 |
1082 | 1082 |
1083 void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { | 1083 void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { |
1084 Variable* variable = decl->proxy()->var(); | 1084 Variable* variable = decl->proxy()->var(); |
1085 VariableMode mode = decl->mode(); | 1085 VariableMode mode = decl->mode(); |
1086 bool hole_init = mode == CONST || mode == CONST_LEGACY || mode == LET; | 1086 bool hole_init = mode == CONST || mode == LET; |
1087 switch (variable->location()) { | 1087 switch (variable->location()) { |
1088 case VariableLocation::GLOBAL: | 1088 case VariableLocation::GLOBAL: |
1089 case VariableLocation::UNALLOCATED: { | 1089 case VariableLocation::UNALLOCATED: { |
1090 Handle<Oddball> value = variable->binding_needs_init() | 1090 Handle<Oddball> value = variable->binding_needs_init() |
1091 ? isolate()->factory()->the_hole_value() | 1091 ? isolate()->factory()->the_hole_value() |
1092 : isolate()->factory()->undefined_value(); | 1092 : isolate()->factory()->undefined_value(); |
1093 globals()->push_back(variable->name()); | 1093 globals()->push_back(variable->name()); |
1094 globals()->push_back(value); | 1094 globals()->push_back(value); |
1095 break; | 1095 break; |
1096 } | 1096 } |
(...skipping 2272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3369 Handle<Name> name = variable->name(); | 3369 Handle<Name> name = variable->name(); |
3370 if (Node* node = TryLoadGlobalConstant(name)) return node; | 3370 if (Node* node = TryLoadGlobalConstant(name)) return node; |
3371 Node* value = BuildGlobalLoad(name, feedback, typeof_mode); | 3371 Node* value = BuildGlobalLoad(name, feedback, typeof_mode); |
3372 states.AddToNode(value, bailout_id, combine); | 3372 states.AddToNode(value, bailout_id, combine); |
3373 return value; | 3373 return value; |
3374 } | 3374 } |
3375 case VariableLocation::PARAMETER: | 3375 case VariableLocation::PARAMETER: |
3376 case VariableLocation::LOCAL: { | 3376 case VariableLocation::LOCAL: { |
3377 // Local var, const, or let variable. | 3377 // Local var, const, or let variable. |
3378 Node* value = environment()->Lookup(variable); | 3378 Node* value = environment()->Lookup(variable); |
3379 if (mode == CONST_LEGACY) { | 3379 if (mode == LET || mode == CONST) { |
3380 // Perform check for uninitialized legacy const variables. | |
3381 if (value->op() == the_hole->op()) { | |
3382 value = jsgraph()->UndefinedConstant(); | |
3383 } else if (value->opcode() == IrOpcode::kPhi) { | |
3384 Node* undefined = jsgraph()->UndefinedConstant(); | |
3385 value = BuildHoleCheckSilent(value, undefined, value); | |
Michael Starzinger
2016/04/18 22:49:16
There should be no more call-sites of BuildHoleChe
adamk
2016/04/18 23:15:34
Done. Also removed a few analogous bits from hydro
| |
3386 } | |
3387 } else if (mode == LET || mode == CONST) { | |
3388 // Perform check for uninitialized let/const variables. | 3380 // Perform check for uninitialized let/const variables. |
3389 if (value->op() == the_hole->op()) { | 3381 if (value->op() == the_hole->op()) { |
3390 value = BuildThrowReferenceError(variable, bailout_id); | 3382 value = BuildThrowReferenceError(variable, bailout_id); |
3391 } else if (value->opcode() == IrOpcode::kPhi) { | 3383 } else if (value->opcode() == IrOpcode::kPhi) { |
3392 value = BuildHoleCheckThenThrow(value, variable, value, bailout_id); | 3384 value = BuildHoleCheckThenThrow(value, variable, value, bailout_id); |
3393 } | 3385 } |
3394 } | 3386 } |
3395 return value; | 3387 return value; |
3396 } | 3388 } |
3397 case VariableLocation::CONTEXT: { | 3389 case VariableLocation::CONTEXT: { |
3398 // Context variable (potentially up the context chain). | 3390 // Context variable (potentially up the context chain). |
3399 int depth = current_scope()->ContextChainLength(variable->scope()); | 3391 int depth = current_scope()->ContextChainLength(variable->scope()); |
3400 bool immutable = variable->maybe_assigned() == kNotAssigned; | 3392 bool immutable = variable->maybe_assigned() == kNotAssigned; |
3401 const Operator* op = | 3393 const Operator* op = |
3402 javascript()->LoadContext(depth, variable->index(), immutable); | 3394 javascript()->LoadContext(depth, variable->index(), immutable); |
3403 Node* value = NewNode(op, current_context()); | 3395 Node* value = NewNode(op, current_context()); |
3404 // TODO(titzer): initialization checks are redundant for already | 3396 // TODO(titzer): initialization checks are redundant for already |
3405 // initialized immutable context loads, but only specialization knows. | 3397 // initialized immutable context loads, but only specialization knows. |
3406 // Maybe specializer should be a parameter to the graph builder? | 3398 // Maybe specializer should be a parameter to the graph builder? |
3407 if (mode == CONST_LEGACY) { | 3399 if (mode == LET || mode == CONST) { |
3408 // Perform check for uninitialized legacy const variables. | |
3409 Node* undefined = jsgraph()->UndefinedConstant(); | |
3410 value = BuildHoleCheckSilent(value, undefined, value); | |
3411 } else if (mode == LET || mode == CONST) { | |
3412 // Perform check for uninitialized let/const variables. | 3400 // Perform check for uninitialized let/const variables. |
3413 value = BuildHoleCheckThenThrow(value, variable, value, bailout_id); | 3401 value = BuildHoleCheckThenThrow(value, variable, value, bailout_id); |
3414 } | 3402 } |
3415 return value; | 3403 return value; |
3416 } | 3404 } |
3417 case VariableLocation::LOOKUP: { | 3405 case VariableLocation::LOOKUP: { |
3418 // Dynamic lookup of context variable (anywhere in the chain). | 3406 // Dynamic lookup of context variable (anywhere in the chain). |
3419 Handle<String> name = variable->name(); | 3407 Handle<String> name = variable->name(); |
3420 if (Node* node = | 3408 if (Node* node = |
3421 TryLoadDynamicVariable(variable, name, bailout_id, states, | 3409 TryLoadDynamicVariable(variable, name, bailout_id, states, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3478 case VariableLocation::UNALLOCATED: { | 3466 case VariableLocation::UNALLOCATED: { |
3479 // Global var, const, or let variable. | 3467 // Global var, const, or let variable. |
3480 Handle<Name> name = variable->name(); | 3468 Handle<Name> name = variable->name(); |
3481 Node* store = BuildGlobalStore(name, value, feedback); | 3469 Node* store = BuildGlobalStore(name, value, feedback); |
3482 states.AddToNode(store, bailout_id, combine); | 3470 states.AddToNode(store, bailout_id, combine); |
3483 return store; | 3471 return store; |
3484 } | 3472 } |
3485 case VariableLocation::PARAMETER: | 3473 case VariableLocation::PARAMETER: |
3486 case VariableLocation::LOCAL: | 3474 case VariableLocation::LOCAL: |
3487 // Local var, const, or let variable. | 3475 // Local var, const, or let variable. |
3488 if (mode == CONST_LEGACY && op == Token::INIT) { | 3476 if (mode == CONST_LEGACY && op != Token::INIT) { |
3489 // Perform an initialization check for legacy const variables. | |
3490 Node* current = environment()->Lookup(variable); | |
3491 if (current->op() != the_hole->op()) { | |
3492 value = BuildHoleCheckSilent(current, value, current); | |
3493 } | |
3494 } else if (mode == CONST_LEGACY && op != Token::INIT) { | |
3495 // Non-initializing assignment to legacy const is | 3477 // Non-initializing assignment to legacy const is |
3496 // - exception in strict mode. | 3478 // - exception in strict mode. |
3497 // - ignored in sloppy mode. | 3479 // - ignored in sloppy mode. |
3498 if (is_strict(language_mode())) { | 3480 if (is_strict(language_mode())) { |
3499 return BuildThrowConstAssignError(bailout_id); | 3481 return BuildThrowConstAssignError(bailout_id); |
3500 } | 3482 } |
3501 return value; | 3483 return value; |
3502 } else if (mode == LET && op == Token::INIT) { | 3484 } else if (mode == LET && op == Token::INIT) { |
3503 // No initialization check needed because scoping guarantees it. Note | 3485 // No initialization check needed because scoping guarantees it. Note |
3504 // that we still perform a lookup to keep the variable live, because | 3486 // that we still perform a lookup to keep the variable live, because |
(...skipping 24 matching lines...) Expand all Loading... | |
3529 } else if (current->opcode() == IrOpcode::kPhi) { | 3511 } else if (current->opcode() == IrOpcode::kPhi) { |
3530 BuildHoleCheckThenThrow(current, variable, value, bailout_id); | 3512 BuildHoleCheckThenThrow(current, variable, value, bailout_id); |
3531 } | 3513 } |
3532 return BuildThrowConstAssignError(bailout_id); | 3514 return BuildThrowConstAssignError(bailout_id); |
3533 } | 3515 } |
3534 environment()->Bind(variable, value); | 3516 environment()->Bind(variable, value); |
3535 return value; | 3517 return value; |
3536 case VariableLocation::CONTEXT: { | 3518 case VariableLocation::CONTEXT: { |
3537 // Context variable (potentially up the context chain). | 3519 // Context variable (potentially up the context chain). |
3538 int depth = current_scope()->ContextChainLength(variable->scope()); | 3520 int depth = current_scope()->ContextChainLength(variable->scope()); |
3539 if (mode == CONST_LEGACY && op == Token::INIT) { | 3521 if (mode == CONST_LEGACY && op != Token::INIT) { |
3540 // Perform an initialization check for legacy const variables. | |
3541 const Operator* op = | |
3542 javascript()->LoadContext(depth, variable->index(), false); | |
3543 Node* current = NewNode(op, current_context()); | |
3544 value = BuildHoleCheckSilent(current, value, current); | |
3545 } else if (mode == CONST_LEGACY && op != Token::INIT) { | |
3546 // Non-initializing assignment to legacy const is | 3522 // Non-initializing assignment to legacy const is |
3547 // - exception in strict mode. | 3523 // - exception in strict mode. |
3548 // - ignored in sloppy mode. | 3524 // - ignored in sloppy mode. |
3549 if (is_strict(language_mode())) { | 3525 if (is_strict(language_mode())) { |
3550 return BuildThrowConstAssignError(bailout_id); | 3526 return BuildThrowConstAssignError(bailout_id); |
3551 } | 3527 } |
3552 return value; | 3528 return value; |
3553 } else if (mode == LET && op != Token::INIT) { | 3529 } else if (mode == LET && op != Token::INIT) { |
3554 // Perform an initialization check for let declared variables. | 3530 // Perform an initialization check for let declared variables. |
3555 const Operator* op = | 3531 const Operator* op = |
(...skipping 17 matching lines...) Expand all Loading... | |
3573 Node* current = NewNode(op, current_context()); | 3549 Node* current = NewNode(op, current_context()); |
3574 BuildHoleCheckThenThrow(current, variable, value, bailout_id); | 3550 BuildHoleCheckThenThrow(current, variable, value, bailout_id); |
3575 return BuildThrowConstAssignError(bailout_id); | 3551 return BuildThrowConstAssignError(bailout_id); |
3576 } | 3552 } |
3577 const Operator* op = javascript()->StoreContext(depth, variable->index()); | 3553 const Operator* op = javascript()->StoreContext(depth, variable->index()); |
3578 return NewNode(op, current_context(), value); | 3554 return NewNode(op, current_context(), value); |
3579 } | 3555 } |
3580 case VariableLocation::LOOKUP: { | 3556 case VariableLocation::LOOKUP: { |
3581 // Dynamic lookup of context variable (anywhere in the chain). | 3557 // Dynamic lookup of context variable (anywhere in the chain). |
3582 Handle<Name> name = variable->name(); | 3558 Handle<Name> name = variable->name(); |
3583 // TODO(mstarzinger): Use Runtime::kInitializeLegacyConstLookupSlot for | |
3584 // initializations of const declarations. | |
3585 Node* store = BuildDynamicStore(name, value); | 3559 Node* store = BuildDynamicStore(name, value); |
3586 PrepareFrameState(store, bailout_id, combine); | 3560 PrepareFrameState(store, bailout_id, combine); |
3587 return store; | 3561 return store; |
3588 } | 3562 } |
3589 } | 3563 } |
3590 UNREACHABLE(); | 3564 UNREACHABLE(); |
3591 return nullptr; | 3565 return nullptr; |
3592 } | 3566 } |
3593 | 3567 |
3594 | 3568 |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4371 // Phi does not exist yet, introduce one. | 4345 // Phi does not exist yet, introduce one. |
4372 value = NewPhi(inputs, value, control); | 4346 value = NewPhi(inputs, value, control); |
4373 value->ReplaceInput(inputs - 1, other); | 4347 value->ReplaceInput(inputs - 1, other); |
4374 } | 4348 } |
4375 return value; | 4349 return value; |
4376 } | 4350 } |
4377 | 4351 |
4378 } // namespace compiler | 4352 } // namespace compiler |
4379 } // namespace internal | 4353 } // namespace internal |
4380 } // namespace v8 | 4354 } // namespace v8 |
OLD | NEW |