From 2109d5d1294ee36bd84ffa829c9729a2debedfdc Mon Sep 17 00:00:00 2001 From: Martin <29605222+Martin521@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:02:20 +0200 Subject: [PATCH] fix parsing table cache bug (#17816) --- src/Compiler/Facilities/prim-parsing.fs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Compiler/Facilities/prim-parsing.fs b/src/Compiler/Facilities/prim-parsing.fs index bb61e76e5f3..7fb0d7fca41 100644 --- a/src/Compiler/Facilities/prim-parsing.fs +++ b/src/Compiler/Facilities/prim-parsing.fs @@ -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 @@ -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.Shared.Rent(cacheSize * 2) let gotoTableCache = ArrayPool.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 @@ -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)