Skip to content

Commit

Permalink
Call stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Nov 18, 2023
1 parent 628f11b commit f348460
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Codec/Archive/Tar/Index/IntTrie.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import Data.IntMap.Strict (IntMap)
import Data.List hiding (lookup, insert)
import Data.Function (on)

import GHC.Stack

-- | A compact mapping from sequences of nats to nats.
--
-- NOTE: The tries in this module have values /only/ at the leaves (which
Expand Down Expand Up @@ -165,10 +167,10 @@ lookup trie@(IntTrie arr) = go 0
where mid = (a + b) `div` 2


enumToWord32 :: Enum n => n -> Word32
enumToWord32 :: (HasCallStack, Enum n) => n -> Word32
enumToWord32 = fromIntegral . fromEnum

word32ToEnum :: Enum n => Word32 -> n
word32ToEnum :: (HasCallStack, Enum n) => Word32 -> n
word32ToEnum = toEnum . fromIntegral


Expand All @@ -186,7 +188,7 @@ data TrieNode k v = TrieLeaf {-# UNPACK #-} !Word32
empty :: IntTrieBuilder k v
empty = IntTrieBuilder IntMap.empty

insert :: (Enum k, Enum v) => [k] -> v
insert :: (HasCallStack, Enum k, Enum v) => [k] -> v
-> IntTrieBuilder k v -> IntTrieBuilder k v
insert [] _v t = t
insert (k:ks) v t = insertTrie (fromEnum k) (map fromEnum ks) (enumToWord32 v) t
Expand Down Expand Up @@ -224,7 +226,7 @@ finalise trie =
A.listArray (0, fromIntegral (flatTrieLength trie) - 1)
(flattenTrie trie)

unfinalise :: (Enum k, Enum v) => IntTrie k v -> IntTrieBuilder k v
unfinalise :: (HasCallStack, Enum k, Enum v) => IntTrie k v -> IntTrieBuilder k v
unfinalise trie =
go (completionsFrom trie 0)
where
Expand Down
6 changes: 4 additions & 2 deletions Codec/Archive/Tar/Index/StringTable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import qualified Data.ByteString.Lazy as LBS
import Data.ByteString.Builder as BS
import Data.ByteString.Builder.Extra as BS (byteStringCopy)

import GHC.Stack

-- | An efficient mapping from strings to a dense set of integers.
--
data StringTable id = StringTable
Expand Down Expand Up @@ -84,7 +86,7 @@ index' bs offsets i = BS.unsafeTake len . BS.unsafeDrop start $ bs

-- | Given the index of a string in the table, return the string.
--
index :: Enum id => StringTable id -> id -> BS.ByteString
index :: (HasCallStack, Enum id) => StringTable id -> id -> BS.ByteString
index (StringTable bs offsets _ids ixs) =
index' bs offsets . (ixs !) . fromIntegral . fromEnum

Expand Down Expand Up @@ -116,7 +118,7 @@ insert str builder@(StringTableBuilder smap nextid) =
inserts :: Enum id => [BS.ByteString] -> StringTableBuilder id -> (StringTableBuilder id, [id])
inserts bss builder = mapAccumL (flip insert) builder bss

finalise :: Enum id => StringTableBuilder id -> StringTable id
finalise :: (HasCallStack, Enum id) => StringTableBuilder id -> StringTable id
finalise (StringTableBuilder smap _) =
(StringTable strs offsets ids ixs)
where
Expand Down

0 comments on commit f348460

Please sign in to comment.