Skip to content

Commit 81b227b

Browse files
committed
Cleanup: Better #ifdef around background parsing code
1 parent 0e29b86 commit 81b227b

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

lib/Parser/Parse.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ Parser::Parser(Js::ScriptContext* scriptContext, BOOL strictMode, PageAllocator
8383
{
8484
AssertMsg(size == sizeof(Parser), "verify conditionals affecting the size of Parser agree");
8585
Assert(scriptContext != nullptr);
86-
m_isInBackground = isBackground;
8786
m_phtbl = nullptr;
8887
m_pscan = nullptr;
8988
m_deferringAST = FALSE;
9089
m_stoppedDeferredParse = FALSE;
90+
#if ENABLE_BACKGROUND_PARSING
91+
m_isInBackground = isBackground;
9192
m_hasParallelJob = false;
9293
m_doingFastScan = false;
94+
#endif
9395
m_scriptContext = scriptContext;
9496
m_pCurrentAstSize = nullptr;
9597
m_arrayDepth = 0;
@@ -113,8 +115,6 @@ Parser::Parser(Js::ScriptContext* scriptContext, BOOL strictMode, PageAllocator
113115
m_length = 0;
114116
m_originalLength = 0;
115117
m_nextFunctionId = nullptr;
116-
m_errorCallback = nullptr;
117-
m_uncertainStructure = FALSE;
118118
m_reparsingLambdaParams = false;
119119
currBackgroundParseItem = nullptr;
120120
backgroundParseItems = nullptr;
@@ -142,9 +142,9 @@ Parser::~Parser(void)
142142
m_registeredRegexPatterns.Reset();
143143
}
144144

145+
#if ENABLE_BACKGROUND_PARSING
145146
if (this->m_hasParallelJob)
146147
{
147-
#if ENABLE_BACKGROUND_PARSING
148148
// Let the background threads know that they can decommit their arena pages.
149149
BackgroundParser *bgp = m_scriptContext->GetBackgroundParser();
150150
Assert(bgp);
@@ -158,8 +158,8 @@ Parser::~Parser(void)
158158
});
159159
Assert(result);
160160
}
161-
#endif
162161
}
162+
#endif
163163

164164
Release();
165165

@@ -409,9 +409,9 @@ HRESULT Parser::ParseSourceInternal(
409409
hr = pse->ProcessError(m_pscan, hr, pnodeBase);
410410
}
411411

412+
#if ENABLE_BACKGROUND_PARSING
412413
if (this->m_hasParallelJob)
413414
{
414-
#if ENABLE_BACKGROUND_PARSING
415415
///// Wait here for remaining jobs to finish. Then look for errors, do final const bindings.
416416
// pleath TODO: If there are remaining jobs, let the main thread help finish them.
417417
BackgroundParser *bgp = m_scriptContext->GetBackgroundParser();
@@ -440,8 +440,8 @@ HRESULT Parser::ParseSourceInternal(
440440
Parser *parser = item->GetParser();
441441
parser->FinishBackgroundPidRefs(item, this != parser);
442442
}
443-
#endif
444443
}
444+
#endif
445445

446446
// done with the scanner
447447
RELEASEPTR(m_pscan);
@@ -2993,7 +2993,7 @@ ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
29932993
m_pscan->Scan();
29942994

29952995
// If the token after the right paren is not => or if there was a newline between () and => this is a syntax error
2996-
if (!m_doingFastScan && (m_token.tk != tkDArrow || m_pscan->FHadNewLine()))
2996+
if (!IsDoingFastScan() && (m_token.tk != tkDArrow || m_pscan->FHadNewLine()))
29972997
{
29982998
Error(ERRsyntax);
29992999
}
@@ -3282,6 +3282,7 @@ LFunction :
32823282
}
32833283
break;
32843284

