Skip to content

Commit d0f42e0

Browse files
authored
Merge pull request #574 from haskell/has_call_stack_mut
Add HasCallStack to all specilization when generic function has one
2 parents a0421dd + d4a91a3 commit d0f42e0

10 files changed

Lines changed: 95 additions & 84 deletions

File tree

‎vector/src/Data/Vector.hs‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ import Data.Vector.Mutable.Unsafe ( MVector )
187187
import Data.Vector.Unsafe ( Vector(..) )
188188
import qualified Data.Vector.Unsafe as U
189189
import qualified Data.Vector.Generic as G
190+
import GHC.Stack (HasCallStack)
190191

191192
import Control.Monad.ST ( ST )
192193
import Control.Monad.Primitive
@@ -242,7 +243,7 @@ null = G.null
242243
-- --------
243244

244245
-- | O(1) Indexing.
245-
(!) :: Vector a -> Int -> a
246+
(!) :: HasCallStack => Vector a -> Int -> a
246247
{-# INLINE (!) #-}
247248
(!) = (G.!)
248249

@@ -297,7 +298,7 @@ unsafeLast = G.unsafeLast
297298
--
298299
-- Here, no references to @v@ are retained because indexing (but /not/ the
299300
-- element) is evaluated eagerly.
300-
indexM :: Monad m => Vector a -> Int -> m a
301+
indexM :: (HasCallStack, Monad m) => Vector a -> Int -> m a
301302
{-# INLINE indexM #-}
302303
indexM = G.indexM
303304

@@ -336,10 +337,11 @@ unsafeLastM = G.unsafeLastM
336337

337338
-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
338339
-- contain at least @i+n@ elements.
339-
slice :: Int -- ^ @i@ starting index
340-
-> Int -- ^ @n@ length
341-
-> Vector a
342-
-> Vector a
340+
slice :: HasCallStack
341+
=> Int -- ^ @i@ starting index
342+
-> Int -- ^ @n@ length
343+
-> Vector a
344+
-> Vector a
343345
{-# INLINE slice #-}
344346
slice = G.slice
345347

@@ -805,7 +807,7 @@ reverse = G.reverse
805807
-- often much more efficient.
806808
--
807809
-- > backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a>
808-
backpermute :: Vector a -> Vector Int -> Vector a
810+
backpermute :: HasCallStack => Vector a -> Vector Int -> Vector a
809811
{-# INLINE backpermute #-}
810812
backpermute = G.backpermute
811813

@@ -2113,7 +2115,7 @@ unsafeCopy = G.unsafeCopy
21132115

21142116
-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
21152117
-- have the same length.
2116-
copy :: PrimMonad m => MVector (PrimState m) a -> Vector a -> m ()
2118+
copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
21172119
{-# INLINE copy #-}
21182120
copy = G.copy
21192121

‎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.hs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ null = G.null
199199
-- --------
200200

201201
-- | O(1) Indexing.
202-
(!) :: Prim a => Vector a -> Int -> a
202+
(!) :: (HasCallStack, Prim a) => Vector a -> Int -> a
203203
{-# INLINE (!) #-}
204204
(!) = (G.!)
205205

@@ -254,7 +254,7 @@ unsafeLast = G.unsafeLast
254254
--
255255
-- Here, no references to @v@ are retained because indexing (but /not/ the
256256
-- element) is evaluated eagerly.
257-
indexM :: (Prim a, Monad m) => Vector a -> Int -> m a
257+
indexM :: (HasCallStack, Prim a, Monad m) => Vector a -> Int -> m a
258258
{-# INLINE indexM #-}
259259
indexM = G.indexM
260260

@@ -293,7 +293,7 @@ unsafeLastM = G.unsafeLastM
293293

294294
-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
295295
-- contain at least @i+n@ elements.
296-
slice :: Prim a
296+
slice :: (HasCallStack, Prim a)
297297
=> Int -- ^ @i@ starting index
298298
-> Int -- ^ @n@ length
299299
-> Vector a
@@ -716,7 +716,7 @@ reverse = G.reverse
716716
-- often much more efficient.
717717
--
718718
-- > backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a>
719-
backpermute :: Prim a => Vector a -> Vector Int -> Vector a
719+
backpermute :: (HasCallStack, Prim a) => Vector a -> Vector Int -> Vector a
720720
{-# INLINE backpermute #-}
721721
backpermute = G.backpermute
722722

@@ -1905,7 +1905,7 @@ unsafeCopy = G.unsafeCopy
19051905

19061906
-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
19071907
-- have the same length.
1908-
copy :: (Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
1908+
copy :: (HasCallStack, Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
19091909
{-# INLINE copy #-}
19101910
copy = G.copy
19111911

‎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.hs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ import qualified Data.Vector.Generic as G
173173
import Data.Vector.Storable.Mutable ( MVector, pattern MVector )
174174
import Data.Vector.Storable.Unsafe (Vector(..))
175175
import qualified Data.Vector.Storable.Unsafe as U
176+
import GHC.Stack (HasCallStack)
176177

177178
import Control.Monad.ST ( ST )
178179
import Control.Monad.Primitive
@@ -203,7 +204,7 @@ null = G.null
203204
-- --------
204205

205206
-- | O(1) Indexing.
206-
(!) :: Storable a => Vector a -> Int -> a
207+
(!) :: (HasCallStack, Storable a) => Vector a -> Int -> a
207208
{-# INLINE (!) #-}
208209
(!) = (G.!)
209210

@@ -258,7 +259,7 @@ unsafeLast = G.unsafeLast
258259
--
259260
-- Here, no references to @v@ are retained because indexing (but /not/ the
260261
-- element) is evaluated eagerly.
261-
indexM :: (Storable a, Monad m) => Vector a -> Int -> m a
262+
indexM :: (HasCallStack, Storable a, Monad m) => Vector a -> Int -> m a
262263
{-# INLINE indexM #-}
263264
indexM = G.indexM
264265

@@ -297,7 +298,7 @@ unsafeLastM = G.unsafeLastM
297298

298299
-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
299300
-- contain at least @i+n@ elements.
300-
slice :: Storable a
301+
slice :: (HasCallStack, Storable a)
301302
=> Int -- ^ @i@ starting index
302303
-> Int -- ^ @n@ length
303304
-> Vector a
@@ -720,7 +721,7 @@ reverse = G.reverse
720721
-- often much more efficient.
721722
--
722723
-- > backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a>
723-
backpermute :: Storable a => Vector a -> Vector Int -> Vector a
724+
backpermute :: (HasCallStack, Storable a) => Vector a -> Vector Int -> Vector a
724725
{-# INLINE backpermute #-}
725726
backpermute = G.backpermute
726727

@@ -1945,7 +1946,7 @@ unsafeCopy = G.unsafeCopy
19451946

19461947
-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
19471948
-- have the same length.
1948-
copy :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
1949+
copy :: (HasCallStack, Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
19491950
{-# INLINE copy #-}
19501951
copy = G.copy
19511952

0 commit comments

Comments
 (0)