Skip to content

Commit 54a31c6

Browse files
committed
Fix failure to initialize stack nested func parent pointer. When a fully compiled function is nested inside a redeferred function, we can quit byte code generation early for the nested function. But don't do so until its stack nested function parent pointer has been initialized (if necessary).
1 parent b23e336 commit 54a31c6

1 file changed

Lines changed: 35 additions & 35 deletions

File tree

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,14 +3008,43 @@ void ByteCodeGenerator::EmitOneFunction(ParseNode *pnode)
30083008
// so they have pointers to the stub sub-trees they need.)
30093009
byteCodeFunction->SetDeferredStubs(nullptr);
30103010

3011-
if (byteCodeFunction->GetByteCode() != nullptr)
3012-
{
3013-
// Previously compiled function nested within a re-deferred and re-compiled function.
3014-
return;
3015-
}
3016-
30173011
try
30183012
{
3013+
if (!funcInfo->IsGlobalFunction())
3014+
{
3015+
// Note: Do not set the stack nested func flag if the function has been redeferred and recompiled.
3016+
// In that case the flag already has the value we want.
3017+
if (CanStackNestedFunc(funcInfo, true) && byteCodeFunction->GetCompileCount() == 0)
3018+
{
3019+
#if DBG
3020+
byteCodeFunction->SetCanDoStackNestedFunc();
3021+
#endif
3022+
if (funcInfo->root->sxFnc.astSize <= PnFnc::MaxStackClosureAST)
3023+
{
3024+
byteCodeFunction->SetStackNestedFunc(true);
3025+
}
3026+
}
3027+
}
3028+
3029+
if (byteCodeFunction->DoStackNestedFunc())
3030+
{
3031+
uint nestedCount = byteCodeFunction->GetNestedCount();
3032+
for (uint i = 0; i < nestedCount; i++)
3033+
{
3034+
Js::FunctionProxy * nested = byteCodeFunction->GetNestedFunctionProxy(i);
3035+
if (nested->IsFunctionBody())
3036+
{
3037+
nested->GetFunctionBody()->SetStackNestedFuncParent(byteCodeFunction->GetFunctionInfo());
3038+
}
3039+
}
3040+
}
3041+
3042+
if (byteCodeFunction->GetByteCode() != nullptr)
3043+
{
3044+
// Previously compiled function nested within a re-deferred and re-compiled function.
3045+
return;
3046+
}
3047+
30193048
// Bug : 301517
30203049
// In the debug mode the hasOnlyThis optimization needs to be disabled, since user can break in this function
30213050
// and do operation on 'this' and its property, which may not be defined yet.
@@ -3059,22 +3088,6 @@ void ByteCodeGenerator::EmitOneFunction(ParseNode *pnode)
30593088
}
30603089
}
30613090

3062-
if (!funcInfo->IsGlobalFunction())
3063-
{
3064-
// Note: Do not set the stack nested func flag if the function has been redeferred and recompiled.
3065-
// In that case the flag already has the value we want.
3066-
if (CanStackNestedFunc(funcInfo, true) && byteCodeFunction->GetCompileCount() == 0)
3067-
{
3068-
#if DBG
3069-
byteCodeFunction->SetCanDoStackNestedFunc();
3070-
#endif
3071-
if (funcInfo->root->sxFnc.astSize <= PnFnc::MaxStackClosureAST)
3072-
{
3073-
byteCodeFunction->SetStackNestedFunc(true);
3074-
}
3075-
}
3076-
}
3077-
30783091
InitScopeSlotArray(funcInfo);
30793092
FinalizeRegisters(funcInfo, byteCodeFunction);
30803093
DebugOnly(Js::RegSlot firstTmpReg = funcInfo->varRegsCount);
@@ -3238,19 +3251,6 @@ void ByteCodeGenerator::EmitOneFunction(ParseNode *pnode)
32383251
}
32393252
}
32403253

3241-
if (byteCodeFunction->DoStackNestedFunc())
3242-
{
3243-
uint nestedCount = byteCodeFunction->GetNestedCount();
3244-
for (uint i = 0; i < nestedCount; i++)
3245-
{
3246-
Js::FunctionProxy * nested = byteCodeFunction->GetNestedFunctionProxy(i);
3247-
if (nested->IsFunctionBody())
3248-
{
3249-
nested->GetFunctionBody()->SetStackNestedFuncParent(byteCodeFunction->GetFunctionInfo());
3250-
}
3251-
}
3252-
}
3253-
32543254
if (funcInfo->IsGlobalFunction())
32553255
{
32563256
EnsureNoRedeclarations(pnode->sxFnc.pnodeScopes, funcInfo);

0 commit comments

Comments
 (0)