OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3278 if (value == graph()->GetConstantHole()) { | 3278 if (value == graph()->GetConstantHole()) { |
3279 ASSERT(variable->mode() == CONST || | 3279 ASSERT(variable->mode() == CONST || |
3280 variable->mode() == CONST_HARMONY || | 3280 variable->mode() == CONST_HARMONY || |
3281 variable->mode() == LET); | 3281 variable->mode() == LET); |
3282 return Bailout("reference to uninitialized variable"); | 3282 return Bailout("reference to uninitialized variable"); |
3283 } | 3283 } |
3284 return ast_context()->ReturnValue(value); | 3284 return ast_context()->ReturnValue(value); |
3285 } | 3285 } |
3286 | 3286 |
3287 case Variable::CONTEXT: { | 3287 case Variable::CONTEXT: { |
3288 if (variable->mode() == CONST) { | |
3289 return Bailout("reference to const context slot"); | |
3290 } | |
3291 HValue* context = BuildContextChainWalk(variable); | 3288 HValue* context = BuildContextChainWalk(variable); |
3292 HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, variable); | 3289 HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, variable); |
3293 return ast_context()->ReturnInstruction(instr, expr->id()); | 3290 return ast_context()->ReturnInstruction(instr, expr->id()); |
3294 } | 3291 } |
3295 | 3292 |
3296 case Variable::LOOKUP: | 3293 case Variable::LOOKUP: |
3297 return Bailout("reference to a variable which requires dynamic lookup"); | 3294 return Bailout("reference to a variable which requires dynamic lookup"); |
3298 } | 3295 } |
3299 } | 3296 } |
3300 | 3297 |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3798 VariableProxy* proxy = target->AsVariableProxy(); | 3795 VariableProxy* proxy = target->AsVariableProxy(); |
3799 Property* prop = target->AsProperty(); | 3796 Property* prop = target->AsProperty(); |
3800 ASSERT(proxy == NULL || prop == NULL); | 3797 ASSERT(proxy == NULL || prop == NULL); |
3801 | 3798 |
3802 // We have a second position recorded in the FullCodeGenerator to have | 3799 // We have a second position recorded in the FullCodeGenerator to have |
3803 // type feedback for the binary operation. | 3800 // type feedback for the binary operation. |
3804 BinaryOperation* operation = expr->binary_operation(); | 3801 BinaryOperation* operation = expr->binary_operation(); |
3805 | 3802 |
3806 if (proxy != NULL) { | 3803 if (proxy != NULL) { |
3807 Variable* var = proxy->var(); | 3804 Variable* var = proxy->var(); |
3808 if (var->mode() == CONST || var->mode() == LET) { | 3805 if (var->mode() == LET) { |
3809 return Bailout("unsupported let or const compound assignment"); | 3806 return Bailout("unsupported let or const compound assignment"); |
3810 } | 3807 } |
3811 | 3808 |
3812 CHECK_ALIVE(VisitForValue(operation)); | 3809 CHECK_ALIVE(VisitForValue(operation)); |
3813 | 3810 |
3814 switch (var->location()) { | 3811 switch (var->location()) { |
3815 case Variable::UNALLOCATED: | 3812 case Variable::UNALLOCATED: |
3816 HandleGlobalVariableAssignment(var, | 3813 HandleGlobalVariableAssignment(var, |
3817 Top(), | 3814 Top(), |
3818 expr->position(), | 3815 expr->position(), |
3819 expr->AssignmentId()); | 3816 expr->AssignmentId()); |
3820 break; | 3817 break; |
3821 | 3818 |
3822 case Variable::PARAMETER: | 3819 case Variable::PARAMETER: |
3823 case Variable::LOCAL: | 3820 case Variable::LOCAL: |
3824 Bind(var, Top()); | 3821 Bind(var, Top()); |
Steven
2011/12/12 13:12:44
mjsunit/compiler/regress-const.js fails because of
| |
3825 break; | 3822 break; |
3826 | 3823 |
3827 case Variable::CONTEXT: { | 3824 case Variable::CONTEXT: { |
3828 // Bail out if we try to mutate a parameter value in a function | 3825 // Bail out if we try to mutate a parameter value in a function |
3829 // using the arguments object. We do not (yet) correctly handle the | 3826 // using the arguments object. We do not (yet) correctly handle the |
3830 // arguments property of the function. | 3827 // arguments property of the function. |
3831 if (info()->scope()->arguments() != NULL) { | 3828 if (info()->scope()->arguments() != NULL) { |
3832 // Parameters will be allocated to context slots. We have no | 3829 // Parameters will be allocated to context slots. We have no |
3833 // direct way to detect that the variable is a parameter so we do | 3830 // direct way to detect that the variable is a parameter so we do |
3834 // a linear search of the parameter variables. | 3831 // a linear search of the parameter variables. |
3835 int count = info()->scope()->num_parameters(); | 3832 int count = info()->scope()->num_parameters(); |
3836 for (int i = 0; i < count; ++i) { | 3833 for (int i = 0; i < count; ++i) { |
3837 if (var == info()->scope()->parameter(i)) { | 3834 if (var == info()->scope()->parameter(i)) { |
3838 Bailout( | 3835 Bailout( |
3839 "assignment to parameter, function uses arguments object"); | 3836 "assignment to parameter, function uses arguments object"); |
3840 } | 3837 } |
3841 } | 3838 } |
3842 } | 3839 } |
3843 | 3840 |
3841 HStoreContextSlot::Mode mode; | |
3842 | |
3843 switch (var->mode()) { | |
3844 case LET: | |
3845 case CONST_HARMONY: | |
Steven
2011/12/12 13:12:44
You can put an UNREACHABLE() in the CONST_HARMONY
| |
3846 mode = HStoreContextSlot::kCheckDeoptimize; | |
3847 break; | |
3848 case CONST: | |
3849 return ast_context()->ReturnValue(Pop()); | |
3850 default: | |
3851 mode = HStoreContextSlot::kNoCheck; | |
3852 } | |
3853 | |
3844 HValue* context = BuildContextChainWalk(var); | 3854 HValue* context = BuildContextChainWalk(var); |
3845 HStoreContextSlot::Mode mode = | |
3846 (var->mode() == LET || var->mode() == CONST_HARMONY) | |
3847 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; | |
3848 HStoreContextSlot* instr = | 3855 HStoreContextSlot* instr = |
3849 new(zone()) HStoreContextSlot(context, var->index(), mode, Top()); | 3856 new(zone()) HStoreContextSlot(context, var->index(), mode, Top()); |
3850 AddInstruction(instr); | 3857 AddInstruction(instr); |
3851 if (instr->HasObservableSideEffects()) { | 3858 if (instr->HasObservableSideEffects()) { |
3852 AddSimulate(expr->AssignmentId()); | 3859 AddSimulate(expr->AssignmentId()); |
3853 } | 3860 } |
3854 break; | 3861 break; |
3855 } | 3862 } |
3856 | 3863 |
3857 case Variable::LOOKUP: | 3864 case Variable::LOOKUP: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3948 | 3955 |
3949 if (expr->is_compound()) { | 3956 if (expr->is_compound()) { |
3950 HandleCompoundAssignment(expr); | 3957 HandleCompoundAssignment(expr); |
3951 return; | 3958 return; |
3952 } | 3959 } |
3953 | 3960 |
3954 if (prop != NULL) { | 3961 if (prop != NULL) { |
3955 HandlePropertyAssignment(expr); | 3962 HandlePropertyAssignment(expr); |
3956 } else if (proxy != NULL) { | 3963 } else if (proxy != NULL) { |
3957 Variable* var = proxy->var(); | 3964 Variable* var = proxy->var(); |
3965 | |
3958 if (var->mode() == CONST) { | 3966 if (var->mode() == CONST) { |
3959 if (expr->op() != Token::INIT_CONST) { | 3967 if (expr->op() != Token::INIT_CONST) { |
3960 return Bailout("non-initializer assignment to const"); | 3968 CHECK_ALIVE(VisitForValue(expr->value())); |
3969 return ast_context()->ReturnValue(Pop()); | |
3961 } | 3970 } |
3962 if (!var->IsStackAllocated()) { | 3971 |
3963 return Bailout("assignment to const context slot"); | 3972 if (var->IsStackAllocated()) { |
3973 // We insert a use of the old value to detect unsupported uses of const | |
3974 // variables (e.g. initialization inside a loop). | |
3975 HValue* old_value = environment()->Lookup(var); | |
3976 AddInstruction(new HUseConst(old_value)); | |
3964 } | 3977 } |
3965 // We insert a use of the old value to detect unsupported uses of const | |
3966 // variables (e.g. initialization inside a loop). | |
3967 HValue* old_value = environment()->Lookup(var); | |
3968 AddInstruction(new HUseConst(old_value)); | |
3969 } else if (var->mode() == CONST_HARMONY) { | 3978 } else if (var->mode() == CONST_HARMONY) { |
3970 if (expr->op() != Token::INIT_CONST_HARMONY) { | 3979 if (expr->op() != Token::INIT_CONST_HARMONY) { |
3971 return Bailout("non-initializer assignment to const"); | 3980 return Bailout("non-initializer assignment to const"); |
3972 } | 3981 } |
3973 } | 3982 } |
3974 | 3983 |
3975 if (proxy->IsArguments()) return Bailout("assignment to arguments"); | 3984 if (proxy->IsArguments()) return Bailout("assignment to arguments"); |
3976 | 3985 |
3977 // Handle the assignment. | 3986 // Handle the assignment. |
3978 switch (var->location()) { | 3987 switch (var->location()) { |
(...skipping 18 matching lines...) Expand all Loading... | |
3997 // We do not allow the arguments object to occur in a context where it | 4006 // We do not allow the arguments object to occur in a context where it |
3998 // may escape, but assignments to stack-allocated locals are | 4007 // may escape, but assignments to stack-allocated locals are |
3999 // permitted. | 4008 // permitted. |
4000 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); | 4009 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); |
4001 HValue* value = Pop(); | 4010 HValue* value = Pop(); |
4002 Bind(var, value); | 4011 Bind(var, value); |
4003 return ast_context()->ReturnValue(value); | 4012 return ast_context()->ReturnValue(value); |
4004 } | 4013 } |
4005 | 4014 |
4006 case Variable::CONTEXT: { | 4015 case Variable::CONTEXT: { |
4007 ASSERT(var->mode() != CONST); | |
4008 // Bail out if we try to mutate a parameter value in a function using | 4016 // Bail out if we try to mutate a parameter value in a function using |
4009 // the arguments object. We do not (yet) correctly handle the | 4017 // the arguments object. We do not (yet) correctly handle the |
4010 // arguments property of the function. | 4018 // arguments property of the function. |
4011 if (info()->scope()->arguments() != NULL) { | 4019 if (info()->scope()->arguments() != NULL) { |
4012 // Parameters will rewrite to context slots. We have no direct way | 4020 // Parameters will rewrite to context slots. We have no direct way |
4013 // to detect that the variable is a parameter. | 4021 // to detect that the variable is a parameter. |
4014 int count = info()->scope()->num_parameters(); | 4022 int count = info()->scope()->num_parameters(); |
4015 for (int i = 0; i < count; ++i) { | 4023 for (int i = 0; i < count; ++i) { |
4016 if (var == info()->scope()->parameter(i)) { | 4024 if (var == info()->scope()->parameter(i)) { |
4017 return Bailout("assignment to parameter in arguments object"); | 4025 return Bailout("assignment to parameter in arguments object"); |
4018 } | 4026 } |
4019 } | 4027 } |
4020 } | 4028 } |
4021 | 4029 |
4022 CHECK_ALIVE(VisitForValue(expr->value())); | 4030 CHECK_ALIVE(VisitForValue(expr->value())); |
4023 HValue* context = BuildContextChainWalk(var); | |
4024 HStoreContextSlot::Mode mode; | 4031 HStoreContextSlot::Mode mode; |
4025 if (expr->op() == Token::ASSIGN) { | 4032 if (expr->op() == Token::ASSIGN) { |
4026 mode = (var->mode() == LET || var->mode() == CONST_HARMONY) | 4033 switch (var->mode()) { |
4027 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; | 4034 case LET: |
4035 case CONST_HARMONY: | |
Steven
2011/12/12 13:12:44
Here also CONST_HARMONY should be UNREACHABLE().
| |
4036 mode = HStoreContextSlot::kCheckDeoptimize; | |
4037 break; | |
4038 case CONST: | |
4039 return ast_context()->ReturnValue(Pop()); | |
4040 default: | |
4041 mode = HStoreContextSlot::kNoCheck; | |
4042 } | |
4043 } else if (expr->op() == Token::INIT_VAR || | |
4044 expr->op() == Token::INIT_LET) { | |
4045 mode = HStoreContextSlot::kNoCheck; | |
4028 } else { | 4046 } else { |
4029 ASSERT(expr->op() == Token::INIT_VAR || | 4047 ASSERT(expr->op() == Token::INIT_CONST_HARMONY || |
Steven
2011/12/12 13:12:44
Here CONST_HARMONY can be moved to the HStoreConte
| |
4030 expr->op() == Token::INIT_LET || | 4048 expr->op() == Token::INIT_CONST); |
4031 expr->op() == Token::INIT_CONST_HARMONY); | 4049 |
4032 mode = HStoreContextSlot::kAssign; | 4050 mode = HStoreContextSlot::kCheckIgnoreAssignment; |
4033 } | 4051 } |
4052 | |
4053 HValue* context = BuildContextChainWalk(var); | |
4034 HStoreContextSlot* instr = new(zone()) HStoreContextSlot( | 4054 HStoreContextSlot* instr = new(zone()) HStoreContextSlot( |
4035 context, var->index(), mode, Top()); | 4055 context, var->index(), mode, Top()); |
4036 AddInstruction(instr); | 4056 AddInstruction(instr); |
4037 if (instr->HasObservableSideEffects()) { | 4057 if (instr->HasObservableSideEffects()) { |
4038 AddSimulate(expr->AssignmentId()); | 4058 AddSimulate(expr->AssignmentId()); |
4039 } | 4059 } |
4040 return ast_context()->ReturnValue(Pop()); | 4060 return ast_context()->ReturnValue(Pop()); |
4041 } | 4061 } |
4042 | 4062 |
4043 case Variable::LOOKUP: | 4063 case Variable::LOOKUP: |
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5594 // element for postfix operations in a non-effect context. The return | 5614 // element for postfix operations in a non-effect context. The return |
5595 // value is ToNumber(input). | 5615 // value is ToNumber(input). |
5596 bool returns_original_input = | 5616 bool returns_original_input = |
5597 expr->is_postfix() && !ast_context()->IsEffect(); | 5617 expr->is_postfix() && !ast_context()->IsEffect(); |
5598 HValue* input = NULL; // ToNumber(original_input). | 5618 HValue* input = NULL; // ToNumber(original_input). |
5599 HValue* after = NULL; // The result after incrementing or decrementing. | 5619 HValue* after = NULL; // The result after incrementing or decrementing. |
5600 | 5620 |
5601 if (proxy != NULL) { | 5621 if (proxy != NULL) { |
5602 Variable* var = proxy->var(); | 5622 Variable* var = proxy->var(); |
5603 if (var->mode() == CONST) { | 5623 if (var->mode() == CONST) { |
5604 return Bailout("unsupported count operation with const"); | 5624 return Bailout("unsupported count operation with const"); |
Steven
2011/12/12 13:12:44
It should be trivial to also remove this bailout a
| |
5605 } | 5625 } |
5606 // Argument of the count operation is a variable, not a property. | 5626 // Argument of the count operation is a variable, not a property. |
5607 ASSERT(prop == NULL); | 5627 ASSERT(prop == NULL); |
5608 CHECK_ALIVE(VisitForValue(target)); | 5628 CHECK_ALIVE(VisitForValue(target)); |
5609 | 5629 |
5610 after = BuildIncrement(returns_original_input, expr); | 5630 after = BuildIncrement(returns_original_input, expr); |
5611 input = returns_original_input ? Top() : Pop(); | 5631 input = returns_original_input ? Top() : Pop(); |
5612 Push(after); | 5632 Push(after); |
5613 | 5633 |
5614 switch (var->location()) { | 5634 switch (var->location()) { |
(...skipping 21 matching lines...) Expand all Loading... | |
5636 for (int i = 0; i < count; ++i) { | 5656 for (int i = 0; i < count; ++i) { |
5637 if (var == info()->scope()->parameter(i)) { | 5657 if (var == info()->scope()->parameter(i)) { |
5638 return Bailout("assignment to parameter in arguments object"); | 5658 return Bailout("assignment to parameter in arguments object"); |
5639 } | 5659 } |
5640 } | 5660 } |
5641 } | 5661 } |
5642 | 5662 |
5643 HValue* context = BuildContextChainWalk(var); | 5663 HValue* context = BuildContextChainWalk(var); |
5644 HStoreContextSlot::Mode mode = | 5664 HStoreContextSlot::Mode mode = |
5645 (var->mode() == LET || var->mode() == CONST_HARMONY) | 5665 (var->mode() == LET || var->mode() == CONST_HARMONY) |
5646 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; | 5666 ? HStoreContextSlot::kCheckDeoptimize : HStoreContextSlot::kNoCheck; |
5647 HStoreContextSlot* instr = | 5667 HStoreContextSlot* instr = |
5648 new(zone()) HStoreContextSlot(context, var->index(), mode, after); | 5668 new(zone()) HStoreContextSlot(context, var->index(), mode, after); |
5649 AddInstruction(instr); | 5669 AddInstruction(instr); |
5650 if (instr->HasObservableSideEffects()) { | 5670 if (instr->HasObservableSideEffects()) { |
5651 AddSimulate(expr->AssignmentId()); | 5671 AddSimulate(expr->AssignmentId()); |
5652 } | 5672 } |
5653 break; | 5673 break; |
5654 } | 5674 } |
5655 | 5675 |
5656 case Variable::LOOKUP: | 5676 case Variable::LOOKUP: |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6244 HValue* value = NULL; | 6264 HValue* value = NULL; |
6245 if (function != NULL) { | 6265 if (function != NULL) { |
6246 VisitForValue(function); | 6266 VisitForValue(function); |
6247 value = Pop(); | 6267 value = Pop(); |
6248 } else { | 6268 } else { |
6249 value = graph()->GetConstantHole(); | 6269 value = graph()->GetConstantHole(); |
6250 } | 6270 } |
6251 if (var->IsContextSlot()) { | 6271 if (var->IsContextSlot()) { |
6252 HValue* context = environment()->LookupContext(); | 6272 HValue* context = environment()->LookupContext(); |
6253 HStoreContextSlot* store = new HStoreContextSlot( | 6273 HStoreContextSlot* store = new HStoreContextSlot( |
6254 context, var->index(), HStoreContextSlot::kAssign, value); | 6274 context, var->index(), HStoreContextSlot::kNoCheck, value); |
6255 AddInstruction(store); | 6275 AddInstruction(store); |
6256 if (store->HasObservableSideEffects()) AddSimulate(proxy->id()); | 6276 if (store->HasObservableSideEffects()) AddSimulate(proxy->id()); |
6257 } else { | 6277 } else { |
6258 environment()->Bind(var, value); | 6278 environment()->Bind(var, value); |
6259 } | 6279 } |
6260 } | 6280 } |
6261 break; | 6281 break; |
6262 case Variable::LOOKUP: | 6282 case Variable::LOOKUP: |
6263 return Bailout("unsupported lookup slot in declaration"); | 6283 return Bailout("unsupported lookup slot in declaration"); |
6264 } | 6284 } |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7266 } | 7286 } |
7267 } | 7287 } |
7268 | 7288 |
7269 #ifdef DEBUG | 7289 #ifdef DEBUG |
7270 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 7290 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
7271 if (allocator_ != NULL) allocator_->Verify(); | 7291 if (allocator_ != NULL) allocator_->Verify(); |
7272 #endif | 7292 #endif |
7273 } | 7293 } |
7274 | 7294 |
7275 } } // namespace v8::internal | 7295 } } // namespace v8::internal |
OLD | NEW |