Skip to content

Commit f8307d2

Browse files
committed
[MERGE chakra-core#3643 @pleath] Clean up several unused/ineffectual flags in FE structures.
Merge pull request chakra-core#3643 from pleath:pidcleanup Delete code that exposed more redeferral candidates in RS2 but is not needed now. Stop creating a node and scope to hold the name of a function expression if we're parsing an arrow function.
2 parents 6a84cc4 + 5383485 commit f8307d2

6 files changed

Lines changed: 15 additions & 130 deletions

File tree

lib/Parser/Hash.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@ enum
3131
fidKwdRsvd = 0x0001, // the keyword is a reserved word
3232
fidKwdFutRsvd = 0x0002, // a future reserved word, but only in strict mode
3333

34-
// Flags to identify tracked aliases of "eval"
35-
fidEval = 0x0008,
36-
// Flags to identify tracked aliases of "let"
37-
fidLetOrConst = 0x0010, // ID has previously been used in a block-scoped declaration
38-
39-
// This flag is used by the Parser CountDcls and FillDcls methods.
40-
// CountDcls sets the bit as it walks through the var decls so that
41-
// it can skip duplicates. FillDcls clears the bit as it walks through
42-
// again to skip duplicates.
43-
fidGlobalDcl = 0x2000,
44-
45-
fidUsed = 0x4000, // name referenced by source code
46-
4734
fidModuleExport = 0x8000 // name is module export
4835
};
4936

@@ -314,12 +301,6 @@ struct Ident
314301
Js::PropertyId GetPropertyId() const { return m_propertyId; }
315302
void SetPropertyId(Js::PropertyId id) { m_propertyId = id; }
316303

317-
void SetIsEval() { m_grfid |= fidEval; }
318-
BOOL GetIsEval() const { return m_grfid & fidEval; }
319-
320-
void SetIsLetOrConst() { m_grfid |= fidLetOrConst; }
321-
BOOL GetIsLetOrConst() const { return m_grfid & fidLetOrConst; }
322-
323304
void SetIsModuleExport() { m_grfid |= fidModuleExport; }
324305
BOOL GetIsModuleExport() const { return m_grfid & fidModuleExport; }
325306

lib/Parser/Parse.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -730,31 +730,25 @@ ParseNodePtr Parser::CreateNodeT(charcount_t ichMin,charcount_t ichLim)
730730
return pnode;
731731
}
732732

733-
ParseNodePtr Parser::CreateDeclNode(OpCode nop, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl, bool *isRedecl)
733+
ParseNodePtr Parser::CreateDeclNode(OpCode nop, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl)
734734
{
735735
ParseNodePtr pnode = CreateNode(nop);
736736

737737
pnode->sxVar.InitDeclNode(pid, NULL);
738738

739739
if (symbolType != STUnknown)
740740
{
741-
pnode->sxVar.sym = AddDeclForPid(pnode, pid, symbolType, errorOnRedecl, isRedecl);
741+
pnode->sxVar.sym = AddDeclForPid(pnode, pid, symbolType, errorOnRedecl);
742742
}
743743

744744
return pnode;
745745
}
746746