3285+
#if ENABLE_BACKGROUND_PARSING
32853286
case tkCASE:
32863287
{
32873288
if (!m_doingFastScan)
@@ -3301,6 +3302,7 @@ LFunction :
33013302
m_pscan->Scan();
33023303
ParseStatement<buildAST>();
33033304
break;
3305+
#endif
33043306

33053307
default:
33063308
LUnknown :
@@ -3341,17 +3343,20 @@ ParseNodePtr Parser::ParseRegExp()
33413343
{
33423344
ParseNodePtr pnode = nullptr;
33433345

3344-
if (buildAST || m_doingFastScan)
3346+
if (buildAST || IsDoingFastScan())
33453347
{
33463348
m_pscan->RescanRegExp();
33473349

3350+
#if ENABLE_BACKGROUND_PARSING
33483351
BOOL saveDeferringAST = this->m_deferringAST;
33493352
if (m_doingFastScan)
33503353
{
33513354
this->m_deferringAST = false;
33523355
}
3356+
#endif
33533357
pnode = CreateNodeWithScanner<knopRegExp>();
33543358
pnode->sxPid.regexPattern = m_token.GetRegex();
3359+
#if ENABLE_BACKGROUND_PARSING
33553360
if (m_doingFastScan)
33563361
{
33573362
this->m_deferringAST = saveDeferringAST;
@@ -3361,7 +3366,6 @@ ParseNodePtr Parser::ParseRegExp()
33613366
pnode = nullptr;
33623367
}
33633368
}
3364-
#if ENABLE_BACKGROUND_PARSING
33653369
else if (this->IsBackgroundParser())
33663370
{
33673371
Assert(pnode->sxPid.regexPattern == nullptr);
@@ -5023,12 +5027,14 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
50235027

50245028
bool isTopLevelDeferredFunc = false;
50255029

5030+
#if ENABLE_BACKGROUND_PARSING
50265031
struct AutoFastScanFlag {
50275032
bool savedDoingFastScan;
50285033
AutoFastScanFlag(Parser *parser) : m_parser(parser) { savedDoingFastScan = m_parser->m_doingFastScan; }
50295034
~AutoFastScanFlag() { m_parser->m_doingFastScan = savedDoingFastScan; }
50305035
Parser *m_parser;
50315036
} flag(this);
5037+
#endif
50325038

50335039
bool doParallel = false;
50345040
bool parallelJobStarted = false;
@@ -5057,7 +5063,8 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
50575063
// These are heuristic conditions that prohibit upfront deferral but not redeferral.
50585064
isTopLevelDeferredFunc = isTopLevelDeferredFunc && !isDeferredFnc &&
50595065
(!isLikelyIIFE || !topLevelStmt || PHASE_FORCE_RAW(Js::DeferParsePhase, m_sourceContextInfo->sourceContextId, pnodeFnc->sxFnc.functionId));
5060-
;
5066+
5067+
#if ENABLE_BACKGROUND_PARSING
50615068
if (!fLambda &&
50625069
!isDeferredFnc &&
50635070
!isLikelyIIFE &&
@@ -5067,7 +5074,7 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
50675074
!(this->m_parseType == ParseType_Deferred && this->m_functionBody && this->m_functionBody->GetScopeInfo() && !isTopLevelDeferredFunc))
50685075
{
50695076
doParallel = DoParallelParse(pnodeFnc);
5070-
#if ENABLE_BACKGROUND_PARSING
5077+
50715078
if (doParallel)
50725079
{
50735080
BackgroundParser *bgp = m_scriptContext->GetBackgroundParser();
@@ -5093,8 +5100,8 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
50935100
}
50945101
}
50955102
}
5096-
#endif
50975103
}
5104+
#endif
50985105
}
50995106

