Skip to content

Commit edd57a2

Browse files
committed
Similarly add HasCallStack to functions working on mutable vectors
- new - grow - read,write - modify,modifyM - swap,exchange,copy,move
1 parent 70f477c commit edd57a2

5 files changed

Lines changed: 54 additions & 50 deletions

File tree

‎vector/src/Data/Vector/Mutable.hs‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import Data.Vector.Mutable.Unsafe (MVector(..))
7777
import Data.Vector.Pattern
7878
import Data.Primitive.Array
7979
import Control.Monad.Primitive
80+
import GHC.Stack (HasCallStack)
8081

8182
import Prelude( Ord, Bool, Ordering(..), Int, Maybe, (<$>) )
8283

@@ -209,7 +210,7 @@ overlaps = G.overlaps
209210
-- --------------
210211

211212
-- | Create a mutable vector of the given length.
212-
new :: PrimMonad m => Int -> m (MVector (PrimState m) a)
213+
new :: (HasCallStack, PrimMonad m) => Int -> m (MVector (PrimState m) a)
213214
{-# INLINE new #-}
214215
new = G.new
215216

@@ -293,7 +294,7 @@ clone = G.clone
293294
-- [10,20,30]
294295
--
295296
-- @since 0.5
296-
grow :: PrimMonad m
297+
grow :: (HasCallStack, PrimMonad m)
297298
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
298299
{-# INLINE grow #-}
299300
grow = G.grow
@@ -328,7 +329,7 @@ clear = G.clear
328329
-- >>> v <- MV.generate 10 (\x -> x*x)
329330
-- >>> MV.read v 3
330331
-- 9
331-
read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a
332+
read :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> m a
332333
{-# INLINE read #-}
333334
read = G.read
334335

@@ -350,29 +351,29 @@ readMaybe :: (PrimMonad m) => MVector (PrimState m) a -> Int -> m (Maybe a)
350351
readMaybe = G.readMaybe
351352

352353
-- | Replace the element at the given position.
353-
write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
354+
write :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m ()
354355
{-# INLINE write #-}
355356
write = G.write
356357

357358
-- | Modify the element at the given position.
358-
modify :: PrimMonad m => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
359+
modify :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
359360
{-# INLINE modify #-}
360361
modify = G.modify
361362

362363
-- | Modify the element at the given position using a monadic function.
363364
--
364365
-- @since 0.12.3.0
365-
modifyM :: (PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
366+
modifyM :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
366367
{-# INLINE modifyM #-}
367368
modifyM = G.modifyM
368369

369370
-- | Swap the elements at the given positions.
370-
swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m ()
371+
swap :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> Int -> m ()
371372
{-# INLINE swap #-}
372373
swap = G.swap
373374

374375
-- | Replace the element at the given position and return the old element.
375-
exchange :: (PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
376+
exchange :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
376377
{-# INLINE exchange #-}
377378
exchange = G.exchange
378379

@@ -420,7 +421,7 @@ set = G.set
420421

421422
-- | Copy a vector. The two vectors must have the same length and may not
422423
-- overlap.
423-
copy :: PrimMonad m => MVector (PrimState m) a -- ^ target
424+
copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
424425
-> MVector (PrimState m) a -- ^ source
425426
-> m ()
426427
{-# INLINE copy #-}
@@ -441,7 +442,7 @@ unsafeCopy = G.unsafeCopy
441442
-- Otherwise, the copying is performed as if the source vector were
442443
-- copied to a temporary vector and then the temporary vector was copied
443444
-- to the target vector.
444-
move :: PrimMonad m => MVector (PrimState m) a -- ^ target
445+
move :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
445446
-> MVector (PrimState m) a -- ^ source
446447
-> m ()
447448
{-# INLINE move #-}

‎vector/src/Data/Vector/Primitive/Mutable.hs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ overlaps = G.overlaps
192192
-- --------------
193193

194194
-- | Create a mutable vector of the given length.
195-
new :: (PrimMonad m, Prim a) => Int -> m (MVector (PrimState m) a)
195+
new :: (HasCallStack, PrimMonad m, Prim a) => Int -> m (MVector (PrimState m) a)
196196
{-# INLINE new #-}
197197
new = G.new
198198

@@ -279,7 +279,7 @@ clone = G.clone
279279
-- [10,20,30]
280280
--
281281
-- @since 0.5
282-
grow :: (PrimMonad m, Prim a)
282+
grow :: (HasCallStack, PrimMonad m, Prim a)
283283
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
284284
{-# INLINE grow #-}
285285
grow = G.grow
@@ -314,7 +314,7 @@ clear = G.clear
314314
-- >>> v <- MVP.generate 10 (\x -> x*x)
315315
-- >>> MVP.read v 3
316316
-- 9
317-
read :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m a
317+
read :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m a
318318
{-# INLINE read #-}
319319
read = G.read
320320

@@ -336,29 +336,29 @@ readMaybe :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m (Maybe
336336
readMaybe = G.readMaybe
337337

338338
-- | Replace the element at the given position.
339-
write :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m ()
339+
write :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m ()
340340
{-# INLINE write #-}
341341
write = G.write
342342

343343
-- | Modify the element at the given position.
344-
modify :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
344+
modify :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
345345
{-# INLINE modify #-}
346346
modify = G.modify
347347

348348
-- | Modify the element at the given position using a monadic function.
349349
--
350350
-- @since 0.12.3.0
351-
modifyM :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
351+
modifyM :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
352352
{-# INLINE modifyM #-}
353353
modifyM = G.modifyM
354354

355355
-- | Swap the elements at the given positions.
356-
swap :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m ()
356+
swap :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m ()
357357
{-# INLINE swap #-}
358358
swap = G.swap
359359

360360
-- | Replace the element at the given position and return the old element.
361-
exchange :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m a
361+
exchange :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m a
362362
{-# INLINE exchange #-}
363363
exchange = G.exchange
364364

@@ -406,7 +406,7 @@ set = G.set
406406

407407
-- | Copy a vector. The two vectors must have the same length and may not
408408
-- overlap.
409-
copy :: (PrimMonad m, Prim a)
409+
copy :: (HasCallStack, PrimMonad m, Prim a)
410410
=> MVector (PrimState m) a -- ^ target
411411
-> MVector (PrimState m) a -- ^ source
412412
-> m ()
@@ -429,7 +429,7 @@ unsafeCopy = G.unsafeCopy
429429
-- Otherwise, the copying is performed as if the source vector were
430430
-- copied to a temporary vector and then the temporary vector was copied
431431
-- to the target vector.
432-
move :: (PrimMonad m, Prim a)
432+
move :: (HasCallStack, PrimMonad m, Prim a)
433433
=> MVector (PrimState m) a -- ^ target
434434
-> MVector (PrimState m) a -- ^ source
435435
-> m ()

‎vector/src/Data/Vector/Storable/Mutable.hs‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import Foreign.ForeignPtr (ForeignPtr)
8686
import Foreign.Ptr (Ptr)
8787

8888
import Control.Monad.Primitive
89+
import GHC.Stack (HasCallStack)
8990

9091
import Prelude (IO, Int, Ord, Bool, Maybe, Ordering(..) )
9192

@@ -197,7 +198,7 @@ overlaps = G.overlaps
197198
-- --------------
198199

199200
-- | Create a mutable vector of the given length.
200-
new :: (PrimMonad m, Storable a) => Int -> m (MVector (PrimState m) a)
201+
new :: (HasCallStack, PrimMonad m, Storable a) => Int -> m (MVector (PrimState m) a)
201202
{-# INLINE new #-}
202203
new = G.new
203204

@@ -284,7 +285,7 @@ clone = G.clone
284285
-- [10,20,30]
285286
--
286287
-- @since 0.5
287-
grow :: (PrimMonad m, Storable a)
288+
grow :: (HasCallStack, PrimMonad m, Storable a)
288289
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
289290
{-# INLINE grow #-}
290291
grow = G.grow
@@ -319,7 +320,7 @@ clear = G.clear
319320
-- >>> v <- MVS.generate 10 (\x -> x*x)
320321
-- >>> MVS.read v 3
321322
-- 9
322-
read :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> m a
323+
read :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> m a
323324
{-# INLINE read #-}
324325
read = G.read
325326

@@ -342,30 +343,30 @@ readMaybe = G.readMaybe
342343

343344
-- | Replace the element at the given position.
344345
write
345-
:: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m ()
346+
:: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m ()
346347
{-# INLINE write #-}
347348
write = G.write
348349

349350
-- | Modify the element at the given position.
350-
modify :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
351+
modify :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
351352
{-# INLINE modify #-}
352353
modify = G.modify
353354

354355
-- | Modify the element at the given position using a monadic function.
355356
--
356357
-- @since 0.12.3.0
357-
modifyM :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
358+
modifyM :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
358359
{-# INLINE modifyM #-}
359360
modifyM = G.modifyM
360361

361362
-- | Swap the elements at the given positions.
362363
swap
363-
:: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> Int -> m ()
364+
:: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> Int -> m ()
364365
{-# INLINE swap #-}
365366
swap = G.swap
366367

367368
-- | Replace the element at the given position and return the old element.
368-
exchange :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m a
369+
exchange :: (HasCallStack, PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m a
369370
{-# INLINE exchange #-}
370371
exchange = G.exchange
371372

@@ -413,7 +414,7 @@ set = G.set
413414

414415
-- | Copy a vector. The two vectors must have the same length and may not
415416
-- overlap.
416-
copy :: (PrimMonad m, Storable a)
417+
copy :: (HasCallStack, PrimMonad m, Storable a)
417418
=> MVector (PrimState m) a -- ^ target
418419
-> MVector (PrimState m) a -- ^ source
419420
-> m ()
@@ -436,7 +437,7 @@ unsafeCopy = G.unsafeCopy
436437
-- Otherwise, the copying is performed as if the source vector were
437438
-- copied to a temporary vector and then the temporary vector was copied
438439
-- to the target vector.
439-
move :: (PrimMonad m, Storable a)
440+
move :: (HasCallStack, PrimMonad m, Storable a)
440441
=> MVector (PrimState m) a -- ^ target
441442
-> MVector (PrimState m) a -- ^ source
442443
-> m ()

‎vector/src/Data/Vector/Strict/Mutable.hs‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import qualified Data.Vector.Mutable as MV
8383
import Data.Vector.Strict.Mutable.Unsafe as U (MVector(..))
8484
import Data.Vector.Strict.Pattern as U
8585
import Control.Monad.Primitive
86+
import GHC.Stack (HasCallStack)
8687

8788
import Prelude ( Ord, Bool, Int, Maybe, Ordering(..), Monad(..), (<$>), ($))
8889

@@ -265,7 +266,7 @@ overlaps = G.overlaps
265266
-- | Create a mutable vector of the given length.
266267
--
267268
-- @since 0.13.2.0
268-
new :: PrimMonad m => Int -> m (MVector (PrimState m) a)
269+
new :: (HasCallStack, PrimMonad m) => Int -> m (MVector (PrimState m) a)
269270
{-# INLINE new #-}
270271
new = G.new
271272

@@ -355,7 +356,7 @@ clone = G.clone
355356
-- [10,20,30]
356357
--
357358
-- @since 0.13.2.0
358-
grow :: PrimMonad m
359+
grow :: (HasCallStack, PrimMonad m)
359360
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
360361
{-# INLINE grow #-}
361362
grow = G.grow
@@ -394,7 +395,7 @@ clear = G.clear
394395
-- 9
395396
--
396397
-- @since 0.13.2.0
397-
read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a
398+
read :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> m a
398399
{-# INLINE read #-}
399400
read = G.read
400401

@@ -420,35 +421,35 @@ readMaybe = G.readMaybe
420421
-- | Replace the element at the given position.
421422
--
422423
-- @since 0.13.2.0
423-
write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
424+
write :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m ()
424425
{-# INLINE write #-}
425426
write = G.write
426427

427428
-- | Modify the element at the given position.
428429
--
429430
-- @since 0.13.2.0
430-
modify :: PrimMonad m => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
431+
modify :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
431432
{-# INLINE modify #-}
432433
modify = G.modify
433434

434435
-- | Modify the element at the given position using a monadic function.
435436
--
436437
-- @since 0.13.2.0
437-
modifyM :: (PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
438+
modifyM :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
438439
{-# INLINE modifyM #-}
439440
modifyM = G.modifyM
440441

441442
-- | Swap the elements at the given positions.
442443
--
443444
-- @since 0.13.2.0
444-
swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m ()
445+
swap :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> Int -> m ()
445446
{-# INLINE swap #-}
446447
swap = G.swap
447448

448449
-- | Replace the element at the given position and return the old element.
449450
--
450451
-- @since 0.13.2.0
451-
exchange :: (PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
452+
exchange :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
452453
{-# INLINE exchange #-}
453454
exchange = G.exchange
454455

@@ -510,7 +511,7 @@ set = G.set
510511
-- overlap.
511512
--
512513
-- @since 0.13.2.0
513-
copy :: PrimMonad m => MVector (PrimState m) a -- ^ target
514+
copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
514515
-> MVector (PrimState m) a -- ^ source
515516
-> m ()
516517
{-# INLINE copy #-}
@@ -535,7 +536,7 @@ unsafeCopy = G.unsafeCopy
535536
-- to the target vector.
536537
--
537538
-- @since 0.13.2.0
538-
move :: PrimMonad m => MVector (PrimState m) a -- ^ target
539+
move :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
539540
-> MVector (PrimState m) a -- ^ source
540541
-> m ()
541542
{-# INLINE move #-}

0 commit comments

Comments
 (0)