Changeset 209723 in webkit
- Timestamp:
- Dec 12, 2016, 1:03:49 PM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r209722 r209723 1 2016-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 1 48 2016-12-12 Saam Barati <sbarati@apple.com> 2 49 -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r208953 r209723 870 870 pushTDZVariables(lexicalVariables, TDZCheckOptimization::Optimize, TDZRequirement::UnderTDZ); 871 871 bool isWithScope = false; 872 m_ symbolTableStack.append(SymbolTableStackEntry{ moduleEnvironmentSymbolTable, m_topMostScope, isWithScope, constantSymbolTable->index() });872 m_lexicalScopeStack.append({ moduleEnvironmentSymbolTable, m_topMostScope, isWithScope, constantSymbolTable->index() }); 873 873 emitPrefillStackTDZVariables(lexicalVariables, moduleEnvironmentSymbolTable); 874 874 … … 1074 1074 1075 1075 if (environment.size() > 0) { 1076 size_t size = m_ symbolTableStack.size();1076 size_t size = m_lexicalScopeStack.size(); 1077 1077 pushLexicalScopeInternal(environment, TDZCheckOptimization::Optimize, NestedScopeType::IsNotNested, nullptr, TDZRequirement::UnderTDZ, ScopeType::LetConstScope, ScopeRegisterType::Block); 1078 1078 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; 1082 1082 } 1083 1083 } … … 1125 1125 } 1126 1126 bool isWithScope = false; 1127 m_ symbolTableStack.append(SymbolTableStackEntry{ functionSymbolTable, m_lexicalEnvironmentRegister, isWithScope, symbolTableConstantIndex });1128 m_varScope SymbolTableIndex = m_symbolTableStack.size() - 1;1127 m_lexicalScopeStack.append({ functionSymbolTable, m_lexicalEnvironmentRegister, isWithScope, symbolTableConstantIndex }); 1128 m_varScopeLexicalScopeStackIndex = m_lexicalScopeStack.size() - 1; 1129 1129 } 1130 1130 … … 2072 2072 2073 2073 bool isWithScope = false; 2074 m_ symbolTableStack.append(SymbolTableStackEntry{ symbolTable, newScope, isWithScope, symbolTableConstantIndex });2074 m_lexicalScopeStack.append({ symbolTable, newScope, isWithScope, symbolTableConstantIndex }); 2075 2075 pushTDZVariables(environment, tdzCheckOptimization, tdzRequirement); 2076 2076 … … 2115 2115 return; 2116 2116 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; 2119 2119 RefPtr<RegisterID> temp = newTemporary(); 2120 2120 int symbolTableIndex = constantSymbolTable ? constantSymbolTable->index() : 0; … … 2145 2145 } 2146 2146 2147 ASSERT(m_varScope SymbolTableIndex);2148 ASSERT(*m_varScope SymbolTableIndex < 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]; 2150 2150 SymbolTable* varSymbolTable = varScope.m_symbolTable; 2151 2151 ASSERT(varSymbolTable->scopeType() == SymbolTable::ScopeType::VarScope); … … 2173 2173 environment.markAllVariablesAsCaptured(); 2174 2174 2175 SymbolTableStackEntry stackEntry = m_symbolTableStack.takeLast();2175 auto stackEntry = m_lexicalScopeStack.takeLast(); 2176 2176 SymbolTable* symbolTable = stackEntry.m_symbolTable; 2177 2177 bool hasCapturedVariables = false; … … 2218 2218 // gets a new activation. 2219 2219 2220 SymbolTableStackEntry stackEntry = m_symbolTableStack.last();2220 auto stackEntry = m_lexicalScopeStack.last(); 2221 2221 SymbolTable* symbolTable = stackEntry.m_symbolTable; 2222 2222 RegisterID* loopScope = stackEntry.m_scope; … … 2297 2297 // } 2298 2298 // } 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]; 2301 2301 if (stackEntry.m_isWithScope) 2302 2302 return Variable(property); … … 2393 2393 ResolveType BytecodeGenerator::resolveType() 2394 2394 { 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) 2397 2397 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) { 2399 2399 // We never want to assign to a FunctionNameScope. Returning Dynamic here achieves this goal. 2400 2400 // If we aren't in non-strict eval mode, then NodesCodeGen needs to take care not to emit … … 2425 2425 // requires weird things because it is a shameful pile of nonsense, but block scoping would make 2426 2426 // 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]; 2429 2429 // We should not resolve a variable to VarKind::Scope if a "with" scope lies in between the current 2430 2430 // scope and the resolved scope. … … 3610 3610 3611 3611 emitMove(scopeRegister(), newScope); 3612 m_ symbolTableStack.append(SymbolTableStackEntry{ nullptr, newScope, true, 0 });3612 m_lexicalScopeStack.append({ nullptr, newScope, true, 0 }); 3613 3613 3614 3614 return newScope; … … 3633 3633 emitPopScope(scopeRegister(), scopeRegister()); 3634 3634 popScopedControlFlowContext(); 3635 SymbolTableStackEntry stackEntry = m_symbolTableStack.takeLast();3635 auto stackEntry = m_lexicalScopeStack.takeLast(); 3636 3636 stackEntry.m_scope->deref(); 3637 3637 RELEASE_ASSERT(stackEntry.m_isWithScope); … … 3691 3691 static_cast<unsigned>(m_tryContextStack.size()), 3692 3692 static_cast<unsigned>(m_labelScopes.size()), 3693 static_cast<unsigned>(m_ symbolTableStack.size()),3693 static_cast<unsigned>(m_lexicalScopeStack.size()), 3694 3694 m_finallyDepth, 3695 3695 m_localScopeDepth … … 3717 3717 static_cast<unsigned>(m_tryContextStack.size()), 3718 3718 static_cast<unsigned>(m_labelScopes.size()), 3719 static_cast<unsigned>(m_ symbolTableStack.size()),3719 static_cast<unsigned>(m_lexicalScopeStack.size()), 3720 3720 m_finallyDepth, 3721 3721 m_localScopeDepth … … 3879 3879 Vector<RefPtr<ForInContext>> savedForInContextStack; 3880 3880 Vector<TryContext> poppedTryContexts; 3881 Vector< SymbolTableStackEntry> savedSymbolTableStack;3881 Vector<LexicalScopeStackEntry> savedLexicalScopeStack; 3882 3882 LabelScopeStore savedLabelScopes; 3883 3883 while (topScope > bottomScope && topScope->isFinallyBlock) { … … 3892 3892 bool flipTries = finallyContext.tryContextStackSize != m_tryContextStack.size(); 3893 3893 bool flipLabelScopes = finallyContext.labelScopesSize != m_labelScopes.size(); 3894 bool flip SymbolTableStack = finallyContext.symbolTableStackSize != m_symbolTableStack.size();3894 bool flipLexicalScopeStack = finallyContext.lexicalScopeStackSize != m_lexicalScopeStack.size(); 3895 3895 int topScopeIndex = -1; 3896 3896 int bottomScopeIndex = -1; … … 3926 3926 m_labelScopes.removeLast(); 3927 3927 } 3928 if (flip SymbolTableStack) {3929 saved SymbolTableStack = m_symbolTableStack;3930 m_ symbolTableStack.shrink(finallyContext.symbolTableStackSize);3928 if (flipLexicalScopeStack) { 3929 savedLexicalScopeStack = m_lexicalScopeStack; 3930 m_lexicalScopeStack.shrink(finallyContext.lexicalScopeStackSize); 3931 3931 } 3932 3932 int savedFinallyDepth = m_finallyDepth; … … 3967 3967 if (flipLabelScopes) 3968 3968 m_labelScopes = savedLabelScopes; 3969 if (flip SymbolTableStack)3970 m_ symbolTableStack = savedSymbolTableStack;3969 if (flipLexicalScopeStack) 3970 m_lexicalScopeStack = savedLexicalScopeStack; 3971 3971 m_finallyDepth = savedFinallyDepth; 3972 3972 m_localScopeDepth = savedDynamicScopeDepth; … … 4036 4036 4037 4037 bool foundLocalScope = false; 4038 for (unsigned i = m_ symbolTableStack.size(); i--; ) {4038 for (unsigned i = m_lexicalScopeStack.size(); i--; ) { 4039 4039 // Note that if we don't find a local scope in the current function/program, 4040 4040 // 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) { 4042 4042 foundLocalScope = true; 4043 emitMove(scopeRegister(), m_ symbolTableStack[i].m_scope);4043 emitMove(scopeRegister(), m_lexicalScopeStack[i].m_scope); 4044 4044 break; 4045 4045 } … … 4120 4120 ASSERT_UNUSED(numVars, m_codeBlock->m_numVars == static_cast<int>(numVars + 1)); // Should have only created one new "var" for the function name scope. 4121 4121 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); 4124 4124 } 4125 4125 -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r209632 r209723 90 90 unsigned tryContextStackSize; 91 91 unsigned labelScopesSize; 92 unsigned symbolTableStackSize;92 unsigned lexicalScopeStackSize; 93 93 int finallyDepth; 94 94 int dynamicScopeDepth; … … 897 897 bool m_shouldEmitDebugHooks; 898 898 899 struct SymbolTableStackEntry {899 struct LexicalScopeStackEntry { 900 900 SymbolTable* m_symbolTable; 901 901 RegisterID* m_scope; … … 903 903 int m_symbolTableConstantIndex; 904 904 }; 905 Vector< SymbolTableStackEntry> m_symbolTableStack;905 Vector<LexicalScopeStackEntry> m_lexicalScopeStack; 906 906 enum class TDZNecessityLevel { 907 907 NotNeeded, … … 911 911 typedef HashMap<RefPtr<UniquedStringImpl>, TDZNecessityLevel, IdentifierRepHash> TDZMap; 912 912 Vector<TDZMap> m_TDZStack; 913 std::optional<size_t> m_varScope SymbolTableIndex;913 std::optional<size_t> m_varScopeLexicalScopeStackIndex; 914 914 void pushTDZVariables(const VariableEnvironment&, TDZCheckOptimization, TDZRequirement); 915 915
Note:
See TracChangeset
for help on using the changeset viewer.