Chromium Code Reviews| Index: src/hydrogen.cc |
| diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
| index 36632374e1ec7d1c00ccc511b9b4b5b98b9f7484..37b58302d5c8d3e47a0b8f0d9c0baec19a330a6b 100644 |
| --- a/src/hydrogen.cc |
| +++ b/src/hydrogen.cc |
| @@ -3285,9 +3285,6 @@ void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) { |
| } |
| case Variable::CONTEXT: { |
| - if (variable->mode() == CONST) { |
| - return Bailout("reference to const context slot"); |
| - } |
| HValue* context = BuildContextChainWalk(variable); |
| HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, variable); |
| return ast_context()->ReturnInstruction(instr, expr->id()); |
| @@ -3805,7 +3802,7 @@ void HGraphBuilder::HandleCompoundAssignment(Assignment* expr) { |
| if (proxy != NULL) { |
| Variable* var = proxy->var(); |
| - if (var->mode() == CONST || var->mode() == LET) { |
| + if (var->mode() == LET) { |
| return Bailout("unsupported let or const compound assignment"); |
| } |
| @@ -3841,10 +3838,20 @@ void HGraphBuilder::HandleCompoundAssignment(Assignment* expr) { |
| } |
| } |
| + HStoreContextSlot::Mode mode; |
| + |
| + switch (var->mode()) { |
| + case LET: |
| + case CONST_HARMONY: |
|
Steven
2011/12/12 13:12:44
You can put an UNREACHABLE() in the CONST_HARMONY
|
| + mode = HStoreContextSlot::kCheckDeoptimize; |
| + break; |
| + case CONST: |
| + return ast_context()->ReturnValue(Pop()); |
| + default: |
| + mode = HStoreContextSlot::kNoCheck; |
| + } |
| + |
| HValue* context = BuildContextChainWalk(var); |
| - HStoreContextSlot::Mode mode = |
| - (var->mode() == LET || var->mode() == CONST_HARMONY) |
| - ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; |
| HStoreContextSlot* instr = |
| new(zone()) HStoreContextSlot(context, var->index(), mode, Top()); |
| AddInstruction(instr); |
| @@ -3955,17 +3962,19 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { |
| HandlePropertyAssignment(expr); |
| } else if (proxy != NULL) { |
| Variable* var = proxy->var(); |
| + |
| if (var->mode() == CONST) { |
| if (expr->op() != Token::INIT_CONST) { |
| - return Bailout("non-initializer assignment to const"); |
| + CHECK_ALIVE(VisitForValue(expr->value())); |
| + return ast_context()->ReturnValue(Pop()); |
| } |
| - if (!var->IsStackAllocated()) { |
| - return Bailout("assignment to const context slot"); |
| + |
| + if (var->IsStackAllocated()) { |
| + // We insert a use of the old value to detect unsupported uses of const |
| + // variables (e.g. initialization inside a loop). |
| + HValue* old_value = environment()->Lookup(var); |
| + AddInstruction(new HUseConst(old_value)); |
| } |
| - // We insert a use of the old value to detect unsupported uses of const |
| - // variables (e.g. initialization inside a loop). |
| - HValue* old_value = environment()->Lookup(var); |
| - AddInstruction(new HUseConst(old_value)); |
| } else if (var->mode() == CONST_HARMONY) { |
| if (expr->op() != Token::INIT_CONST_HARMONY) { |
| return Bailout("non-initializer assignment to const"); |
| @@ -4004,7 +4013,6 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { |
| } |
| case Variable::CONTEXT: { |
| - ASSERT(var->mode() != CONST); |
| // Bail out if we try to mutate a parameter value in a function using |
| // the arguments object. We do not (yet) correctly handle the |
| // arguments property of the function. |
| @@ -4020,17 +4028,29 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { |
| } |
| CHECK_ALIVE(VisitForValue(expr->value())); |
| - HValue* context = BuildContextChainWalk(var); |
| HStoreContextSlot::Mode mode; |
| if (expr->op() == Token::ASSIGN) { |
| - mode = (var->mode() == LET || var->mode() == CONST_HARMONY) |
| - ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; |
| + switch (var->mode()) { |
| + case LET: |
| + case CONST_HARMONY: |
|
Steven
2011/12/12 13:12:44
Here also CONST_HARMONY should be UNREACHABLE().
|
| + mode = HStoreContextSlot::kCheckDeoptimize; |
| + break; |
| + case CONST: |
| + return ast_context()->ReturnValue(Pop()); |
| + default: |
| + mode = HStoreContextSlot::kNoCheck; |
| + } |
| + } else if (expr->op() == Token::INIT_VAR || |
| + expr->op() == Token::INIT_LET) { |
| + mode = HStoreContextSlot::kNoCheck; |
| } else { |
| - ASSERT(expr->op() == Token::INIT_VAR || |
| - expr->op() == Token::INIT_LET || |
| - expr->op() == Token::INIT_CONST_HARMONY); |
| - mode = HStoreContextSlot::kAssign; |
| + ASSERT(expr->op() == Token::INIT_CONST_HARMONY || |
|
Steven
2011/12/12 13:12:44
Here CONST_HARMONY can be moved to the HStoreConte
|
| + expr->op() == Token::INIT_CONST); |
| + |
| + mode = HStoreContextSlot::kCheckIgnoreAssignment; |
| } |
| + |
| + HValue* context = BuildContextChainWalk(var); |
| HStoreContextSlot* instr = new(zone()) HStoreContextSlot( |
| context, var->index(), mode, Top()); |
| AddInstruction(instr); |
| @@ -5643,7 +5663,7 @@ void HGraphBuilder::VisitCountOperation(CountOperation* expr) { |
| HValue* context = BuildContextChainWalk(var); |
| HStoreContextSlot::Mode mode = |
| (var->mode() == LET || var->mode() == CONST_HARMONY) |
| - ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; |
| + ? HStoreContextSlot::kCheckDeoptimize : HStoreContextSlot::kNoCheck; |
| HStoreContextSlot* instr = |
| new(zone()) HStoreContextSlot(context, var->index(), mode, after); |
| AddInstruction(instr); |
| @@ -6251,7 +6271,7 @@ void HGraphBuilder::HandleDeclaration(VariableProxy* proxy, |
| if (var->IsContextSlot()) { |
| HValue* context = environment()->LookupContext(); |
| HStoreContextSlot* store = new HStoreContextSlot( |
| - context, var->index(), HStoreContextSlot::kAssign, value); |
| + context, var->index(), HStoreContextSlot::kNoCheck, value); |
| AddInstruction(store); |
| if (store->HasObservableSideEffects()) AddSimulate(proxy->id()); |
| } else { |