diff --git a/vector/src/Data/Vector.hs b/vector/src/Data/Vector.hs
index 072fef4b..1100b1b0 100644
--- a/vector/src/Data/Vector.hs
+++ b/vector/src/Data/Vector.hs
@@ -187,6 +187,7 @@ import Data.Vector.Mutable.Unsafe ( MVector )
import Data.Vector.Unsafe ( Vector(..) )
import qualified Data.Vector.Unsafe as U
import qualified Data.Vector.Generic as G
+import GHC.Stack (HasCallStack)
import Control.Monad.ST ( ST )
import Control.Monad.Primitive
@@ -242,7 +243,7 @@ null = G.null
-- --------
-- | O(1) Indexing.
-(!) :: Vector a -> Int -> a
+(!) :: HasCallStack => Vector a -> Int -> a
{-# INLINE (!) #-}
(!) = (G.!)
@@ -297,7 +298,7 @@ unsafeLast = G.unsafeLast
--
-- Here, no references to @v@ are retained because indexing (but /not/ the
-- element) is evaluated eagerly.
-indexM :: Monad m => Vector a -> Int -> m a
+indexM :: (HasCallStack, Monad m) => Vector a -> Int -> m a
{-# INLINE indexM #-}
indexM = G.indexM
@@ -336,10 +337,11 @@ unsafeLastM = G.unsafeLastM
-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
-- contain at least @i+n@ elements.
-slice :: Int -- ^ @i@ starting index
- -> Int -- ^ @n@ length
- -> Vector a
- -> Vector a
+slice :: HasCallStack
+ => Int -- ^ @i@ starting index
+ -> Int -- ^ @n@ length
+ -> Vector a
+ -> Vector a
{-# INLINE slice #-}
slice = G.slice
@@ -805,7 +807,7 @@ reverse = G.reverse
-- often much more efficient.
--
-- > backpermute <0,3,2,3,1,0> =
-backpermute :: Vector a -> Vector Int -> Vector a
+backpermute :: HasCallStack => Vector a -> Vector Int -> Vector a
{-# INLINE backpermute #-}
backpermute = G.backpermute
@@ -2113,7 +2115,7 @@ unsafeCopy = G.unsafeCopy
-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
-- have the same length.
-copy :: PrimMonad m => MVector (PrimState m) a -> Vector a -> m ()
+copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
{-# INLINE copy #-}
copy = G.copy
diff --git a/vector/src/Data/Vector/Mutable.hs b/vector/src/Data/Vector/Mutable.hs
index dc7d9d5a..414ab67b 100644
--- a/vector/src/Data/Vector/Mutable.hs
+++ b/vector/src/Data/Vector/Mutable.hs
@@ -77,6 +77,7 @@ import Data.Vector.Mutable.Unsafe (MVector(..))
import Data.Vector.Pattern
import Data.Primitive.Array
import Control.Monad.Primitive
+import GHC.Stack (HasCallStack)
import Prelude( Ord, Bool, Ordering(..), Int, Maybe, (<$>) )
@@ -209,7 +210,7 @@ overlaps = G.overlaps
-- --------------
-- | Create a mutable vector of the given length.
-new :: PrimMonad m => Int -> m (MVector (PrimState m) a)
+new :: (HasCallStack, PrimMonad m) => Int -> m (MVector (PrimState m) a)
{-# INLINE new #-}
new = G.new
@@ -293,7 +294,7 @@ clone = G.clone
-- [10,20,30]
--
-- @since 0.5
-grow :: PrimMonad m
+grow :: (HasCallStack, PrimMonad m)
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
{-# INLINE grow #-}
grow = G.grow
@@ -328,7 +329,7 @@ clear = G.clear
-- >>> v <- MV.generate 10 (\x -> x*x)
-- >>> MV.read v 3
-- 9
-read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a
+read :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> m a
{-# INLINE read #-}
read = G.read
@@ -350,29 +351,29 @@ readMaybe :: (PrimMonad m) => MVector (PrimState m) a -> Int -> m (Maybe a)
readMaybe = G.readMaybe
-- | Replace the element at the given position.
-write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
+write :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m ()
{-# INLINE write #-}
write = G.write
-- | Modify the element at the given position.
-modify :: PrimMonad m => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
+modify :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
{-# INLINE modify #-}
modify = G.modify
-- | Modify the element at the given position using a monadic function.
--
-- @since 0.12.3.0
-modifyM :: (PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
+modifyM :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
{-# INLINE modifyM #-}
modifyM = G.modifyM
-- | Swap the elements at the given positions.
-swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m ()
+swap :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> Int -> m ()
{-# INLINE swap #-}
swap = G.swap
-- | Replace the element at the given position and return the old element.
-exchange :: (PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
+exchange :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
{-# INLINE exchange #-}
exchange = G.exchange
@@ -420,7 +421,7 @@ set = G.set
-- | Copy a vector. The two vectors must have the same length and may not
-- overlap.
-copy :: PrimMonad m => MVector (PrimState m) a -- ^ target
+copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
{-# INLINE copy #-}
@@ -441,7 +442,7 @@ unsafeCopy = G.unsafeCopy
-- Otherwise, the copying is performed as if the source vector were
-- copied to a temporary vector and then the temporary vector was copied
-- to the target vector.
-move :: PrimMonad m => MVector (PrimState m) a -- ^ target
+move :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
{-# INLINE move #-}
diff --git a/vector/src/Data/Vector/Primitive.hs b/vector/src/Data/Vector/Primitive.hs
index 4f8e25bf..d8df6783 100644
--- a/vector/src/Data/Vector/Primitive.hs
+++ b/vector/src/Data/Vector/Primitive.hs
@@ -199,7 +199,7 @@ null = G.null
-- --------
-- | O(1) Indexing.
-(!) :: Prim a => Vector a -> Int -> a
+(!) :: (HasCallStack, Prim a) => Vector a -> Int -> a
{-# INLINE (!) #-}
(!) = (G.!)
@@ -254,7 +254,7 @@ unsafeLast = G.unsafeLast
--
-- Here, no references to @v@ are retained because indexing (but /not/ the
-- element) is evaluated eagerly.
-indexM :: (Prim a, Monad m) => Vector a -> Int -> m a
+indexM :: (HasCallStack, Prim a, Monad m) => Vector a -> Int -> m a
{-# INLINE indexM #-}
indexM = G.indexM
@@ -293,7 +293,7 @@ unsafeLastM = G.unsafeLastM
-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
-- contain at least @i+n@ elements.
-slice :: Prim a
+slice :: (HasCallStack, Prim a)
=> Int -- ^ @i@ starting index
-> Int -- ^ @n@ length
-> Vector a
@@ -716,7 +716,7 @@ reverse = G.reverse
-- often much more efficient.
--
-- > backpermute <0,3,2,3,1,0> =
-backpermute :: Prim a => Vector a -> Vector Int -> Vector a
+backpermute :: (HasCallStack, Prim a) => Vector a -> Vector Int -> Vector a
{-# INLINE backpermute #-}
backpermute = G.backpermute
@@ -1905,7 +1905,7 @@ unsafeCopy = G.unsafeCopy
-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
-- have the same length.
-copy :: (Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
+copy :: (HasCallStack, Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
{-# INLINE copy #-}
copy = G.copy
diff --git a/vector/src/Data/Vector/Primitive/Mutable.hs b/vector/src/Data/Vector/Primitive/Mutable.hs
index 4915d76d..ef22e625 100644
--- a/vector/src/Data/Vector/Primitive/Mutable.hs
+++ b/vector/src/Data/Vector/Primitive/Mutable.hs
@@ -192,7 +192,7 @@ overlaps = G.overlaps
-- --------------
-- | Create a mutable vector of the given length.
-new :: (PrimMonad m, Prim a) => Int -> m (MVector (PrimState m) a)
+new :: (HasCallStack, PrimMonad m, Prim a) => Int -> m (MVector (PrimState m) a)
{-# INLINE new #-}
new = G.new
@@ -279,7 +279,7 @@ clone = G.clone
-- [10,20,30]
--
-- @since 0.5
-grow :: (PrimMonad m, Prim a)
+grow :: (HasCallStack, PrimMonad m, Prim a)
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
{-# INLINE grow #-}
grow = G.grow
@@ -314,7 +314,7 @@ clear = G.clear
-- >>> v <- MVP.generate 10 (\x -> x*x)
-- >>> MVP.read v 3
-- 9
-read :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m a
+read :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m a
{-# INLINE read #-}
read = G.read
@@ -336,29 +336,29 @@ readMaybe :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m (Maybe
readMaybe = G.readMaybe
-- | Replace the element at the given position.
-write :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m ()
+write :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m ()
{-# INLINE write #-}
write = G.write
-- | Modify the element at the given position.
-modify :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
+modify :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
{-# INLINE modify #-}
modify = G.modify
-- | Modify the element at the given position using a monadic function.
--
-- @since 0.12.3.0
-modifyM :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
+modifyM :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
{-# INLINE modifyM #-}
modifyM = G.modifyM
-- | Swap the elements at the given positions.
-swap :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m ()
+swap :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m ()
{-# INLINE swap #-}
swap = G.swap
-- | Replace the element at the given position and return the old element.
-exchange :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m a
+exchange :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m a
{-# INLINE exchange #-}
exchange = G.exchange
@@ -406,7 +406,7 @@ set = G.set
-- | Copy a vector. The two vectors must have the same length and may not
-- overlap.
-copy :: (PrimMonad m, Prim a)
+copy :: (HasCallStack, PrimMonad m, Prim a)
=> MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
@@ -429,7 +429,7 @@ unsafeCopy = G.unsafeCopy
-- Otherwise, the copying is performed as if the source vector were
-- copied to a temporary vector and then the temporary vector was copied
-- to the target vector.
-move :: (PrimMonad m, Prim a)
+move :: (HasCallStack, PrimMonad m, Prim a)
=> MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
diff --git a/vector/src/Data/Vector/Storable.hs b/vector/src/Data/Vector/Storable.hs
index 6ac73f86..55f26098 100644
--- a/vector/src/Data/Vector/Storable.hs
+++ b/vector/src/Data/Vector/Storable.hs
@@ -173,6 +173,7 @@ import qualified Data.Vector.Generic as G
import Data.Vector.Storable.Mutable ( MVector, pattern MVector )
import Data.Vector.Storable.Unsafe (Vector(..))
import qualified Data.Vector.Storable.Unsafe as U
+import GHC.Stack (HasCallStack)
import Control.Monad.ST ( ST )
import Control.Monad.Primitive
@@ -203,7 +204,7 @@ null = G.null
-- --------
-- | O(1) Indexing.
-(!) :: Storable a => Vector a -> Int -> a
+(!) :: (HasCallStack, Storable a) => Vector a -> Int -> a
{-# INLINE (!) #-}
(!) = (G.!)
@@ -258,7 +259,7 @@ unsafeLast = G.unsafeLast
--
-- Here, no references to @v@ are retained because indexing (but /not/ the
-- element) is evaluated eagerly.
-indexM :: (Storable a, Monad m) => Vector a -> Int -> m a
+indexM :: (HasCallStack, Storable a, Monad m) => Vector a -> Int -> m a
{-# INLINE indexM #-}
indexM = G.indexM
@@ -297,7 +298,7 @@ unsafeLastM = G.unsafeLastM
-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
-- contain at least @i+n@ elements.
-slice :: Storable a
+slice :: (HasCallStack, Storable a)
=> Int -- ^ @i@ starting index
-> Int -- ^ @n@ length
-> Vector a
@@ -720,7 +721,7 @@ reverse = G.reverse
-- often much more efficient.
--
-- > backpermute <0,3,2,3,1,0> =
-backpermute :: Storable a => Vector a -> Vector Int -> Vector a
+backpermute :: (HasCallStack, Storable a) => Vector a -> Vector Int -> Vector a
{-# INLINE backpermute #-}
backpermute = G.backpermute
@@ -1945,7 +1946,7 @@ unsafeCopy = G.unsafeCopy
-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
-- have the same length.
-copy :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
+copy :: (HasCallStack, Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
{-# INLINE copy #-}
copy = G.copy
diff --git a/vector/src/Data/Vector/Storable/Mutable.hs b/vector/src/Data/Vector/Storable/Mutable.hs
index 2b4e0d74..98fe89fe 100644
--- a/vector/src/Data/Vector/Storable/Mutable.hs
+++ b/vector/src/Data/Vector/Storable/Mutable.hs
@@ -86,6 +86,7 @@ import Foreign.ForeignPtr (ForeignPtr)
import Foreign.Ptr (Ptr)
import Control.Monad.Primitive
+import GHC.Stack (HasCallStack)
import Prelude (IO, Int, Ord, Bool, Maybe, Ordering(..) )
@@ -197,7 +198,7 @@ overlaps = G.overlaps
-- --------------
-- | Create a mutable vector of the given length.
-new :: (PrimMonad m, Storable a) => Int -> m (MVector (PrimState m) a)
+new :: (HasCallStack, PrimMonad m, Storable a) => Int -> m (MVector (PrimState m) a)
{-# INLINE new #-}
new = G.new
@@ -284,7 +285,7 @@ clone = G.clone
-- [10,20,30]
--
-- @since 0.5
-grow :: (PrimMonad m, Storable a)
+grow :: (HasCallStack, PrimMonad m, Storable a)
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
{-# INLINE grow #-}
grow = G.grow
@@ -319,7 +320,7 @@ clear = G.clear
-- >>> v <- MVS.generate 10 (\x -> x*x)
-- >>> MVS.read v 3
-- 9
-read :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> m a
+read :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> m a
{-# INLINE read #-}
read = G.read
@@ -342,30 +343,30 @@ readMaybe = G.readMaybe
-- | Replace the element at the given position.
write
- :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m ()
+ :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m ()
{-# INLINE write #-}
write = G.write
-- | Modify the element at the given position.
-modify :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
+modify :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
{-# INLINE modify #-}
modify = G.modify
-- | Modify the element at the given position using a monadic function.
--
-- @since 0.12.3.0
-modifyM :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
+modifyM :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
{-# INLINE modifyM #-}
modifyM = G.modifyM
-- | Swap the elements at the given positions.
swap
- :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> Int -> m ()
+ :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> Int -> m ()
{-# INLINE swap #-}
swap = G.swap
-- | Replace the element at the given position and return the old element.
-exchange :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m a
+exchange :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m a
{-# INLINE exchange #-}
exchange = G.exchange
@@ -413,7 +414,7 @@ set = G.set
-- | Copy a vector. The two vectors must have the same length and may not
-- overlap.
-copy :: (PrimMonad m, Storable a)
+copy :: (HasCallStack, PrimMonad m, Storable a)
=> MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
@@ -436,7 +437,7 @@ unsafeCopy = G.unsafeCopy
-- Otherwise, the copying is performed as if the source vector were
-- copied to a temporary vector and then the temporary vector was copied
-- to the target vector.
-move :: (PrimMonad m, Storable a)
+move :: (HasCallStack, PrimMonad m, Storable a)
=> MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
diff --git a/vector/src/Data/Vector/Strict.hs b/vector/src/Data/Vector/Strict.hs
index 62f60631..b6a19a71 100644
--- a/vector/src/Data/Vector/Strict.hs
+++ b/vector/src/Data/Vector/Strict.hs
@@ -189,6 +189,7 @@ import qualified Data.Vector.Strict.Unsafe as U
import qualified Data.Vector.Generic as G
import qualified Data.Vector as V
import qualified Data.Traversable as Traversable
+import GHC.Stack (HasCallStack)
import Control.Monad.ST ( ST )
@@ -263,7 +264,7 @@ null = G.null
-- | O(1) Indexing.
--
-- @since 0.13.2.0
-(!) :: Vector a -> Int -> a
+(!) :: HasCallStack => Vector a -> Int -> a
{-# INLINE (!) #-}
(!) = (G.!)
@@ -332,7 +333,7 @@ unsafeLast = G.unsafeLast
-- element) is evaluated eagerly.
--
-- @since 0.13.2.0
-indexM :: Monad m => Vector a -> Int -> m a
+indexM :: (HasCallStack, Monad m) => Vector a -> Int -> m a
{-# INLINE indexM #-}
indexM = G.indexM
@@ -383,10 +384,11 @@ unsafeLastM = G.unsafeLastM
-- contain at least @i+n@ elements.
--
-- @since 0.13.2.0
-slice :: Int -- ^ @i@ starting index
- -> Int -- ^ @n@ length
- -> Vector a
- -> Vector a
+slice :: HasCallStack
+ => Int -- ^ @i@ starting index
+ -> Int -- ^ @n@ length
+ -> Vector a
+ -> Vector a
{-# INLINE slice #-}
slice = G.slice
@@ -942,7 +944,7 @@ reverse = G.reverse
-- > backpermute <0,3,2,3,1,0> =
--
-- @since 0.13.2.0
-backpermute :: Vector a -> Vector Int -> Vector a
+backpermute :: HasCallStack => Vector a -> Vector Int -> Vector a
{-# INLINE backpermute #-}
backpermute = G.backpermute
@@ -2467,7 +2469,7 @@ unsafeCopy = G.unsafeCopy
-- have the same length.
--
-- @since 0.13.2.0
-copy :: PrimMonad m => MVector (PrimState m) a -> Vector a -> m ()
+copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
{-# INLINE copy #-}
copy = G.copy
diff --git a/vector/src/Data/Vector/Strict/Mutable.hs b/vector/src/Data/Vector/Strict/Mutable.hs
index b7d8bb87..8e4e5fe1 100644
--- a/vector/src/Data/Vector/Strict/Mutable.hs
+++ b/vector/src/Data/Vector/Strict/Mutable.hs
@@ -83,6 +83,7 @@ import qualified Data.Vector.Mutable as MV
import Data.Vector.Strict.Mutable.Unsafe as U (MVector(..))
import Data.Vector.Strict.Pattern as U
import Control.Monad.Primitive
+import GHC.Stack (HasCallStack)
import Prelude ( Ord, Bool, Int, Maybe, Ordering(..), Monad(..), (<$>), ($))
@@ -265,7 +266,7 @@ overlaps = G.overlaps
-- | Create a mutable vector of the given length.
--
-- @since 0.13.2.0
-new :: PrimMonad m => Int -> m (MVector (PrimState m) a)
+new :: (HasCallStack, PrimMonad m) => Int -> m (MVector (PrimState m) a)
{-# INLINE new #-}
new = G.new
@@ -355,7 +356,7 @@ clone = G.clone
-- [10,20,30]
--
-- @since 0.13.2.0
-grow :: PrimMonad m
+grow :: (HasCallStack, PrimMonad m)
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
{-# INLINE grow #-}
grow = G.grow
@@ -394,7 +395,7 @@ clear = G.clear
-- 9
--
-- @since 0.13.2.0
-read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a
+read :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> m a
{-# INLINE read #-}
read = G.read
@@ -420,35 +421,35 @@ readMaybe = G.readMaybe
-- | Replace the element at the given position.
--
-- @since 0.13.2.0
-write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
+write :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m ()
{-# INLINE write #-}
write = G.write
-- | Modify the element at the given position.
--
-- @since 0.13.2.0
-modify :: PrimMonad m => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
+modify :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
{-# INLINE modify #-}
modify = G.modify
-- | Modify the element at the given position using a monadic function.
--
-- @since 0.13.2.0
-modifyM :: (PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
+modifyM :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
{-# INLINE modifyM #-}
modifyM = G.modifyM
-- | Swap the elements at the given positions.
--
-- @since 0.13.2.0
-swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m ()
+swap :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> Int -> m ()
{-# INLINE swap #-}
swap = G.swap
-- | Replace the element at the given position and return the old element.
--
-- @since 0.13.2.0
-exchange :: (PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
+exchange :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
{-# INLINE exchange #-}
exchange = G.exchange
@@ -510,7 +511,7 @@ set = G.set
-- overlap.
--
-- @since 0.13.2.0
-copy :: PrimMonad m => MVector (PrimState m) a -- ^ target
+copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
{-# INLINE copy #-}
@@ -535,7 +536,7 @@ unsafeCopy = G.unsafeCopy
-- to the target vector.
--
-- @since 0.13.2.0
-move :: PrimMonad m => MVector (PrimState m) a -- ^ target
+move :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
{-# INLINE move #-}
diff --git a/vector/src/Data/Vector/Unboxed.hs b/vector/src/Data/Vector/Unboxed.hs
index f413c020..ed1719e3 100644
--- a/vector/src/Data/Vector/Unboxed.hs
+++ b/vector/src/Data/Vector/Unboxed.hs
@@ -234,6 +234,7 @@ import qualified Data.Vector.Unboxed.Unsafe as U
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Fusion.Bundle as Bundle
import Data.Vector.Fusion.Util ( delayed_min )
+import GHC.Stack (HasCallStack)
import Control.Monad.ST ( ST )
import Control.Monad.Primitive
@@ -319,7 +320,7 @@ null = G.null
-- --------
-- | O(1) Indexing.
-(!) :: Unbox a => Vector a -> Int -> a
+(!) :: (HasCallStack, Unbox a) => Vector a -> Int -> a
{-# INLINE (!) #-}
(!) = (G.!)
@@ -374,7 +375,7 @@ unsafeLast = G.unsafeLast
--
-- Here, no references to @v@ are retained because indexing (but /not/ the
-- element) is evaluated eagerly.
-indexM :: (Unbox a, Monad m) => Vector a -> Int -> m a
+indexM :: (HasCallStack, Unbox a, Monad m) => Vector a -> Int -> m a
{-# INLINE indexM #-}
indexM = G.indexM
@@ -413,10 +414,11 @@ unsafeLastM = G.unsafeLastM
-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
-- contain at least @i+n@ elements.
-slice :: Unbox a => Int -- ^ @i@ starting index
- -> Int -- ^ @n@ length
- -> Vector a
- -> Vector a
+slice :: (HasCallStack, Unbox a)
+ => Int -- ^ @i@ starting index
+ -> Int -- ^ @n@ length
+ -> Vector a
+ -> Vector a
{-# INLINE slice #-}
slice = G.slice
@@ -886,7 +888,7 @@ reverse = G.reverse
-- often much more efficient.
--
-- > backpermute <0,3,2,3,1,0> =
-backpermute :: Unbox a => Vector a -> Vector Int -> Vector a
+backpermute :: (HasCallStack, Unbox a) => Vector a -> Vector Int -> Vector a
{-# INLINE backpermute #-}
backpermute = G.backpermute
@@ -2170,7 +2172,7 @@ unsafeCopy = G.unsafeCopy
-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
-- have the same length.
-copy :: (Unbox a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
+copy :: (HasCallStack, Unbox a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
{-# INLINE copy #-}
copy = G.copy
diff --git a/vector/src/Data/Vector/Unboxed/Mutable.hs b/vector/src/Data/Vector/Unboxed/Mutable.hs
index bc5f889a..a002038c 100644
--- a/vector/src/Data/Vector/Unboxed/Mutable.hs
+++ b/vector/src/Data/Vector/Unboxed/Mutable.hs
@@ -80,6 +80,7 @@ import qualified Data.Vector.Unboxed.Unsafe as U
import qualified Data.Vector.Generic.Mutable as G
import Data.Vector.Fusion.Util ( delayed_min )
import Control.Monad.Primitive
+import GHC.Stack (HasCallStack)
import Prelude ( Ord, Bool, Int, Maybe, Ordering(..) )
@@ -190,7 +191,7 @@ overlaps = G.overlaps
-- --------------
-- | Create a mutable vector of the given length.
-new :: (PrimMonad m, Unbox a) => Int -> m (MVector (PrimState m) a)
+new :: (HasCallStack, PrimMonad m, Unbox a) => Int -> m (MVector (PrimState m) a)
{-# INLINE new #-}
new = G.new
@@ -277,7 +278,7 @@ clone = G.clone
-- [('a',10),('b',20),('c',30)]
--
-- @since 0.5
-grow :: (PrimMonad m, Unbox a)
+grow :: (HasCallStack, PrimMonad m, Unbox a)
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
{-# INLINE grow #-}
grow = G.grow
@@ -312,7 +313,7 @@ clear = G.clear
-- >>> v <- MVU.generate 10 (\x -> x*x)
-- >>> MVU.read v 3
-- 9
-read :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> m a
+read :: (HasCallStack, PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> m a
{-# INLINE read #-}
read = G.read
@@ -334,29 +335,29 @@ readMaybe :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> m (Mayb
readMaybe = G.readMaybe
-- | Replace the element at the given position.
-write :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m ()
+write :: (HasCallStack, PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m ()
{-# INLINE write #-}
write = G.write
-- | Modify the element at the given position.
-modify :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
+modify :: (HasCallStack, PrimMonad m, Unbox a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
{-# INLINE modify #-}
modify = G.modify
-- | Modify the element at the given position using a monadic function.
--
-- @since 0.12.3.0
-modifyM :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
+modifyM :: (HasCallStack, PrimMonad m, Unbox a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
{-# INLINE modifyM #-}
modifyM = G.modifyM
-- | Swap the elements at the given positions.
-swap :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> Int -> m ()
+swap :: (HasCallStack, PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> Int -> m ()
{-# INLINE swap #-}
swap = G.swap
-- | Replace the element at the given position and return the old element.
-exchange :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m a
+exchange :: (HasCallStack, PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m a
{-# INLINE exchange #-}
exchange = G.exchange
@@ -404,7 +405,7 @@ set = G.set
-- | Copy a vector. The two vectors must have the same length and may not
-- overlap.
-copy :: (PrimMonad m, Unbox a)
+copy :: (HasCallStack, PrimMonad m, Unbox a)
=> MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
@@ -427,7 +428,7 @@ unsafeCopy = G.unsafeCopy
-- Otherwise, the copying is performed as if the source vector were
-- copied to a temporary vector and then the temporary vector was copied
-- to the target vector.
-move :: (PrimMonad m, Unbox a)
+move :: (HasCallStack, PrimMonad m, Unbox a)
=> MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()