Changeset 209728 in webkit


Ignore:
Timestamp:
Dec 12, 2016 3:11:29 PM (7 years ago)
Author:
mark.lam@apple.com
Message:

Rename BytecodeGenerator's ControlFlowContext to ControlFlowScope.
https://bugs.webkit.org/show_bug.cgi?id=165777

Reviewed by Keith Miller.

The existing code sometimes refer to ControlFlowContext (and associated references)
as context, and sometimes as scope. Let's be consistent and always call it a scope.

Also renamed push/popScopedControlFlowContext() to push/popLocalControlFlowScope()
because these are only used when we inc/dec the m_localScopeDepth.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::initializeVarLexicalEnvironment):
(JSC::BytecodeGenerator::pushLexicalScopeInternal):
(JSC::BytecodeGenerator::popLexicalScopeInternal):
(JSC::BytecodeGenerator::emitPushWithScope):
(JSC::BytecodeGenerator::emitPopWithScope):
(JSC::BytecodeGenerator::pushFinallyControlFlowScope):
(JSC::BytecodeGenerator::pushIteratorCloseControlFlowScope):
(JSC::BytecodeGenerator::popFinallyControlFlowScope):
(JSC::BytecodeGenerator::popIteratorCloseControlFlowScope):
(JSC::BytecodeGenerator::emitComplexPopScopes):
(JSC::BytecodeGenerator::emitPopScopes):
(JSC::BytecodeGenerator::pushLocalControlFlowScope):
(JSC::BytecodeGenerator::popLocalControlFlowScope):
(JSC::BytecodeGenerator::emitEnumeration):
(JSC::BytecodeGenerator::pushFinallyContext): Deleted.
(JSC::BytecodeGenerator::pushIteratorCloseContext): Deleted.
(JSC::BytecodeGenerator::popFinallyContext): Deleted.
(JSC::BytecodeGenerator::popIteratorCloseContext): Deleted.
(JSC::BytecodeGenerator::pushScopedControlFlowContext): Deleted.
(JSC::BytecodeGenerator::popScopedControlFlowContext): Deleted.

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:

