Skip to content

Commit

Permalink
Add a comment about safety of accursedUnutterablePerformIO usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Nov 20, 2024
1 parent 1588e3a commit 03d23d0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cardano-crypto-class/src/Cardano/Crypto/PackedBytes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ instance KnownNat n => MemPack (PackedBytes n) where
buf <- ask
pure $! buffer buf
(\ba# -> packBytes (SBS.SBS ba#) curPos)
-- Usage of `accursedUnutterablePerformIO` is safe below because there are no memory
-- allocations happening that depend on the IO monad that we are excaping here. All
-- IO actions are morally pure reads using pointers into the immutable
-- memory. Furthermore, in the place where ByteArray is allocated in
-- `packPinnedPtrN`, mutation and freezing are encapsulated with `runST` and is not
-- related to the `IO` we are escaping.
(\addr# -> accursedUnutterablePerformIO $ packPinnedPtr (Ptr (addr# `plusAddr#` curPos#)))
{-# INLINE unpackM #-}

Expand Down

0 comments on commit 03d23d0

Please sign in to comment.