747-
Symbol* Parser::AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl, bool *isRedecl)
747+
Symbol* Parser::AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl)
748748
{
749749
Assert(pnode->IsVarLetOrConst());
750750

751751
PidRefStack *refForUse = nullptr, *refForDecl = nullptr;
752-
753-
if (isRedecl)
754-
{
755-
*isRedecl = false;
756-
}
757-
758752
BlockInfoStack *blockInfo;
759753
bool fBlockScope = false;
760754
if (pnode->nop != knopVarDecl || symbolType == STFunction)
@@ -813,10 +807,6 @@ Symbol* Parser::AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbo
813807
Symbol *sym = refForDecl->GetSym();
814808
if (sym != nullptr)
815809
{
816-
if (isRedecl)
817-
{
818-
*isRedecl = true;
819-
}
820810
// Multiple declarations in the same scope. 3 possibilities: error, existing one wins, new one wins.
821811
switch (pnode->nop)
822812
{
@@ -1385,9 +1375,9 @@ ParseNodePtr Parser::CreateModuleImportDeclNode(IdentPtr localName)
13851375
return declNode;
13861376
}
13871377

1388-
ParseNodePtr Parser::CreateVarDeclNode(IdentPtr pid, SymbolType symbolType, bool autoArgumentsObject, ParseNodePtr pnodeFnc, bool errorOnRedecl, bool *isRedecl)
1378+
ParseNodePtr Parser::CreateVarDeclNode(IdentPtr pid, SymbolType symbolType, bool autoArgumentsObject, ParseNodePtr pnodeFnc, bool errorOnRedecl)
13891379
{
1390-
ParseNodePtr pnode = CreateDeclNode(knopVarDecl, pid, symbolType, errorOnRedecl, isRedecl);
1380+
ParseNodePtr pnode = CreateDeclNode(knopVarDecl, pid, symbolType, errorOnRedecl);
13911381

13921382
// Append the variable to the end of the current variable list.
13931383
AssertMem(m_ppnodeVar);
@@ -1413,7 +1403,6 @@ ParseNodePtr Parser::CreateBlockScopedDeclNode(IdentPtr pid, OpCode nodeType)
14131403
if (nullptr != pid)
14141404
{
14151405
AssertMem(pid);
1416-
pid->SetIsLetOrConst();
14171406
AddVarDeclToBlock(pnode);
14181407
CheckPidIsValid(pid);
14191408
}
@@ -4855,13 +4844,8 @@ ParseNodePtr Parser::ParseFncDecl(ushort flags, LPCOLESTR pNameHint, const bool
48554844
// level and we accomplish this by having each block scoped function
48564845
// declaration assign to both the block scoped "let" binding, as well
48574846
// as the function scoped "var" binding.
4858-
bool isRedecl = false;
4859-
ParseNodePtr vardecl = CreateVarDeclNode(pnodeFnc->sxFnc.pnodeName->sxVar.pid, STVariable, false, nullptr, false, &isRedecl);
4847+
ParseNodePtr vardecl = CreateVarDeclNode(pnodeFnc->sxFnc.pnodeName->sxVar.pid, STVariable, false, nullptr, false);
48604848
vardecl->sxVar.isBlockScopeFncDeclVar = true;
4861-
if (isRedecl)
4862-
{
4863-
vardecl->sxVar.sym->SetHasBlockFncVarRedecl();
4864-
}
48654849
}
48664850
}
48674851

@@ -4972,8 +4956,11 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
49724956
Scope *fncExprScope = nullptr;
49734957
if (!fDeclaration)
49744958
{
4975-
pnodeFncExprScope = StartParseBlock<buildAST>(PnodeBlockType::Function, ScopeType_FuncExpr);
4976-
fncExprScope = pnodeFncExprScope->sxBlock.scope;
4959+
if (!fLambda)
4960+
{
4961+
pnodeFncExprScope = StartParseBlock<buildAST>(PnodeBlockType::Function, ScopeType_FuncExpr);
4962+
fncExprScope = pnodeFncExprScope->sxBlock.scope;
4963+
}
49774964

49784965
// Function expression: push the new function onto the stack now so that the name (if any) will be
49794966
// local to the new function.

lib/Parser/Parse.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ class Parser
271271
ParseNodePtr CreateTempRef(ParseNode* tempNode);
272272

273273
ParseNodePtr CreateNode(OpCode nop) { return CreateNode(nop, m_pscan? m_pscan->IchMinTok() : 0); }
274-
ParseNodePtr CreateDeclNode(OpCode nop, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl = true, bool *isRedecl = nullptr);
275-
Symbol* AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl, bool *isRedecl = nullptr);
274+
ParseNodePtr CreateDeclNode(OpCode nop, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl = true);
275+
Symbol* AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl);
276276
void CheckRedeclarationErrorForBlockId(IdentPtr pid, int blockId);
277277
ParseNodePtr CreateNameNode(IdentPtr pid)
278278
{
@@ -325,7 +325,7 @@ class Parser
325325
void CheckPidIsValid(IdentPtr pid, bool autoArgumentsObject = false);
326326
void AddVarDeclToBlock(ParseNode *pnode);
327327
// Add a var declaration. Only use while parsing. Assumes m_ppnodeVar is pointing to the right place already
328-
ParseNodePtr CreateVarDeclNode(IdentPtr pid, SymbolType symbolType, bool autoArgumentsObject = false, ParseNodePtr pnodeFnc = NULL, bool checkReDecl = true, bool *isRedecl = nullptr);
328+
ParseNodePtr CreateVarDeclNode(IdentPtr pid, SymbolType symbolType, bool autoArgumentsObject = false, ParseNodePtr pnodeFnc = NULL, bool checkReDecl = true);
329329
// Add a var declaration, during parse tree rewriting. Will setup m_ppnodeVar for the given pnodeFnc
330330
ParseNodePtr AddVarDeclNode(IdentPtr pid, ParseNodePtr pnodeFnc);
331331
// Add a 'const' or 'let' declaration.

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ void EmitAssignmentToFuncName(ParseNode *pnodeFnc, ByteCodeGenerator *byteCodeGe
11821182
{
11831183
byteCodeGenerator->EmitPropStore(pnodeFnc->location, sym, nullptr, funcInfoParent);
11841184
}
1185-
else if (!sym->GetIsBlockVar() || sym->HasRealBlockVarRef() || sym->GetScope()->GetIsObject())
1185+
else
11861186
{
11871187
byteCodeGenerator->EmitLocalPropInit(pnodeFnc->location, sym, funcInfoParent);
11881188
}

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,64 +1648,6 @@ Symbol * ByteCodeGenerator::FindSymbol(Symbol **symRef, IdentPtr pid, bool forRe
16481648
}
16491649
}
16501650

1651-
bool didTransferToFncVarSym = false;
1652-
1653-
#pragma prefast(suppress:6237, "The right hand side condition does not have any side effects.")
1654-
if (PHASE_ON(Js::OptimizeBlockScopePhase, top->byteCodeFunction) &&
1655-
sym->GetIsBlockVar() &&
1656-
!sym->GetScope()->IsBlockInLoop() &&
1657-
sym->GetSymbolType() == STFunction)
1658-
{
1659-
// Try to use the var-scoped function binding in place of the lexically scoped one.
1660-
// This can be done if neither binding is explicitly assigned to, if there's no ambiguity in the binding
1661-
// (with/eval), and if the function is not declared in a loop. (Loops are problematic, because as the loop
1662-
// iterates different instances can be captured. If we always capture the var-scoped binding, then we
1663-
// always get the latest instance, when we should get the instance belonging to the iteration that captured it.)
1664-
if (sym->GetHasNonLocalReference())
1665-
{
1666-
if (!scope)
1667-
{
1668-
Js::PropertyId i;
1669-
scope = FindScopeForSym(symScope, nullptr, &i, top);
1670-
}
1671-
if (scope == symScope && !scope->GetIsObject())
1672-
{
1673-
Symbol *fncVarSym = sym->GetFuncScopeVarSym();
1674-
if (fncVarSym &&
1675-
!fncVarSym->HasBlockFncVarRedecl() &&
1676-
sym->GetAssignmentState() == NotAssigned &&
1677-
fncVarSym->GetAssignmentState() == NotAssigned)
1678-
{
1679-
// Make sure no dynamic scope intrudes between the two bindings.
1680-
bool foundDynamicScope = false;
1681-
for (Scope *tmpScope = symScope->GetEnclosingScope(); tmpScope != fncVarSym->GetScope(); tmpScope = tmpScope->GetEnclosingScope())
1682-
{
1683-
Assert(tmpScope);
1684-
if (tmpScope->GetIsDynamic())
1685-
{
1686-
foundDynamicScope = true;
1687-
break;
1688-
}
1689-
}
1690-
if (!foundDynamicScope)
1691-
{
1692-
didTransferToFncVarSym = true;
1693-
sym = fncVarSym;
1694-
symScope = sym->GetScope();
1695-
if (nonLocalRef)
1696-
{
1697-
sym->SetHasNonLocalReference();
1698-
}
1699-
}
1700-
}
1701-
}
1702-
}
1703-
}
1704-
if (!didTransferToFncVarSym)
1705-
{
1706-
sym->SetHasRealBlockVarRef();
1707-
}
1708-
17091651
// This may not be a non-local reference, but the symbol may still be accessed non-locally. ('with', e.g.)
17101652
// In that case, make sure we still process the symbol and its scope for closure capture.
17111653
if (nonLocalRef || sym->GetHasNonLocalReference())
@@ -3242,7 +3184,6 @@ void AddFunctionsToScope(ParseNodePtr scope, ByteCodeGenerator * byteCodeGenerat
32423184
sym->GetScope() != sym->GetScope()->GetFunc()->GetParamScope())
32433185
{
32443186
sym->SetIsBlockVar(true);
3245-
sym->SetHasRealBlockVarRef(true);
32463187
}
32473188
}
32483189
});

