Changeset 209728 in webkit
- Timestamp:
- Dec 12, 2016, 3:11:29 PM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r209727 r209728 1 2016-12-12 Mark Lam <mark.lam@apple.com> 2 3 Rename BytecodeGenerator's ControlFlowContext to ControlFlowScope. 4 https://bugs.webkit.org/show_bug.cgi?id=165777 5 6 Reviewed by Keith Miller. 7 8 The existing code sometimes refer to ControlFlowContext (and associated references) 9 as context, and sometimes as scope. Let's be consistent and always call it a scope. 10 11 Also renamed push/popScopedControlFlowContext() to push/popLocalControlFlowScope() 12 because these are only used when we inc/dec the m_localScopeDepth. 13 14 * bytecompiler/BytecodeGenerator.cpp: 15 (JSC::BytecodeGenerator::initializeVarLexicalEnvironment): 16 (JSC::BytecodeGenerator::pushLexicalScopeInternal): 17 (JSC::BytecodeGenerator::popLexicalScopeInternal): 18 (JSC::BytecodeGenerator::emitPushWithScope): 19 (JSC::BytecodeGenerator::emitPopWithScope): 20 (JSC::BytecodeGenerator::pushFinallyControlFlowScope): 21 (JSC::BytecodeGenerator::pushIteratorCloseControlFlowScope): 22 (JSC::BytecodeGenerator::popFinallyControlFlowScope): 23 (JSC::BytecodeGenerator::popIteratorCloseControlFlowScope): 24 (JSC::BytecodeGenerator::emitComplexPopScopes): 25 (JSC::BytecodeGenerator::emitPopScopes): 26 (JSC::BytecodeGenerator::pushLocalControlFlowScope): 27 (JSC::BytecodeGenerator::popLocalControlFlowScope): 28 (JSC::BytecodeGenerator::emitEnumeration): 29 (JSC::BytecodeGenerator::pushFinallyContext): Deleted. 30 (JSC::BytecodeGenerator::pushIteratorCloseContext): Deleted. 31 (JSC::BytecodeGenerator::popFinallyContext): Deleted. 32 (JSC::BytecodeGenerator::popIteratorCloseContext): Deleted. 33 (JSC::BytecodeGenerator::pushScopedControlFlowContext): Deleted. 34 (JSC::BytecodeGenerator::popScopedControlFlowContext): Deleted. 35 * bytecompiler/BytecodeGenerator.h: 36 * bytecompiler/NodesCodegen.cpp: 37 (JSC::TryNode::emitBytecode): 38 1 39 2016-12-12 Filip Pizlo <fpizlo@apple.com> 2 40 -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r209723 r209728 1122 1122 instructions().append(m_lexicalEnvironmentRegister->index()); 1123 1123 1124 push ScopedControlFlowContext();1124 pushLocalControlFlowScope(); 1125 1125 } 1126 1126 bool isWithScope = false; … … 2068 2068 emitMove(scopeRegister(), newScope); 2069 2069 2070 push ScopedControlFlowContext();2070 pushLocalControlFlowScope(); 2071 2071 } 2072 2072 … … 2192 2192 RELEASE_ASSERT(stackEntry.m_scope); 2193 2193 emitPopScope(scopeRegister(), stackEntry.m_scope); 2194 pop ScopedControlFlowContext();2194 popLocalControlFlowScope(); 2195 2195 stackEntry.m_scope->deref(); 2196 2196 } … … 3600 3600 RegisterID* BytecodeGenerator::emitPushWithScope(RegisterID* objectScope) 3601 3601 { 3602 push ScopedControlFlowContext();3602 pushLocalControlFlowScope(); 3603 3603 RegisterID* newScope = newBlockScopeVariable(); 3604 3604 newScope->ref(); … … 3632 3632 { 3633 3633 emitPopScope(scopeRegister(), scopeRegister()); 3634 pop ScopedControlFlowContext();3634 popLocalControlFlowScope(); 3635 3635 auto stackEntry = m_lexicalScopeStack.takeLast(); 3636 3636 stackEntry.m_scope->deref(); … … 3674 3674 } 3675 3675 3676 void BytecodeGenerator::pushFinallyCont ext(StatementNode* finallyBlock)3676 void BytecodeGenerator::pushFinallyControlFlowScope(StatementNode* finallyBlock) 3677 3677 { 3678 3678 // Reclaim free label scopes. … … 3680 3680 m_labelScopes.removeLast(); 3681 3681 3682 ControlFlow Contextscope;3682 ControlFlowScope scope; 3683 3683 scope.isFinallyBlock = true; 3684 3684 FinallyContext context = { … … 3686 3686 nullptr, 3687 3687 nullptr, 3688 static_cast<unsigned>(m_ scopeContextStack.size()),3688 static_cast<unsigned>(m_controlFlowScopeStack.size()), 3689 3689 static_cast<unsigned>(m_switchContextStack.size()), 3690 3690 static_cast<unsigned>(m_forInContextStack.size()), … … 3696 3696 }; 3697 3697 scope.finallyContext = context; 3698 m_ scopeContextStack.append(scope);3698 m_controlFlowScopeStack.append(scope); 3699 3699 m_finallyDepth++; 3700 3700 } 3701 3701 3702 void BytecodeGenerator::pushIteratorCloseCont ext(RegisterID* iterator, ThrowableExpressionData* node)3702 void BytecodeGenerator::pushIteratorCloseControlFlowScope(RegisterID* iterator, ThrowableExpressionData* node) 3703 3703 { 3704 3704 // Reclaim free label scopes. … … 3706 3706 m_labelScopes.removeLast(); 3707 3707 3708 ControlFlow Contextscope;3708 ControlFlowScope scope; 3709 3709 scope.isFinallyBlock = true; 3710 3710 FinallyContext context = { … … 3712 3712 iterator, 3713 3713 node, 3714 static_cast<unsigned>(m_ scopeContextStack.size()),3714 static_cast<unsigned>(m_controlFlowScopeStack.size()), 3715 3715 static_cast<unsigned>(m_switchContextStack.size()), 3716 3716 static_cast<unsigned>(m_forInContextStack.size()), … … 3722 3722 }; 3723 3723 scope.finallyContext = context; 3724 m_ scopeContextStack.append(scope);3724 m_controlFlowScopeStack.append(scope); 3725 3725 m_finallyDepth++; 3726 3726 } 3727 3727 3728 void BytecodeGenerator::popFinallyCont ext()3729 { 3730 ASSERT(m_ scopeContextStack.size());3731 ASSERT(m_ scopeContextStack.last().isFinallyBlock);3732 ASSERT(m_ scopeContextStack.last().finallyContext.finallyBlock);3733 ASSERT(!m_ scopeContextStack.last().finallyContext.iterator);3734 ASSERT(!m_ scopeContextStack.last().finallyContext.enumerationNode);3728 void BytecodeGenerator::popFinallyControlFlowScope() 3729 { 3730 ASSERT(m_controlFlowScopeStack.size()); 3731 ASSERT(m_controlFlowScopeStack.last().isFinallyBlock); 3732 ASSERT(m_controlFlowScopeStack.last().finallyContext.finallyBlock); 3733 ASSERT(!m_controlFlowScopeStack.last().finallyContext.iterator); 3734 ASSERT(!m_controlFlowScopeStack.last().finallyContext.enumerationNode); 3735 3735 ASSERT(m_finallyDepth > 0); 3736 m_ scopeContextStack.removeLast();3736 m_controlFlowScopeStack.removeLast(); 3737 3737 m_finallyDepth--; 3738 3738 } 3739 3739 3740 void BytecodeGenerator::popIteratorCloseCont ext()3741 { 3742 ASSERT(m_ scopeContextStack.size());3743 ASSERT(m_ scopeContextStack.last().isFinallyBlock);3744 ASSERT(!m_ scopeContextStack.last().finallyContext.finallyBlock);3745 ASSERT(m_ scopeContextStack.last().finallyContext.iterator);3746 ASSERT(m_ scopeContextStack.last().finallyContext.enumerationNode);3740 void BytecodeGenerator::popIteratorCloseControlFlowScope() 3741 { 3742 ASSERT(m_controlFlowScopeStack.size()); 3743 ASSERT(m_controlFlowScopeStack.last().isFinallyBlock); 3744 ASSERT(!m_controlFlowScopeStack.last().finallyContext.finallyBlock); 3745 ASSERT(m_controlFlowScopeStack.last().finallyContext.iterator); 3746 ASSERT(m_controlFlowScopeStack.last().finallyContext.enumerationNode); 3747 3747 ASSERT(m_finallyDepth > 0); 3748 m_ scopeContextStack.removeLast();3748 m_controlFlowScopeStack.removeLast(); 3749 3749 m_finallyDepth--; 3750 3750 } … … 3848 3848 } 3849 3849 3850 void BytecodeGenerator::emitComplexPopScopes(RegisterID* scope, ControlFlow Context* topScope, ControlFlowContext* bottomScope)3850 void BytecodeGenerator::emitComplexPopScopes(RegisterID* scope, ControlFlowScope* topScope, ControlFlowScope* bottomScope) 3851 3851 { 3852 3852 while (topScope > bottomScope) { 3853 3853 // First we count the number of dynamic scopes we need to remove to get 3854 3854 // to a finally block. 3855 int n NormalScopes = 0;3855 int numberOfNormalScopes = 0; 3856 3856 while (topScope > bottomScope) { 3857 3857 if (topScope->isFinallyBlock) 3858 3858 break; 3859 ++n NormalScopes;3859 ++numberOfNormalScopes; 3860 3860 --topScope; 3861 3861 } 3862 3862 3863 if (n NormalScopes) {3863 if (numberOfNormalScopes) { 3864 3864 // We need to remove a number of dynamic scopes to get to the next 3865 3865 // finally block 3866 3866 RefPtr<RegisterID> parentScope = newTemporary(); 3867 while (n NormalScopes--) {3867 while (numberOfNormalScopes--) { 3868 3868 parentScope = emitGetParentScope(parentScope.get(), scope); 3869 3869 emitMove(scope, parentScope.get()); … … 3875 3875 } 3876 3876 3877 Vector<ControlFlow Context> savedScopeContextStack;3877 Vector<ControlFlowScope> savedControlFlowScopeStack; 3878 3878 Vector<SwitchInfo> savedSwitchContextStack; 3879 3879 Vector<RefPtr<ForInContext>> savedForInContextStack; … … 3887 3887 // for the finally block. 3888 3888 FinallyContext finallyContext = topScope->finallyContext; 3889 bool flipScopes = finallyContext. scopeContextStackSize != m_scopeContextStack.size();3889 bool flipScopes = finallyContext.controlFlowScopeStackSize != m_controlFlowScopeStack.size(); 3890 3890 bool flipSwitches = finallyContext.switchContextStackSize != m_switchContextStack.size(); 3891 3891 bool flipForIns = finallyContext.forInContextStackSize != m_forInContextStack.size(); … … 3896 3896 int bottomScopeIndex = -1; 3897 3897 if (flipScopes) { 3898 topScopeIndex = topScope - m_ scopeContextStack.begin();3899 bottomScopeIndex = bottomScope - m_ scopeContextStack.begin();3900 saved ScopeContextStack = m_scopeContextStack;3901 m_ scopeContextStack.shrink(finallyContext.scopeContextStackSize);3898 topScopeIndex = topScope - m_controlFlowScopeStack.begin(); 3899 bottomScopeIndex = bottomScope - m_controlFlowScopeStack.begin(); 3900 savedControlFlowScopeStack = m_controlFlowScopeStack; 3901 m_controlFlowScopeStack.shrink(finallyContext.controlFlowScopeStackSize); 3902 3902 } 3903 3903 if (flipSwitches) { … … 3948 3948 // Restore the state of the world. 3949 3949 if (flipScopes) { 3950 m_ scopeContextStack = savedScopeContextStack;3951 topScope = &m_ scopeContextStack[topScopeIndex]; // assert it's within bounds3952 bottomScope = m_ scopeContextStack.begin() + bottomScopeIndex; // don't assert, since it the index might be -1.3950 m_controlFlowScopeStack = savedControlFlowScopeStack; 3951 topScope = &m_controlFlowScopeStack[topScopeIndex]; // assert it's within bounds 3952 bottomScope = m_controlFlowScopeStack.begin() + bottomScopeIndex; // don't assert, since it the index might be -1. 3953 3953 } 3954 3954 if (flipSwitches) … … 3982 3982 3983 3983 size_t scopeDelta = labelScopeDepth() - targetScopeDepth; 3984 ASSERT(scopeDelta <= m_ scopeContextStack.size());3984 ASSERT(scopeDelta <= m_controlFlowScopeStack.size()); 3985 3985 if (!scopeDelta) 3986 3986 return; … … 3995 3995 } 3996 3996 3997 emitComplexPopScopes(scope, &m_ scopeContextStack.last(), &m_scopeContextStack.last() - scopeDelta);3997 emitComplexPopScopes(scope, &m_controlFlowScopeStack.last(), &m_controlFlowScopeStack.last() - scopeDelta); 3998 3998 } 3999 3999 … … 4124 4124 } 4125 4125 4126 void BytecodeGenerator::push ScopedControlFlowContext()4127 { 4128 ControlFlow Context context;4129 context.isFinallyBlock = false;4130 m_ scopeContextStack.append(context);4126 void BytecodeGenerator::pushLocalControlFlowScope() 4127 { 4128 ControlFlowScope scope; 4129 scope.isFinallyBlock = false; 4130 m_controlFlowScopeStack.append(scope); 4131 4131 m_localScopeDepth++; 4132 4132 } 4133 4133 4134 void BytecodeGenerator::pop ScopedControlFlowContext()4135 { 4136 ASSERT(m_ scopeContextStack.size());4137 ASSERT(!m_ scopeContextStack.last().isFinallyBlock);4138 m_ scopeContextStack.removeLast();4134 void BytecodeGenerator::popLocalControlFlowScope() 4135 { 4136 ASSERT(m_controlFlowScopeStack.size()); 4137 ASSERT(!m_controlFlowScopeStack.last().isFinallyBlock); 4138 m_controlFlowScopeStack.removeLast(); 4139 4139 m_localScopeDepth--; 4140 4140 } … … 4304 4304 RefPtr<Label> loopDone = newLabel(); 4305 4305 // RefPtr<Register> iterator's lifetime must be longer than IteratorCloseContext. 4306 pushIteratorCloseCont ext(iterator.get(), node);4306 pushIteratorCloseControlFlowScope(iterator.get(), node); 4307 4307 { 4308 4308 LabelScopePtr scope = newLabelScope(LabelScope::Loop); … … 4370 4370 4371 4371 // IteratorClose sequence for break-ed control flow. 4372 popIteratorCloseCont ext();4372 popIteratorCloseControlFlowScope(); 4373 4373 emitIteratorClose(iterator.get(), node); 4374 4374 emitLabel(loopDone.get()); -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r209723 r209728 85 85 RegisterID* iterator; 86 86 ThrowableExpressionData* enumerationNode; 87 unsigned scopeContextStackSize;87 unsigned controlFlowScopeStackSize; 88 88 unsigned switchContextStackSize; 89 89 unsigned forInContextStackSize; … … 95 95 }; 96 96 97 struct ControlFlow Context{97 struct ControlFlowScope { 98 98 bool isFinallyBlock; 99 99 FinallyContext finallyContext; … … 701 701 bool isInFinallyBlock() { return m_finallyDepth > 0; } 702 702 703 void pushFinallyCont ext(StatementNode* finallyBlock);704 void popFinallyCont ext();705 void pushIteratorCloseCont ext(RegisterID* iterator, ThrowableExpressionData* enumerationNode);706 void popIteratorCloseCont ext();703 void pushFinallyControlFlowScope(StatementNode* finallyBlock); 704 void popFinallyControlFlowScope(); 705 void pushIteratorCloseControlFlowScope(RegisterID* iterator, ThrowableExpressionData* enumerationNode); 706 void popIteratorCloseControlFlowScope(); 707 707 708 708 void pushIndexedForInScope(RegisterID* local, RegisterID* index); … … 798 798 void allocateCalleeSaveSpace(); 799 799 void allocateAndEmitScope(); 800 void emitComplexPopScopes(RegisterID*, ControlFlow Context* topScope, ControlFlowContext* bottomScope);800 void emitComplexPopScopes(RegisterID*, ControlFlowScope* topScope, ControlFlowScope* bottomScope); 801 801 802 802 typedef HashMap<double, JSValue> NumberMap; … … 947 947 948 948 int localScopeDepth() const; 949 void push ScopedControlFlowContext();950 void pop ScopedControlFlowContext();951 952 Vector<ControlFlow Context, 0, UnsafeVectorOverflow> m_scopeContextStack;949 void pushLocalControlFlowScope(); 950 void popLocalControlFlowScope(); 951 952 Vector<ControlFlowScope, 0, UnsafeVectorOverflow> m_controlFlowScopeStack; 953 953 Vector<SwitchInfo> m_switchContextStack; 954 954 Vector<RefPtr<ForInContext>> m_forInContextStack; -
trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r208985 r209728 3285 3285 3286 3286 if (m_finallyBlock) 3287 generator.pushFinallyCont ext(m_finallyBlock);3287 generator.pushFinallyControlFlowScope(m_finallyBlock); 3288 3288 TryData* tryData = generator.pushTry(tryStartLabel.get()); 3289 3289 … … 3323 3323 RefPtr<Label> preFinallyLabel = generator.emitLabel(generator.newLabel().get()); 3324 3324 3325 generator.popFinallyCont ext();3325 generator.popFinallyControlFlowScope(); 3326 3326 3327 3327 RefPtr<Label> finallyEndLabel = generator.newLabel();
Note:
See TracChangeset
for help on using the changeset viewer.