Changeset 209723 in webkit


Ignore:
Timestamp:
Dec 12, 2016 1:03:49 PM (7 years ago)
Author:
mark.lam@apple.com
Message:

Rename BytecodeGenerator's m_symbolTableStack to m_lexicalScopeStack.
https://bugs.webkit.org/show_bug.cgi?id=165768

Reviewed by Saam Barati.

The lexical scope in "m_lexicalScopeStack" here refers to a pair of { } in the
source code that bounds the scope of variables.

There are 4 places in the code where we call m_symbolTableStack.append() to
append a new stack entry. In only 3 of the 4 cases, a symbol table is provided
in the new stack entry. In all 4 cases, a scope register is provided in the new
stack entry.

Also, 3 of the 4 functions that appends an entry to this stack are named:

  1. initializeVarLexicalEnvironment()
  2. pushLexicalScopeInternal()
  3. emitPushWithScope()

The 4th function is the BytecodeGenerator constructor where it pushes the scope
for a module environment.

Based on these details, m_lexicalScopeStack is a better name for this stack than
m_symbolTableStack.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded):
(JSC::BytecodeGenerator::initializeVarLexicalEnvironment):
(JSC::BytecodeGenerator::pushLexicalScopeInternal):
(JSC::BytecodeGenerator::initializeBlockScopedFunctions):
(JSC::BytecodeGenerator::hoistSloppyModeFunctionIfNecessary):
(JSC::BytecodeGenerator::popLexicalScopeInternal):
(JSC::BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration):
(JSC::BytecodeGenerator::variable):
(JSC::BytecodeGenerator::resolveType):
(JSC::BytecodeGenerator::emitResolveScope):
(JSC::BytecodeGenerator::emitPushWithScope):
(JSC::BytecodeGenerator::emitPopWithScope):
(JSC::BytecodeGenerator::pushFinallyContext):
(JSC::BytecodeGenerator::pushIteratorCloseContext):
(JSC::BytecodeGenerator::emitComplexPopScopes):
(JSC::BytecodeGenerator::popTryAndEmitCatch):
(JSC::BytecodeGenerator::emitPushFunctionNameScope):

  • bytecompiler/BytecodeGenerator.h:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r209722 r209723  
     12016-12-12  Mark Lam  <mark.lam@apple.com>
     2
     3        Rename BytecodeGenerator's m_symbolTableStack to m_lexicalScopeStack.
     4        https://bugs.webkit.org/show_bug.cgi?id=165768
     5
     6        Reviewed by Saam Barati.
     7
     8        The lexical scope in "m_lexicalScopeStack" here refers to a pair of { } in the
     9        source code that bounds the scope of variables.
     10
     11        There are 4 places in the code where we call m_symbolTableStack.append() to
     12        append a new stack entry.  In only 3 of the 4 cases, a symbol table is provided
     13        in the new stack entry.  In all 4 cases, a scope register is provided in the new
     14        stack entry.
     15
     16        Also, 3 of the 4 functions that appends an entry to this stack are named:
     17        1. initializeVarLexicalEnvironment()
     18        2. pushLexicalScopeInternal()
     19        3. emitPushWithScope()
     20
     21        The 4th function is the BytecodeGenerator constructor where it pushes the scope
     22        for a module environment.
     23
     24        Based on these details, m_lexicalScopeStack is a better name for this stack than
     25        m_symbolTableStack.
     26
     27        * bytecompiler/BytecodeGenerator.cpp:
     28        (JSC::BytecodeGenerator::BytecodeGenerator):
     29        (JSC::BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded):
     30        (JSC::BytecodeGenerator::initializeVarLexicalEnvironment):
     31        (JSC::BytecodeGenerator::pushLexicalScopeInternal):
     32        (JSC::BytecodeGenerator::initializeBlockScopedFunctions):
     33        (JSC::BytecodeGenerator::hoistSloppyModeFunctionIfNecessary):
     34        (JSC::BytecodeGenerator::popLexicalScopeInternal):
     35        (JSC::BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration):
     36        (JSC::BytecodeGenerator::variable):
     37        (JSC::BytecodeGenerator::resolveType):
     38        (JSC::BytecodeGenerator::emitResolveScope):
     39        (JSC::BytecodeGenerator::emitPushWithScope):
     40        (JSC::BytecodeGenerator::emitPopWithScope):
     41        (JSC::BytecodeGenerator::pushFinallyContext):
     42        (JSC::BytecodeGenerator::pushIteratorCloseContext):
     43        (JSC::BytecodeGenerator::emitComplexPopScopes):
     44        (JSC::BytecodeGenerator::popTryAndEmitCatch):
     45        (JSC::BytecodeGenerator::emitPushFunctionNameScope):
     46        * bytecompiler/BytecodeGenerator.h:
     47
    1482016-12-12  Saam Barati  <sbarati@apple.com>
    249
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r208953 r209723  
    870870    pushTDZVariables(lexicalVariables, TDZCheckOptimization::Optimize, TDZRequirement::UnderTDZ);
    871871    bool isWithScope = false;
    872     m_symbolTableStack.append(SymbolTableStackEntry { moduleEnvironmentSymbolTable, m_topMostScope, isWithScope, constantSymbolTable->index() });
     872    m_lexicalScopeStack.append({ moduleEnvironmentSymbolTable, m_topMostScope, isWithScope, constantSymbolTable->index() });
    873873    emitPrefillStackTDZVariables(lexicalVariables, moduleEnvironmentSymbolTable);
    874874
     
    10741074
    10751075    if (environment.size() > 0) {
    1076         size_t size = m_symbolTableStack.size();
     1076        size_t size = m_lexicalScopeStack.size();
    10771077        pushLexicalScopeInternal(environment, TDZCheckOptimization::Optimize, NestedScopeType::IsNotNested, nullptr, TDZRequirement::UnderTDZ, ScopeType::LetConstScope, ScopeRegisterType::Block);
    10781078
    1079         ASSERT_UNUSED(size, m_symbolTableStack.size() == size + 1);
    1080 
    1081         m_arrowFunctionContextLexicalEnvironmentRegister = m_symbolTableStack.last().m_scope;
     1079        ASSERT_UNUSED(size, m_lexicalScopeStack.size() == size + 1);
     1080
     1081        m_arrowFunctionContextLexicalEnvironmentRegister = m_lexicalScopeStack.last().m_scope;
    10821082    }
    10831083}
     
    11251125    }
    11261126    bool isWithScope = false;
    1127     m_symbolTableStack.append(SymbolTableStackEntry{ functionSymbolTable, m_lexicalEnvironmentRegister, isWithScope, symbolTableConstantIndex });
    1128     m_varScopeSymbolTableIndex = m_symbolTableStack.size() - 1;
     1127    m_lexicalScopeStack.append({ functionSymbolTable, m_lexicalEnvironmentRegister, isWithScope, symbolTableConstantIndex });
     1128    m_varScopeLexicalScopeStackIndex = m_lexicalScopeStack.size() - 1;
    11291129}
    11301130
     
    20722072
    20732073    bool isWithScope = false;
    2074     m_symbolTableStack.append(SymbolTableStackEntry{ symbolTable, newScope, isWithScope, symbolTableConstantIndex });
     2074    m_lexicalScopeStack.append({ symbolTable, newScope, isWithScope, symbolTableConstantIndex });
    20752075    pushTDZVariables(environment, tdzCheckOptimization, tdzRequirement);
    20762076
     
    21152115        return;
    21162116
    2117     SymbolTable* symbolTable = m_symbolTableStack.last().m_symbolTable;
    2118     RegisterID* scope = m_symbolTableStack.last().m_scope;
     2117    SymbolTable* symbolTable = m_lexicalScopeStack.last().m_symbolTable;
     2118    RegisterID* scope = m_lexicalScopeStack.last().m_scope;
    21192119    RefPtr<RegisterID> temp = newTemporary();
    21202120    int symbolTableIndex = constantSymbolTable ? constantSymbolTable->index() : 0;
     
    21452145        }
    21462146       
    2147         ASSERT(m_varScopeSymbolTableIndex);
    2148         ASSERT(*m_varScopeSymbolTableIndex < m_symbolTableStack.size());
    2149         SymbolTableStackEntry& varScope = m_symbolTableStack[*m_varScopeSymbolTableIndex];
     2147        ASSERT(m_varScopeLexicalScopeStackIndex);
     2148        ASSERT(*m_varScopeLexicalScopeStackIndex < m_lexicalScopeStack.size());
     2149        auto& varScope = m_lexicalScopeStack[*m_varScopeLexicalScopeStackIndex];
    21502150        SymbolTable* varSymbolTable = varScope.m_symbolTable;
    21512151        ASSERT(varSymbolTable->scopeType() == SymbolTable::ScopeType::VarScope);
     
    21732173        environment.markAllVariablesAsCaptured();
    21742174
    2175     SymbolTableStackEntry stackEntry = m_symbolTableStack.takeLast();
     2175    auto stackEntry = m_lexicalScopeStack.takeLast();
    21762176    SymbolTable* symbolTable = stackEntry.m_symbolTable;
    21772177    bool hasCapturedVariables = false;
     
    22182218    // gets a new activation.
    22192219
    2220     SymbolTableStackEntry stackEntry = m_symbolTableStack.last();
     2220    auto stackEntry = m_lexicalScopeStack.last();
    22212221    SymbolTable* symbolTable = stackEntry.m_symbolTable;
    22222222    RegisterID* loopScope = stackEntry.m_scope;
     
    22972297    //     }
    22982298    // }
    2299     for (unsigned i = m_symbolTableStack.size(); i--; ) {
    2300         SymbolTableStackEntry& stackEntry = m_symbolTableStack[i];
     2299    for (unsigned i = m_lexicalScopeStack.size(); i--; ) {
     2300        auto& stackEntry = m_lexicalScopeStack[i];
    23012301        if (stackEntry.m_isWithScope)
    23022302            return Variable(property);
     
    23932393ResolveType BytecodeGenerator::resolveType()
    23942394{
    2395     for (unsigned i = m_symbolTableStack.size(); i--; ) {
    2396         if (m_symbolTableStack[i].m_isWithScope)
     2395    for (unsigned i = m_lexicalScopeStack.size(); i--; ) {
     2396        if (m_lexicalScopeStack[i].m_isWithScope)
    23972397            return Dynamic;
    2398         if (m_usesNonStrictEval && m_symbolTableStack[i].m_symbolTable->scopeType() == SymbolTable::ScopeType::FunctionNameScope) {
     2398        if (m_usesNonStrictEval && m_lexicalScopeStack[i].m_symbolTable->scopeType() == SymbolTable::ScopeType::FunctionNameScope) {
    23992399            // We never want to assign to a FunctionNameScope. Returning Dynamic here achieves this goal.
    24002400            // If we aren't in non-strict eval mode, then NodesCodeGen needs to take care not to emit
     
    24252425        // requires weird things because it is a shameful pile of nonsense, but block scoping would make
    24262426        // that code sensible and obviate the need for us to do bad things.
    2427         for (unsigned i = m_symbolTableStack.size(); i--; ) {
    2428             SymbolTableStackEntry& stackEntry = m_symbolTableStack[i];
     2427        for (unsigned i = m_lexicalScopeStack.size(); i--; ) {
     2428            auto& stackEntry = m_lexicalScopeStack[i];
    24292429            // We should not resolve a variable to VarKind::Scope if a "with" scope lies in between the current
    24302430            // scope and the resolved scope.
     
    36103610
    36113611    emitMove(scopeRegister(), newScope);
    3612     m_symbolTableStack.append(SymbolTableStackEntry{ nullptr, newScope, true, 0 });
     3612    m_lexicalScopeStack.append({ nullptr, newScope, true, 0 });
    36133613
    36143614    return newScope;
     
    36333633    emitPopScope(scopeRegister(), scopeRegister());
    36343634    popScopedControlFlowContext();
    3635     SymbolTableStackEntry stackEntry = m_symbolTableStack.takeLast();
     3635    auto stackEntry = m_lexicalScopeStack.takeLast();
    36363636    stackEntry.m_scope->deref();
    36373637    RELEASE_ASSERT(stackEntry.m_isWithScope);
     
    36913691        static_cast<unsigned>(m_tryContextStack.size()),
    36923692        static_cast<unsigned>(m_labelScopes.size()),
    3693         static_cast<unsigned>(m_symbolTableStack.size()),
     3693        static_cast<unsigned>(m_lexicalScopeStack.size()),
    36943694        m_finallyDepth,
    36953695        m_localScopeDepth
     
    37173717        static_cast<unsigned>(m_tryContextStack.size()),
    37183718        static_cast<unsigned>(m_labelScopes.size()),
    3719         static_cast<unsigned>(m_symbolTableStack.size()),
     3719        static_cast<unsigned>(m_lexicalScopeStack.size()),
    37203720        m_finallyDepth,
    37213721        m_localScopeDepth
     
    38793879        Vector<RefPtr<ForInContext>> savedForInContextStack;
    38803880        Vector<TryContext> poppedTryContexts;
    3881         Vector<SymbolTableStackEntry> savedSymbolTableStack;
     3881        Vector<LexicalScopeStackEntry> savedLexicalScopeStack;
    38823882        LabelScopeStore savedLabelScopes;
    38833883        while (topScope > bottomScope && topScope->isFinallyBlock) {
     
    38923892            bool flipTries = finallyContext.tryContextStackSize != m_tryContextStack.size();
    38933893            bool flipLabelScopes = finallyContext.labelScopesSize != m_labelScopes.size();
    3894             bool flipSymbolTableStack = finallyContext.symbolTableStackSize != m_symbolTableStack.size();
     3894            bool flipLexicalScopeStack = finallyContext.lexicalScopeStackSize != m_lexicalScopeStack.size();
    38953895            int topScopeIndex = -1;
    38963896            int bottomScopeIndex = -1;
     
    39263926                    m_labelScopes.removeLast();
    39273927            }
    3928             if (flipSymbolTableStack) {
    3929                 savedSymbolTableStack = m_symbolTableStack;
    3930                 m_symbolTableStack.shrink(finallyContext.symbolTableStackSize);
     3928            if (flipLexicalScopeStack) {
     3929                savedLexicalScopeStack = m_lexicalScopeStack;
     3930                m_lexicalScopeStack.shrink(finallyContext.lexicalScopeStackSize);
    39313931            }
    39323932            int savedFinallyDepth = m_finallyDepth;
     
    39673967            if (flipLabelScopes)
    39683968                m_labelScopes = savedLabelScopes;
    3969             if (flipSymbolTableStack)
    3970                 m_symbolTableStack = savedSymbolTableStack;
     3969            if (flipLexicalScopeStack)
     3970                m_lexicalScopeStack = savedLexicalScopeStack;
    39713971            m_finallyDepth = savedFinallyDepth;
    39723972            m_localScopeDepth = savedDynamicScopeDepth;
     
    40364036
    40374037    bool foundLocalScope = false;
    4038     for (unsigned i = m_symbolTableStack.size(); i--; ) {
     4038    for (unsigned i = m_lexicalScopeStack.size(); i--; ) {
    40394039        // Note that if we don't find a local scope in the current function/program,
    40404040        // we must grab the outer-most scope of this bytecode generation.
    4041         if (m_symbolTableStack[i].m_scope) {
     4041        if (m_lexicalScopeStack[i].m_scope) {
    40424042            foundLocalScope = true;
    4043             emitMove(scopeRegister(), m_symbolTableStack[i].m_scope);
     4043            emitMove(scopeRegister(), m_lexicalScopeStack[i].m_scope);
    40444044            break;
    40454045        }
     
    41204120    ASSERT_UNUSED(numVars, m_codeBlock->m_numVars == static_cast<int>(numVars + 1)); // Should have only created one new "var" for the function name scope.
    41214121    bool shouldTreatAsLexicalVariable = isStrictMode();
    4122     Variable functionVar = variableForLocalEntry(property, m_symbolTableStack.last().m_symbolTable->get(NoLockingNecessary, property.impl()), m_symbolTableStack.last().m_symbolTableConstantIndex, shouldTreatAsLexicalVariable);
    4123     emitPutToScope(m_symbolTableStack.last().m_scope, functionVar, callee, ThrowIfNotFound, InitializationMode::NotInitialization);
     4122    Variable functionVar = variableForLocalEntry(property, m_lexicalScopeStack.last().m_symbolTable->get(NoLockingNecessary, property.impl()), m_lexicalScopeStack.last().m_symbolTableConstantIndex, shouldTreatAsLexicalVariable);
     4123    emitPutToScope(m_lexicalScopeStack.last().m_scope, functionVar, callee, ThrowIfNotFound, InitializationMode::NotInitialization);
    41244124}
    41254125
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r209632 r209723  
    9090        unsigned tryContextStackSize;
    9191        unsigned labelScopesSize;
    92         unsigned symbolTableStackSize;
     92        unsigned lexicalScopeStackSize;
    9393        int finallyDepth;
    9494        int dynamicScopeDepth;
     
    897897        bool m_shouldEmitDebugHooks;
    898898
    899         struct SymbolTableStackEntry {
     899        struct LexicalScopeStackEntry {
    900900            SymbolTable* m_symbolTable;
    901901            RegisterID* m_scope;
     
    903903            int m_symbolTableConstantIndex;
    904904        };
    905         Vector<SymbolTableStackEntry> m_symbolTableStack;
     905        Vector<LexicalScopeStackEntry> m_lexicalScopeStack;
    906906        enum class TDZNecessityLevel {
    907907            NotNeeded,
     
    911911        typedef HashMap<RefPtr<UniquedStringImpl>, TDZNecessityLevel, IdentifierRepHash> TDZMap;
    912912        Vector<TDZMap> m_TDZStack;
    913         std::optional<size_t> m_varScopeSymbolTableIndex;
     913        std::optional<size_t> m_varScopeLexicalScopeStackIndex;
    914914        void pushTDZVariables(const VariableEnvironment&, TDZCheckOptimization, TDZRequirement);
    915915
Note: See TracChangeset for help on using the changeset viewer.