https://github.com/dmwit/encoding/pull/11 From ce27249d4260c7eb3f514c95d5edd762804dd4f3 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sat, 29 Aug 2020 13:52:33 +0100 Subject: [PATCH] Data/Map/Static/Builder.hs: avoid shiftL with negative offset On ghc-8.8 building `encoding` fails as: ``` Preprocessing library for encoding-0.8.5.. arithmetic overflow ``` This happens because `findSplitSize` can't handle small values, like `findSplitSize 1` and calls `shiftL` with negative value, which is forbdden: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Bits.html#v:shiftL Work it around by always passing non-negative offset. Signed-off-by: Sergei Trofimovich --- Data/Map/Static/Builder.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Data/Map/Static/Builder.hs b/Data/Map/Static/Builder.hs index 486e19c..61851cd 100644 --- a/Data/Map/Static/Builder.hs +++ b/Data/Map/Static/Builder.hs @@ -37,6 +37,6 @@ treeDepth sz = find' [0..] findSplitSize :: Int -> Int findSplitSize len = let depth = treeDepth len free = (maxSize depth) - len - in if free <= (1 `shiftL` (depth - 2)) + in if 2 * free <= (1 `shiftL` (depth - 1)) then maxSize (depth - 1) else len - (maxSize (depth - 2)) - 1 -- 2.28.0