Skip to content

Commit 2109d5d

Browse files
authored
fix parsing table cache bug (#17816)
1 parent 69fa88b commit 2109d5d

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/Compiler/Facilities/prim-parsing.fs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ module internal Implementation =
151151
//-------------------------------------------------------------------------
152152
// Read the tables written by FSYACC.
153153

154-
type AssocTable(elemTab: uint16[], offsetTab: uint16[], cache: int[], cacheSize: int) =
154+
type AssocTable(elemTab: uint16[], offsetTab: uint16[], cache: int[]) =
155+
156+
do Array.fill cache 0 cache.Length -1
157+
let cacheSize = cache.Length / 2
155158

156159
member t.ReadAssoc(minElemNum, maxElemNum, defaultValueOfAssoc, keyToFind) =
157160
// do a binary chop on the table
@@ -273,13 +276,8 @@ module internal Implementation =
273276
let lhsPos = (Array.zeroCreate 2: Position[])
274277
let reductions = tables.reductions
275278
let cacheSize = 7919 // the 1000'th prime
276-
// Use a simpler hash table with faster lookup, but only one
277-
// hash bucket per key.
278279
let actionTableCache = ArrayPool<int>.Shared.Rent(cacheSize * 2)
279280
let gotoTableCache = ArrayPool<int>.Shared.Rent(cacheSize * 2)
280-
// Clear the arrays since ArrayPool does not
281-
Array.Clear(actionTableCache, 0, actionTableCache.Length)
282-
Array.Clear(gotoTableCache, 0, gotoTableCache.Length)
283281

284282
use _cacheDisposal =
285283
{ new IDisposable with
@@ -289,10 +287,10 @@ module internal Implementation =
289287
}
290288

291289
let actionTable =
292-
AssocTable(tables.actionTableElements, tables.actionTableRowOffsets, actionTableCache, cacheSize)
290+
AssocTable(tables.actionTableElements, tables.actionTableRowOffsets, actionTableCache)
293291

294292
let gotoTable =
295-
AssocTable(tables.gotos, tables.sparseGotoTableRowOffsets, gotoTableCache, cacheSize)
293+
AssocTable(tables.gotos, tables.sparseGotoTableRowOffsets, gotoTableCache)
296294

297295
let stateToProdIdxsTable =
298296
IdxToIdxListTable(tables.stateToProdIdxsTableElements, tables.stateToProdIdxsTableRowOffsets)

0 commit comments

Comments
 (0)