51005107
if (!doParallel)
@@ -10059,7 +10066,7 @@ ParseNodePtr Parser::ParseStatement()
1005910066
{
1006010067
// If we're doing a fast scan, we're not tracking labels, so we can't accurately do this analysis.
1006110068
// Let the thread that's doing the full parse detect the error, if there is one.
10062-
if (!this->m_doingFastScan)
10069+
if (!this->IsDoingFastScan())
1006310070
{
1006410071
// Unlabeled break or continue.
1006510072
if (buildAST)
@@ -11113,14 +11120,14 @@ ParseNodePtr Parser::Parse(LPCUTF8 pszSrc, size_t offset, size_t length, charcou
1111311120

1111411121
if (m_stoppedDeferredParse)
1111511122
{
11123+
#if ENABLE_BACKGROUND_PARSING
1111611124
if (this->m_hasParallelJob)
1111711125
{
11118-
#if ENABLE_BACKGROUND_PARSING
1111911126
BackgroundParser *bgp = static_cast<BackgroundParser*>(m_scriptContext->GetBackgroundParser());
1112011127
Assert(bgp);
1112111128
this->WaitForBackgroundJobs(bgp, pse);
11122-
#endif
1112311129
}
11130+
#endif
1112411131

1112511132
// Do any remaining bindings of globals referenced in non-deferred functions.
1112611133
if (pnodeGlobalEvalBlock)
@@ -11314,7 +11321,6 @@ void Parser::AddBackgroundParseItem(BackgroundParseItem *const item)
1131411321
}
1131511322
currBackgroundParseItem = item;
1131611323
}
11317-
#endif
1131811324

1131911325
void Parser::AddFastScannedRegExpNode(ParseNodePtr const pnode)
1132011326
{
@@ -11328,7 +11334,6 @@ void Parser::AddFastScannedRegExpNode(ParseNodePtr const pnode)
1132811334
fastScannedRegExpNodes->Append(pnode);
1132911335
}
1133011336

11331-
#if ENABLE_BACKGROUND_PARSING
1133211337
void Parser::AddBackgroundRegExpNode(ParseNodePtr const pnode)
1133311338
{
1133411339
Assert(IsBackgroundParser());

lib/Parser/Parse.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ struct BackgroundParseItem;
7171
struct PnClass;
7272
class HashTbl;
7373

74-
typedef void (*ParseErrorCallback)(void *data, charcount_t position, charcount_t length, HRESULT hr);
75-
7674
struct PidRefStack;
7775

7876
struct DeferredFunctionStub;
@@ -133,8 +131,13 @@ class Parser
133131
Js::ScriptContext* GetScriptContext() const { return m_scriptContext; }
134132
void ClearScriptContext() { m_scriptContext = nullptr; }
135133

134+
#if ENABLE_BACKGROUND_PARSING
136135
bool IsBackgroundParser() const { return m_isInBackground; }
137136
bool IsDoingFastScan() const { return m_doingFastScan; }
137+
#else
138+
bool IsBackgroundParser() const { return false; }
139+
bool IsDoingFastScan() const { return false; }
140+
#endif
138141

139142
static IdentPtr PidFromNode(ParseNodePtr pnode);
140143

@@ -194,11 +197,11 @@ class Parser
194197
Js::LocalFunctionId * m_nextFunctionId;
195198
SourceContextInfo* m_sourceContextInfo;
196199

197-
ParseErrorCallback m_errorCallback;
198-
void * m_errorCallbackData;
199-
BOOL m_uncertainStructure;
200+
#if ENABLE_BACKGROUND_PARSING
200201
bool m_hasParallelJob;
202+
bool m_isInBackground;
201203
bool m_doingFastScan;
204+
#endif
202205
int m_nextBlockId;
203206

204207
// RegexPattern objects created for literal regexes are recycler-allocated and need to be kept alive until the function body
@@ -308,9 +311,9 @@ class Parser
308311
charcount_t ichMin,charcount_t ichLim);
309312

310313
void PrepareScanner(bool fromExternal);
314+
#if ENABLE_BACKGROUND_PARSING
311315
void PrepareForBackgroundParse();
312316
void AddFastScannedRegExpNode(ParseNodePtr const pnode);
313-
#if ENABLE_BACKGROUND_PARSING
314317
void AddBackgroundRegExpNode(ParseNodePtr const pnode);
315318
void AddBackgroundParseItem(BackgroundParseItem *const item);
316319
void FinishBackgroundRegExpNodes();
@@ -373,8 +376,7 @@ class Parser
373376
ParseNodePtr * m_ppnodeScope; // function list tail
374377
ParseNodePtr * m_ppnodeExprScope; // function expression list tail
375378
ParseNodePtr * m_ppnodeVar; // variable list tail
376-
bool m_inDeferredNestedFunc; // true if parsing a function in deferred mode, nested within the current node
377-
bool m_isInBackground;
379+
bool m_inDeferredNestedFunc; // true if parsing a function in deferred mode, nested within the current node
378380
bool m_reparsingLambdaParams;
379381

380382
// This bool is used for deferring the shorthand initializer error ( {x = 1}) - as it is allowed in the destructuring grammar.

lib/Parser/Scan.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ void Scanner<EncodingPolicy>::SetText(EncodedCharPtr pszSrc, size_t offset, size
151151
m_DeferredParseFlags = ScanFlagNone;
152152
}
153153

154+
#if ENABLE_BACKGROUND_PARSING
154155
template <typename EncodingPolicy>
155156
void Scanner<EncodingPolicy>::PrepareForBackgroundParse(Js::ScriptContext *scriptContext)
156157
{
157158
scriptContext->GetThreadContext()->GetStandardChars((EncodedChar*)0);
158159
scriptContext->GetThreadContext()->GetStandardChars((char16*)0);
159160
}
161+
#endif
160162

161163
//-----------------------------------------------------------------------------
162164
// Number of code points from 'first' up to, but not including the next

lib/Parser/Scan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,9 @@ class Scanner : public IScanner, public EncodingPolicy
376376
tokens ScanNoKeywords();
377377
tokens ScanForcingPid();
378378
void SetText(EncodedCharPtr psz, size_t offset, size_t length, charcount_t characterOffset, ULONG grfscr, ULONG lineNumber = 0);
379+
#if ENABLE_BACKGROUND_PARSING
379380
void PrepareForBackgroundParse(Js::ScriptContext *scriptContext);
380-
381+
#endif
381382
enum ScanState
382383
{
383384
ScanStateNormal = 0,

0 commit comments

Comments
 (0)