Skip to content

Commit

Permalink
fix parsing table cache bug (#17816)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin521 authored Oct 8, 2024
1 parent 69fa88b commit 2109d5d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Compiler/Facilities/prim-parsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ module internal Implementation =
//-------------------------------------------------------------------------
// Read the tables written by FSYACC.

type AssocTable(elemTab: uint16[], offsetTab: uint16[], cache: int[], cacheSize: int) =
type AssocTable(elemTab: uint16[], offsetTab: uint16[], cache: int[]) =

do Array.fill cache 0 cache.Length -1
let cacheSize = cache.Length / 2

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

use _cacheDisposal =
{ new IDisposable with
Expand All @@ -289,10 +287,10 @@ module internal Implementation =
}

let actionTable =
AssocTable(tables.actionTableElements, tables.actionTableRowOffsets, actionTableCache, cacheSize)
AssocTable(tables.actionTableElements, tables.actionTableRowOffsets, actionTableCache)

let gotoTable =
AssocTable(tables.gotos, tables.sparseGotoTableRowOffsets, gotoTableCache, cacheSize)
AssocTable(tables.gotos, tables.sparseGotoTableRowOffsets, gotoTableCache)

let stateToProdIdxsTable =
IdxToIdxListTable(tables.stateToProdIdxsTableElements, tables.stateToProdIdxsTableRowOffsets)
Expand Down

0 comments on commit 2109d5d

Please sign in to comment.