lib/Runtime/ByteCode/Symbol.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class Symbol
4040
BYTE isGlobalCatch : 1;
4141
BYTE isCommittedToSlot : 1;
4242
BYTE hasNonCommittedReference : 1;
43-
BYTE hasRealBlockVarRef : 1;
44-
BYTE hasBlockFncVarRedecl : 1;
4543
BYTE hasVisitedCapturingFunc : 1;
4644
BYTE isTrackedForDebugger : 1; // Whether the sym is tracked for debugger scope. This is fine because a sym can only be added to (not more than) one scope.
4745
BYTE isModuleExportStorage : 1; // If true, this symbol should be stored in the global scope export storage array.
@@ -75,8 +73,6 @@ class Symbol
7573
isGlobalCatch(false),
7674
isCommittedToSlot(false),
7775
hasNonCommittedReference(false),
78-
hasRealBlockVarRef(false),
79-
hasBlockFncVarRedecl(false),
8076
hasVisitedCapturingFunc(false),
8177
isTrackedForDebugger(false),
8278
isNonSimpleParameter(false),
@@ -316,26 +312,6 @@ class Symbol
316312
isUsed = is;
317313
}
318314

319-
bool HasRealBlockVarRef() const
320-
{
321-
return hasRealBlockVarRef;
322-
}
323-
324-
void SetHasRealBlockVarRef(bool has = true)
325-
{
326-
hasRealBlockVarRef = has;
327-
}
328-
329-
bool HasBlockFncVarRedecl() const
330-
{
331-
return hasBlockFncVarRedecl;
332-
}
333-
334-
void SetHasBlockFncVarRedecl(bool has = true)
335-
{
336-
hasBlockFncVarRedecl = has;
337-
}
338-
339315
AssignmentState GetAssignmentState() const
340316
{
341317
return assignmentState;

0 commit comments

Comments
 (0)