{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
module Ouroboros.Consensus.Storage.ImmutableDB.Chunks.Internal (
ChunkInfo (..)
, chunkInfoSupportsEBBs
, simpleChunkInfo
, singleChunkInfo
, ChunkNo (..)
, chunkNoFromInt
, chunkNoToInt
, chunksBetween
, countChunks
, firstChunkNo
, nextChunkNo
, prevChunkNo
, unsafeChunkNoToEpochNo
, unsafeEpochNoToChunkNo
, ChunkSize (..)
, getChunkSize
, RelativeSlot (..)
, assertRelativeSlotInChunk
, compareRelativeSlot
, maxRelativeIndex
, mkRelativeSlot
, ChunkAssertionFailure
, assertChunkCanContainEBB
, assertSameChunk
, assertWithinBounds
) where
import Control.Exception
import Control.Monad
import Data.Word
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Util.CallStack
import Ouroboros.Consensus.Util.RedundantConstraints
data ChunkInfo =
UniformChunkSize !ChunkSize
deriving stock (Int -> ChunkInfo -> ShowS
[ChunkInfo] -> ShowS
ChunkInfo -> String
(Int -> ChunkInfo -> ShowS)
-> (ChunkInfo -> String)
-> ([ChunkInfo] -> ShowS)
-> Show ChunkInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChunkInfo -> ShowS
showsPrec :: Int -> ChunkInfo -> ShowS
$cshow :: ChunkInfo -> String
show :: ChunkInfo -> String
$cshowList :: [ChunkInfo] -> ShowS
showList :: [ChunkInfo] -> ShowS
Show, (forall x. ChunkInfo -> Rep ChunkInfo x)
-> (forall x. Rep ChunkInfo x -> ChunkInfo) -> Generic ChunkInfo
forall x. Rep ChunkInfo x -> ChunkInfo
forall x. ChunkInfo -> Rep ChunkInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ChunkInfo -> Rep ChunkInfo x
from :: forall x. ChunkInfo -> Rep ChunkInfo x
$cto :: forall x. Rep ChunkInfo x -> ChunkInfo
to :: forall x. Rep ChunkInfo x -> ChunkInfo
Generic)
deriving anyclass (Context -> ChunkInfo -> IO (Maybe ThunkInfo)
Proxy ChunkInfo -> String
(Context -> ChunkInfo -> IO (Maybe ThunkInfo))
-> (Context -> ChunkInfo -> IO (Maybe ThunkInfo))
-> (Proxy ChunkInfo -> String)
-> NoThunks ChunkInfo
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> ChunkInfo -> IO (Maybe ThunkInfo)
noThunks :: Context -> ChunkInfo -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> ChunkInfo -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> ChunkInfo -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy ChunkInfo -> String
showTypeOf :: Proxy ChunkInfo -> String
NoThunks)
simpleChunkInfo :: EpochSize -> ChunkInfo
simpleChunkInfo :: EpochSize -> ChunkInfo
simpleChunkInfo (EpochSize Word64
sz) = ChunkSize -> ChunkInfo
UniformChunkSize (Bool -> Word64 -> ChunkSize
ChunkSize Bool
True Word64
sz)
singleChunkInfo :: ChunkSize -> ChunkInfo
singleChunkInfo :: ChunkSize -> ChunkInfo
singleChunkInfo = ChunkSize -> ChunkInfo
UniformChunkSize
chunkInfoSupportsEBBs :: ChunkInfo -> Bool
chunkInfoSupportsEBBs :: ChunkInfo -> Bool
chunkInfoSupportsEBBs (UniformChunkSize ChunkSize
chunkSize) =
ChunkSize -> Bool
chunkCanContainEBB ChunkSize
chunkSize
data ChunkSize = ChunkSize {
ChunkSize -> Bool
chunkCanContainEBB :: !Bool
, ChunkSize -> Word64
numRegularBlocks :: !Word64
}
deriving stock (Int -> ChunkSize -> ShowS
[ChunkSize] -> ShowS
ChunkSize -> String
(Int -> ChunkSize -> ShowS)
-> (ChunkSize -> String)
-> ([ChunkSize] -> ShowS)
-> Show ChunkSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChunkSize -> ShowS
showsPrec :: Int -> ChunkSize -> ShowS
$cshow :: ChunkSize -> String
show :: ChunkSize -> String
$cshowList :: [ChunkSize] -> ShowS
showList :: [ChunkSize] -> ShowS
Show, (forall x. ChunkSize -> Rep ChunkSize x)
-> (forall x. Rep ChunkSize x -> ChunkSize) -> Generic ChunkSize
forall x. Rep ChunkSize x -> ChunkSize
forall x. ChunkSize -> Rep ChunkSize x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ChunkSize -> Rep ChunkSize x
from :: forall x. ChunkSize -> Rep ChunkSize x
$cto :: forall x. Rep ChunkSize x -> ChunkSize
to :: forall x. Rep ChunkSize x -> ChunkSize
Generic)
deriving anyclass (Context -> ChunkSize -> IO (Maybe ThunkInfo)
Proxy ChunkSize -> String
(Context -> ChunkSize -> IO (Maybe ThunkInfo))
-> (Context -> ChunkSize -> IO (Maybe ThunkInfo))
-> (Proxy ChunkSize -> String)
-> NoThunks ChunkSize
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> ChunkSize -> IO (Maybe ThunkInfo)
noThunks :: Context -> ChunkSize -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> ChunkSize -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> ChunkSize -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy ChunkSize -> String
showTypeOf :: Proxy ChunkSize -> String
NoThunks)
newtype ChunkNo = ChunkNo { ChunkNo -> Word64
unChunkNo :: Word64 }
deriving stock (ChunkNo -> ChunkNo -> Bool
(ChunkNo -> ChunkNo -> Bool)
-> (ChunkNo -> ChunkNo -> Bool) -> Eq ChunkNo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChunkNo -> ChunkNo -> Bool
== :: ChunkNo -> ChunkNo -> Bool
$c/= :: ChunkNo -> ChunkNo -> Bool
/= :: ChunkNo -> ChunkNo -> Bool
Eq, Eq ChunkNo
Eq ChunkNo =>
(ChunkNo -> ChunkNo -> Ordering)
-> (ChunkNo -> ChunkNo -> Bool)
-> (ChunkNo -> ChunkNo -> Bool)
-> (ChunkNo -> ChunkNo -> Bool)
-> (ChunkNo -> ChunkNo -> Bool)
-> (ChunkNo -> ChunkNo -> ChunkNo)
-> (ChunkNo -> ChunkNo -> ChunkNo)
-> Ord ChunkNo
ChunkNo -> ChunkNo -> Bool
ChunkNo -> ChunkNo -> Ordering
ChunkNo -> ChunkNo -> ChunkNo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ChunkNo -> ChunkNo -> Ordering
compare :: ChunkNo -> ChunkNo -> Ordering
$c< :: ChunkNo -> ChunkNo -> Bool
< :: ChunkNo -> ChunkNo -> Bool
$c<= :: ChunkNo -> ChunkNo -> Bool
<= :: ChunkNo -> ChunkNo -> Bool
$c> :: ChunkNo -> ChunkNo -> Bool
> :: ChunkNo -> ChunkNo -> Bool
$c>= :: ChunkNo -> ChunkNo -> Bool
>= :: ChunkNo -> ChunkNo -> Bool
$cmax :: ChunkNo -> ChunkNo -> ChunkNo
max :: ChunkNo -> ChunkNo -> ChunkNo
$cmin :: ChunkNo -> ChunkNo -> ChunkNo
min :: ChunkNo -> ChunkNo -> ChunkNo
Ord, (forall x. ChunkNo -> Rep ChunkNo x)
-> (forall x. Rep ChunkNo x -> ChunkNo) -> Generic ChunkNo
forall x. Rep ChunkNo x -> ChunkNo
forall x. ChunkNo -> Rep ChunkNo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ChunkNo -> Rep ChunkNo x
from :: forall x. ChunkNo -> Rep ChunkNo x
$cto :: forall x. Rep ChunkNo x -> ChunkNo
to :: forall x. Rep ChunkNo x -> ChunkNo
Generic)
deriving newtype (Int -> ChunkNo -> ShowS
[ChunkNo] -> ShowS
ChunkNo -> String
(Int -> ChunkNo -> ShowS)
-> (ChunkNo -> String) -> ([ChunkNo] -> ShowS) -> Show ChunkNo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChunkNo -> ShowS
showsPrec :: Int -> ChunkNo -> ShowS
$cshow :: ChunkNo -> String
show :: ChunkNo -> String
$cshowList :: [ChunkNo] -> ShowS
showList :: [ChunkNo] -> ShowS
Show, Context -> ChunkNo -> IO (Maybe ThunkInfo)
Proxy ChunkNo -> String
(Context -> ChunkNo -> IO (Maybe ThunkInfo))
-> (Context -> ChunkNo -> IO (Maybe ThunkInfo))
-> (Proxy ChunkNo -> String)
-> NoThunks ChunkNo
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> ChunkNo -> IO (Maybe ThunkInfo)
noThunks :: Context -> ChunkNo -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> ChunkNo -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> ChunkNo -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy ChunkNo -> String
showTypeOf :: Proxy ChunkNo -> String
NoThunks)
firstChunkNo :: ChunkNo
firstChunkNo :: ChunkNo
firstChunkNo = Word64 -> ChunkNo
ChunkNo Word64
0
chunkNoToInt :: ChunkNo -> Int
chunkNoToInt :: ChunkNo -> Int
chunkNoToInt (ChunkNo Word64
n) = Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n
chunkNoFromInt :: Int -> ChunkNo
chunkNoFromInt :: Int -> ChunkNo
chunkNoFromInt Int
n = Word64 -> ChunkNo
ChunkNo (Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
nextChunkNo :: ChunkNo -> ChunkNo
nextChunkNo :: ChunkNo -> ChunkNo
nextChunkNo (ChunkNo Word64
n) = Word64 -> ChunkNo
ChunkNo (Word64
n Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
1)
prevChunkNo :: ChunkNo -> Maybe ChunkNo
prevChunkNo :: ChunkNo -> Maybe ChunkNo
prevChunkNo (ChunkNo Word64
n) = Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word64
n Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> Word64
0) Maybe () -> Maybe ChunkNo -> Maybe ChunkNo
forall a b. Maybe a -> Maybe b -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ChunkNo -> Maybe ChunkNo
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word64 -> ChunkNo
ChunkNo (Word64 -> ChunkNo) -> Word64 -> ChunkNo
forall a b. (a -> b) -> a -> b
$ Word64
n Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1)
countChunks :: ChunkNo -> ChunkNo -> Word64
countChunks :: ChunkNo -> ChunkNo -> Word64
countChunks (ChunkNo Word64
a) (ChunkNo Word64
b) = if Word64
a Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
b then Word64
a Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
b else Word64
b Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
a
chunksBetween :: ChunkNo -> ChunkNo -> [ChunkNo]
chunksBetween :: ChunkNo -> ChunkNo -> [ChunkNo]
chunksBetween (ChunkNo Word64
a) (ChunkNo Word64
b) = (Word64 -> ChunkNo) -> [Word64] -> [ChunkNo]
forall a b. (a -> b) -> [a] -> [b]
map Word64 -> ChunkNo
ChunkNo ([Word64] -> [ChunkNo]) -> [Word64] -> [ChunkNo]
forall a b. (a -> b) -> a -> b
$
if Word64
a Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
b then [Word64
a .. Word64
b] else [Word64
b .. Word64
a]
unsafeEpochNoToChunkNo :: EpochNo -> ChunkNo
unsafeEpochNoToChunkNo :: EpochNo -> ChunkNo
unsafeEpochNoToChunkNo (EpochNo Word64
n) = Word64 -> ChunkNo
ChunkNo Word64
n
unsafeChunkNoToEpochNo :: ChunkNo -> EpochNo
unsafeChunkNoToEpochNo :: ChunkNo -> EpochNo
unsafeChunkNoToEpochNo (ChunkNo Word64
n) = Word64 -> EpochNo
EpochNo Word64
n
getChunkSize :: ChunkInfo -> ChunkNo -> ChunkSize
getChunkSize :: ChunkInfo -> ChunkNo -> ChunkSize
getChunkSize ChunkInfo
chunkInfo ChunkNo
_chunk =
case ChunkInfo
chunkInfo of
UniformChunkSize ChunkSize
sz -> ChunkSize
sz
data RelativeSlot = RelativeSlot {
RelativeSlot -> ChunkNo
relativeSlotChunkNo :: !ChunkNo
, RelativeSlot -> ChunkSize
relativeSlotChunkSize :: !ChunkSize
, RelativeSlot -> Word64
relativeSlotIndex :: !Word64
}
deriving stock (Int -> RelativeSlot -> ShowS
[RelativeSlot] -> ShowS
RelativeSlot -> String
(Int -> RelativeSlot -> ShowS)
-> (RelativeSlot -> String)
-> ([RelativeSlot] -> ShowS)
-> Show RelativeSlot
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RelativeSlot -> ShowS
showsPrec :: Int -> RelativeSlot -> ShowS
$cshow :: RelativeSlot -> String
show :: RelativeSlot -> String
$cshowList :: [RelativeSlot] -> ShowS
showList :: [RelativeSlot] -> ShowS
Show, (forall x. RelativeSlot -> Rep RelativeSlot x)
-> (forall x. Rep RelativeSlot x -> RelativeSlot)
-> Generic RelativeSlot
forall x. Rep RelativeSlot x -> RelativeSlot
forall x. RelativeSlot -> Rep RelativeSlot x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RelativeSlot -> Rep RelativeSlot x
from :: forall x. RelativeSlot -> Rep RelativeSlot x
$cto :: forall x. Rep RelativeSlot x -> RelativeSlot
to :: forall x. Rep RelativeSlot x -> RelativeSlot
Generic)
deriving anyclass (Context -> RelativeSlot -> IO (Maybe ThunkInfo)
Proxy RelativeSlot -> String
(Context -> RelativeSlot -> IO (Maybe ThunkInfo))
-> (Context -> RelativeSlot -> IO (Maybe ThunkInfo))
-> (Proxy RelativeSlot -> String)
-> NoThunks RelativeSlot
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> RelativeSlot -> IO (Maybe ThunkInfo)
noThunks :: Context -> RelativeSlot -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> RelativeSlot -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> RelativeSlot -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy RelativeSlot -> String
showTypeOf :: Proxy RelativeSlot -> String
NoThunks)
maxRelativeIndex :: ChunkSize -> Word64
maxRelativeIndex :: ChunkSize -> Word64
maxRelativeIndex ChunkSize{Bool
Word64
chunkCanContainEBB :: ChunkSize -> Bool
numRegularBlocks :: ChunkSize -> Word64
chunkCanContainEBB :: Bool
numRegularBlocks :: Word64
..}
| Bool
chunkCanContainEBB = Word64
numRegularBlocks
| Bool
otherwise = Word64
numRegularBlocks Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1
mkRelativeSlot :: HasCallStack => ChunkInfo -> ChunkNo -> Word64 -> RelativeSlot
mkRelativeSlot :: HasCallStack => ChunkInfo -> ChunkNo -> Word64 -> RelativeSlot
mkRelativeSlot ChunkInfo
chunkInfo ChunkNo
chunk Word64
index =
Word64 -> ChunkSize -> RelativeSlot -> RelativeSlot
forall a. HasCallStack => Word64 -> ChunkSize -> a -> a
assertWithinBounds Word64
index ChunkSize
size (RelativeSlot -> RelativeSlot) -> RelativeSlot -> RelativeSlot
forall a b. (a -> b) -> a -> b
$
RelativeSlot {
relativeSlotChunkNo :: ChunkNo
relativeSlotChunkNo = ChunkNo
chunk
, relativeSlotChunkSize :: ChunkSize
relativeSlotChunkSize = ChunkSize
size
, relativeSlotIndex :: Word64
relativeSlotIndex = Word64
index
}
where
size :: ChunkSize
size = ChunkInfo -> ChunkNo -> ChunkSize
getChunkSize ChunkInfo
chunkInfo ChunkNo
chunk
instance Eq RelativeSlot where
RelativeSlot
a == :: RelativeSlot -> RelativeSlot -> Bool
== RelativeSlot
b
| RelativeSlot -> ChunkNo
relativeSlotChunkNo RelativeSlot
a ChunkNo -> ChunkNo -> Bool
forall a. Eq a => a -> a -> Bool
/= RelativeSlot -> ChunkNo
relativeSlotChunkNo RelativeSlot
b = Bool
False
| Bool
otherwise =
ChunkNo -> ChunkNo -> Bool -> Bool
forall a. HasCallStack => ChunkNo -> ChunkNo -> a -> a
assertSameChunk (RelativeSlot -> ChunkNo
relativeSlotChunkNo RelativeSlot
a) (RelativeSlot -> ChunkNo
relativeSlotChunkNo RelativeSlot
b) (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$
RelativeSlot -> Word64
relativeSlotIndex RelativeSlot
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== RelativeSlot -> Word64
relativeSlotIndex RelativeSlot
b
compareRelativeSlot :: HasCallStack => RelativeSlot -> RelativeSlot -> Ordering
compareRelativeSlot :: HasCallStack => RelativeSlot -> RelativeSlot -> Ordering
compareRelativeSlot RelativeSlot
a RelativeSlot
b =
ChunkNo -> ChunkNo -> Ordering -> Ordering
forall a. HasCallStack => ChunkNo -> ChunkNo -> a -> a
assertSameChunk (RelativeSlot -> ChunkNo
relativeSlotChunkNo RelativeSlot
a) (RelativeSlot -> ChunkNo
relativeSlotChunkNo RelativeSlot
b) (Ordering -> Ordering) -> Ordering -> Ordering
forall a b. (a -> b) -> a -> b
$
Word64 -> Word64 -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (RelativeSlot -> Word64
relativeSlotIndex RelativeSlot
a) (RelativeSlot -> Word64
relativeSlotIndex RelativeSlot
b)
assertRelativeSlotInChunk :: HasCallStack => ChunkNo -> RelativeSlot -> Word64
assertRelativeSlotInChunk :: HasCallStack => ChunkNo -> RelativeSlot -> Word64
assertRelativeSlotInChunk ChunkNo
chunk RelativeSlot
relSlot =
ChunkNo -> ChunkNo -> Word64 -> Word64
forall a. HasCallStack => ChunkNo -> ChunkNo -> a -> a
assertSameChunk (RelativeSlot -> ChunkNo
relativeSlotChunkNo RelativeSlot
relSlot) ChunkNo
chunk (Word64 -> Word64) -> Word64 -> Word64
forall a b. (a -> b) -> a -> b
$
RelativeSlot -> Word64
relativeSlotIndex RelativeSlot
relSlot
data ChunkAssertionFailure =
NotSameChunk ChunkNo ChunkNo PrettyCallStack
| NotWithinBounds Word64 ChunkSize PrettyCallStack
| ChunkCannotContainEBBs ChunkNo PrettyCallStack
deriving (Int -> ChunkAssertionFailure -> ShowS
[ChunkAssertionFailure] -> ShowS
ChunkAssertionFailure -> String
(Int -> ChunkAssertionFailure -> ShowS)
-> (ChunkAssertionFailure -> String)
-> ([ChunkAssertionFailure] -> ShowS)
-> Show ChunkAssertionFailure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChunkAssertionFailure -> ShowS
showsPrec :: Int -> ChunkAssertionFailure -> ShowS
$cshow :: ChunkAssertionFailure -> String
show :: ChunkAssertionFailure -> String
$cshowList :: [ChunkAssertionFailure] -> ShowS
showList :: [ChunkAssertionFailure] -> ShowS
Show)
instance Exception ChunkAssertionFailure
assertSameChunk :: HasCallStack => ChunkNo -> ChunkNo -> a -> a
#if ENABLE_ASSERTIONS
assertSameChunk :: forall a. HasCallStack => ChunkNo -> ChunkNo -> a -> a
assertSameChunk ChunkNo
a ChunkNo
b
| ChunkNo
a ChunkNo -> ChunkNo -> Bool
forall a. Eq a => a -> a -> Bool
== ChunkNo
b = a -> a
forall a. a -> a
id
| Bool
otherwise = ChunkAssertionFailure -> a -> a
forall a e. Exception e => e -> a
throw (ChunkAssertionFailure -> a -> a)
-> ChunkAssertionFailure -> a -> a
forall a b. (a -> b) -> a -> b
$ ChunkNo -> ChunkNo -> PrettyCallStack -> ChunkAssertionFailure
NotSameChunk ChunkNo
a ChunkNo
b PrettyCallStack
HasCallStack => PrettyCallStack
prettyCallStack
#else
assertSameChunk _ _ = id
#endif
where
()
_ = Proxy HasCallStack -> ()
forall (c :: Constraint) (proxy :: Constraint -> *).
c =>
proxy c -> ()
keepRedundantConstraint (forall {k} (t :: k). Proxy t
forall (t :: Constraint). Proxy t
Proxy @HasCallStack)
assertWithinBounds :: HasCallStack => Word64 -> ChunkSize -> a -> a
#if ENABLE_ASSERTIONS
assertWithinBounds :: forall a. HasCallStack => Word64 -> ChunkSize -> a -> a
assertWithinBounds Word64
ix ChunkSize
sz
| Word64
ix Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= ChunkSize -> Word64
maxRelativeIndex ChunkSize
sz = a -> a
forall a. a -> a
id
| Bool
otherwise = ChunkAssertionFailure -> a -> a
forall a e. Exception e => e -> a
throw (ChunkAssertionFailure -> a -> a)
-> ChunkAssertionFailure -> a -> a
forall a b. (a -> b) -> a -> b
$ Word64 -> ChunkSize -> PrettyCallStack -> ChunkAssertionFailure
NotWithinBounds Word64
ix ChunkSize
sz PrettyCallStack
HasCallStack => PrettyCallStack
prettyCallStack
#else
assertWithinBounds _ _ = id
#endif
where
()
_ = Proxy HasCallStack -> ()
forall (c :: Constraint) (proxy :: Constraint -> *).
c =>
proxy c -> ()
keepRedundantConstraint (forall {k} (t :: k). Proxy t
forall (t :: Constraint). Proxy t
Proxy @HasCallStack)
assertChunkCanContainEBB :: HasCallStack => ChunkNo -> ChunkSize -> a -> a
#if ENABLE_ASSERTIONS
assertChunkCanContainEBB :: forall a. HasCallStack => ChunkNo -> ChunkSize -> a -> a
assertChunkCanContainEBB ChunkNo
chunk ChunkSize
size
| ChunkSize -> Bool
chunkCanContainEBB ChunkSize
size = a -> a
forall a. a -> a
id
| Bool
otherwise = ChunkAssertionFailure -> a -> a
forall a e. Exception e => e -> a
throw (ChunkAssertionFailure -> a -> a)
-> ChunkAssertionFailure -> a -> a
forall a b. (a -> b) -> a -> b
$ ChunkNo -> PrettyCallStack -> ChunkAssertionFailure
ChunkCannotContainEBBs ChunkNo
chunk PrettyCallStack
HasCallStack => PrettyCallStack
prettyCallStack
#else
assertChunkCanContainEBB _ _ = id
#endif
where
()
_ = Proxy HasCallStack -> ()
forall (c :: Constraint) (proxy :: Constraint -> *).
c =>
proxy c -> ()
keepRedundantConstraint (forall {k} (t :: k). Proxy t
forall (t :: Constraint). Proxy t
Proxy @HasCallStack)