(JSC::TryNode::emitBytecode):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r209727 r209728  
     12016-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
    1392016-12-12  Filip Pizlo  <fpizlo@apple.com>
    240
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r209723 r209728  
    11221122        instructions().append(m_lexicalEnvironmentRegister->index());
    11231123
    1124         pushScopedControlFlowContext();
     1124        pushLocalControlFlowScope();
    11251125    }
    11261126    bool isWithScope = false;
     
    20682068        emitMove(scopeRegister(), newScope);
    20692069
    2070         pushScopedControlFlowContext();
     2070        pushLocalControlFlowScope();
    20712071    }
    20722072
     
    21922192        RELEASE_ASSERT(stackEntry.m_scope);
    21932193        emitPopScope(scopeRegister(), stackEntry.m_scope);
    2194         popScopedControlFlowContext();
     2194        popLocalControlFlowScope();
    21952195        stackEntry.m_scope->deref();
    21962196    }
     
    36003600RegisterID* BytecodeGenerator::emitPushWithScope(RegisterID* objectScope)
    36013601{
    3602     pushScopedControlFlowContext();
     3602    pushLocalControlFlowScope();
    36033603    RegisterID* newScope = newBlockScopeVariable();
    36043604    newScope->ref();
     
    36323632{
    36333633    emitPopScope(scopeRegister(), scopeRegister());
    3634     popScopedControlFlowContext();
     3634    popLocalControlFlowScope();
    36353635    auto stackEntry = m_lexicalScopeStack.takeLast();
    36363636    stackEntry.m_scope->deref();
     
    36743674}
    36753675
    3676 void BytecodeGenerator::pushFinallyContext(StatementNode* finallyBlock)
     3676void BytecodeGenerator::pushFinallyControlFlowScope(StatementNode* finallyBlock)
    36773677{
    36783678    // Reclaim free label scopes.
     
    36803680        m_labelScopes.removeLast();
    36813681
    3682     ControlFlowContext scope;
     3682    ControlFlowScope scope;
    36833683    scope.isFinallyBlock = true;
    36843684    FinallyContext context = {
     
    36863686        nullptr,
    36873687        nullptr,
    3688         static_cast<unsigned>(m_scopeContextStack.size()),
     3688        static_cast<unsigned>(m_controlFlowScopeStack.size()),
    36893689        static_cast<unsigned>(m_switchContextStack.size()),
    36903690        static_cast<unsigned>(m_forInContextStack.size()),
     
    36963696    };
    36973697    scope.finallyContext = context;
    3698     m_scopeContextStack.append(scope);
     3698    m_controlFlowScopeStack.append(scope);
    36993699    m_finallyDepth++;
    37003700}
    37013701
    3702 void BytecodeGenerator::pushIteratorCloseContext(RegisterID* iterator, ThrowableExpressionData* node)
     3702void BytecodeGenerator::pushIteratorCloseControlFlowScope(RegisterID* iterator, ThrowableExpressionData* node)
    37033703{
    37043704    // Reclaim free label scopes.
     
    37063706        m_labelScopes.removeLast();
    37073707
    3708     ControlFlowContext scope;
     3708    ControlFlowScope scope;
    37093709    scope.isFinallyBlock = true;
    37103710    FinallyContext context = {
     
    37123712        iterator,
    37133713        node,
    3714         static_cast<unsigned>(m_scopeContextStack.size()),
     3714        static_cast<unsigned>(m_controlFlowScopeStack.size()),
    37153715        static_cast<unsigned>(m_switchContextStack.size()),
    37163716        static_cast<unsigned>(m_forInContextStack.size()),
     
    37223722    };
    37233723    scope.finallyContext = context;
    3724     m_scopeContextStack.append(scope);
     3724    m_controlFlowScopeStack.append(scope);
    37253725    m_finallyDepth++;
    37263726}
    37273727
    3728 void BytecodeGenerator::popFinallyContext()
    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);
     3728void 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);
    37353735    ASSERT(m_finallyDepth > 0);
    3736     m_scopeContextStack.removeLast();
     3736    m_controlFlowScopeStack.removeLast();
    37373737    m_finallyDepth--;
    37383738}
    37393739
    3740 void BytecodeGenerator::popIteratorCloseContext()
    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);
     3740void 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);
    37473747    ASSERT(m_finallyDepth > 0);
    3748     m_scopeContextStack.removeLast();
     3748    m_controlFlowScopeStack.removeLast();
    37493749    m_finallyDepth--;
    37503750}
     
    38483848}
    38493849   
    3850 void BytecodeGenerator::emitComplexPopScopes(RegisterID* scope, ControlFlowContext* topScope, ControlFlowContext* bottomScope)
     3850void BytecodeGenerator::emitComplexPopScopes(RegisterID* scope, ControlFlowScope* topScope, ControlFlowScope* bottomScope)
    38513851{
    38523852    while (topScope > bottomScope) {
    38533853        // First we count the number of dynamic scopes we need to remove to get
    38543854        // to a finally block.
    3855         int nNormalScopes = 0;
     3855        int numberOfNormalScopes = 0;
    38563856        while (topScope > bottomScope) {
    38573857            if (topScope->isFinallyBlock)
    38583858                break;
    3859             ++nNormalScopes;
     3859            ++numberOfNormalScopes;
    38603860            --topScope;
    38613861        }
    38623862
    3863         if (nNormalScopes) {
     3863        if (numberOfNormalScopes) {
    38643864            // We need to remove a number of dynamic scopes to get to the next
    38653865            // finally block
    38663866            RefPtr<RegisterID> parentScope = newTemporary();
    3867             while (nNormalScopes--) {
     3867            while (numberOfNormalScopes--) {
    38683868                parentScope = emitGetParentScope(parentScope.get(), scope);
    38693869                emitMove(scope, parentScope.get());
     
    38753875        }
    38763876       
    3877         Vector<ControlFlowContext> savedScopeContextStack;
     3877        Vector<ControlFlowScope> savedControlFlowScopeStack;
    38783878        Vector<SwitchInfo> savedSwitchContextStack;
    38793879        Vector<RefPtr<ForInContext>> savedForInContextStack;
     
    38873887            // for the finally block.
    38883888            FinallyContext finallyContext = topScope->finallyContext;
    3889             bool flipScopes = finallyContext.scopeContextStackSize != m_scopeContextStack.size();
     3889            bool flipScopes = finallyContext.controlFlowScopeStackSize != m_controlFlowScopeStack.size();
    38903890            bool flipSwitches = finallyContext.switchContextStackSize != m_switchContextStack.size();
    38913891            bool flipForIns = finallyContext.forInContextStackSize != m_forInContextStack.size();
     
    38963896            int bottomScopeIndex = -1;
    38973897            if (flipScopes) {
    3898                 topScopeIndex = topScope - m_scopeContextStack.begin();
    3899                 bottomScopeIndex = bottomScope - m_scopeContextStack.begin();
    3900                 savedScopeContextStack = 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);
    39023902            }
    39033903            if (flipSwitches) {
     
    39483948            // Restore the state of the world.
    39493949            if (flipScopes) {
    3950                 m_scopeContextStack = savedScopeContextStack;
    3951                 topScope = &m_scopeContextStack[topScopeIndex]; // assert it's within bounds
    3952                 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.
    39533953            }
    39543954            if (flipSwitches)
     
    39823982
    39833983    size_t scopeDelta = labelScopeDepth() - targetScopeDepth;
    3984     ASSERT(scopeDelta <= m_scopeContextStack.size());
     3984    ASSERT(scopeDelta <= m_controlFlowScopeStack.size());
    39853985    if (!scopeDelta)
    39863986        return;
     
    39953995    }
    39963996
    3997     emitComplexPopScopes(scope, &m_scopeContextStack.last(), &m_scopeContextStack.last() - scopeDelta);
     3997    emitComplexPopScopes(scope, &m_controlFlowScopeStack.last(), &m_controlFlowScopeStack.last() - scopeDelta);
    39983998}
    39993999
     
    41244124}
    41254125
    4126 void BytecodeGenerator::pushScopedControlFlowContext()
    4127 {
    4128     ControlFlowContext context;
    4129     context.isFinallyBlock = false;
    4130     m_scopeContextStack.append(context);
     4126void BytecodeGenerator::pushLocalControlFlowScope()
     4127{
     4128    ControlFlowScope scope;
     4129    scope.isFinallyBlock = false;
     4130    m_controlFlowScopeStack.append(scope);
    41314131    m_localScopeDepth++;
    41324132}
    41334133
    4134 void BytecodeGenerator::popScopedControlFlowContext()
    4135 {
    4136     ASSERT(m_scopeContextStack.size());
    4137     ASSERT(!m_scopeContextStack.last().isFinallyBlock);
    4138     m_scopeContextStack.removeLast();
     4134void BytecodeGenerator::popLocalControlFlowScope()
     4135{
     4136    ASSERT(m_controlFlowScopeStack.size());
     4137    ASSERT(!m_controlFlowScopeStack.last().isFinallyBlock);
     4138    m_controlFlowScopeStack.removeLast();
    41394139    m_localScopeDepth--;
    41404140}
     
    43044304    RefPtr<Label> loopDone = newLabel();
    43054305    // RefPtr<Register> iterator's lifetime must be longer than IteratorCloseContext.
    4306     pushIteratorCloseContext(iterator.get(), node);
     4306    pushIteratorCloseControlFlowScope(iterator.get(), node);
    43074307    {
    43084308        LabelScopePtr scope = newLabelScope(LabelScope::Loop);
     
    43704370
    43714371    // IteratorClose sequence for break-ed control flow.
    4372     popIteratorCloseContext();
     4372    popIteratorCloseControlFlowScope();
    43734373    emitIteratorClose(iterator.get(), node);
    43744374    emitLabel(loopDone.get());
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r209723 r209728  
    8585        RegisterID* iterator;
    8686        ThrowableExpressionData* enumerationNode;
    87         unsigned scopeContextStackSize;
     87        unsigned controlFlowScopeStackSize;
    8888        unsigned switchContextStackSize;
    8989        unsigned forInContextStackSize;
     
    9595    };
    9696
    97     struct ControlFlowContext {
     97    struct ControlFlowScope {
    9898        bool isFinallyBlock;
    9999        FinallyContext finallyContext;
     
    701701        bool isInFinallyBlock() { return m_finallyDepth > 0; }
    702702
    703         void pushFinallyContext(StatementNode* finallyBlock);
    704         void popFinallyContext();
    705         void pushIteratorCloseContext(RegisterID* iterator, ThrowableExpressionData* enumerationNode);
    706         void popIteratorCloseContext();
     703        void pushFinallyControlFlowScope(StatementNode* finallyBlock);
     704        void popFinallyControlFlowScope();
     705        void pushIteratorCloseControlFlowScope(RegisterID* iterator, ThrowableExpressionData* enumerationNode);
     706        void popIteratorCloseControlFlowScope();
    707707
    708708        void pushIndexedForInScope(RegisterID* local, RegisterID* index);
     
    798798        void allocateCalleeSaveSpace();
    799799        void allocateAndEmitScope();
    800         void emitComplexPopScopes(RegisterID*, ControlFlowContext* topScope, ControlFlowContext* bottomScope);
     800        void emitComplexPopScopes(RegisterID*, ControlFlowScope* topScope, ControlFlowScope* bottomScope);
    801801
    802802        typedef HashMap<double, JSValue> NumberMap;
     
    947947
    948948        int localScopeDepth() const;
    949         void pushScopedControlFlowContext();
    950         void popScopedControlFlowContext();
    951 
    952         Vector<ControlFlowContext, 0, UnsafeVectorOverflow> m_scopeContextStack;
     949        void pushLocalControlFlowScope();
     950        void popLocalControlFlowScope();
     951
     952        Vector<ControlFlowScope, 0, UnsafeVectorOverflow> m_controlFlowScopeStack;
    953953        Vector<SwitchInfo> m_switchContextStack;
    954954        Vector<RefPtr<ForInContext>> m_forInContextStack;
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r208985 r209728  
    32853285   
    32863286    if (m_finallyBlock)
    3287         generator.pushFinallyContext(m_finallyBlock);
     3287        generator.pushFinallyControlFlowScope(m_finallyBlock);
    32883288    TryData* tryData = generator.pushTry(tryStartLabel.get());
    32893289
     
    33233323        RefPtr<Label> preFinallyLabel = generator.emitLabel(generator.newLabel().get());
    33243324       
    3325         generator.popFinallyContext();
     3325        generator.popFinallyControlFlowScope();
    33263326
    33273327        RefPtr<Label> finallyEndLabel = generator.newLabel();
Note: See TracChangeset for help on using the changeset viewer.