Skip to content

Commit db3529f

Browse files
committed
Drop functions which don't enforce strictness
These functions require user to maintain invariant that all element of vector is in WHNF. And it's well known that this insvariant is difficult to enforce and its violations are usually invisible. Such spec leaks may be invisibe during testing only to cause pproblem in production. So it's better to remove them unless good use case for them appears
1 parent 8f60f2a commit db3529f

File tree

2 files changed

+7
-46
lines changed

2 files changed

+7
-46
lines changed

vector/src/Data/Vector/Strict.hs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
-- Immutable strict boxed vectors (that is, polymorphic arrays capable
2424
-- of holding any Haskell value). It is possible to create vector
2525
-- which contain bottom elements, either by using mutable interfaces
26-
-- (see "Data.Vector.Strict.Mutable") or functions that don't preserve
27-
-- strictness ('lazyFromArray').
26+
-- (see "Data.Vector.Strict.Mutable")
2827
--
2928
-- For unboxed arrays, use "Data.Vector.Unboxed".
30-
3129
module Data.Vector.Strict (
3230
-- * Boxed vectors
3331
Vector, MVector,
@@ -163,9 +161,9 @@ module Data.Vector.Strict (
163161
-- ** Lists
164162
toList, Data.Vector.Strict.fromList, Data.Vector.Strict.fromListN,
165163
-- ** Lazy vectors
166-
toLazy, fromLazy, lazyFromLazy,
164+
toLazy, fromLazy,
167165
-- ** Arrays
168-
toArray, fromArray, lazyFromArray, toArraySlice, unsafeFromArraySlice, unsafeLazyFromArraySlice,
166+
toArray, fromArray, toArraySlice, unsafeFromArraySlice,
169167

170168
-- ** Other vector types
171169
G.convert,
@@ -2476,11 +2474,6 @@ toLazy (Vector v) = v
24762474
fromLazy :: V.Vector a -> Vector a
24772475
fromLazy vec = liftRnfV (`seq` ()) v `seq` v where v = Vector vec
24782476

2479-
-- | /O(1)/ Convert lazy array to strict array. This function does not
2480-
-- evaluate vector elements.
2481-
lazyFromLazy :: V.Vector a -> Vector a
2482-
lazyFromLazy = Vector
2483-
24842477

24852478
-- Conversions - Arrays
24862479
-- -----------------------------
@@ -2492,15 +2485,7 @@ fromArray :: Array a -> Vector a
24922485
{-# INLINE fromArray #-}
24932486
fromArray arr = liftRnfV (`seq` ()) vec `seq` vec
24942487
where
2495-
vec = lazyFromArray arr
2496-
2497-
-- | /O(1)/ Convert an array to a vector. This function does not touch
2498-
-- content of array so resulting vector may contain bottoms.
2499-
--
2500-
-- @since NEXT
2501-
lazyFromArray :: Array a -> Vector a
2502-
{-# INLINE lazyFromArray #-}
2503-
lazyFromArray = Vector . V.fromArray
2488+
vec = Vector $ V.fromArray arr
25042489

25052490
-- | /O(n)/ Convert a vector to an array.
25062491
--
@@ -2537,25 +2522,8 @@ unsafeFromArraySlice ::
25372522
-> Vector a
25382523
{-# INLINE unsafeFromArraySlice #-}
25392524
unsafeFromArraySlice arr offset len = liftRnfV (`seq` ()) vec `seq` vec
2540-
where vec = unsafeLazyFromArraySlice arr offset len
2525+
where vec = Vector (V.unsafeFromArraySlice arr offset len)
25412526

2542-
-- | /O(1)/ Convert an array slice to a vector. This function does not touch
2543-
-- content of array so resulting vector may contain bottoms.
2544-
--
2545-
-- This function is very unsafe, because constructing an invalid
2546-
-- vector can yield almost all other safe functions in this module
2547-
-- unsafe. These are equivalent:
2548-
--
2549-
-- > unsafeFromArraySlice len offset === unsafeTake len . unsafeDrop offset . fromArray
2550-
--
2551-
-- @since 0.13.0.0
2552-
unsafeLazyFromArraySlice ::
2553-
Array a -- ^ Immutable boxed array.
2554-
-> Int -- ^ Offset
2555-
-> Int -- ^ Length
2556-
-> Vector a
2557-
{-# INLINE unsafeLazyFromArraySlice #-}
2558-
unsafeLazyFromArraySlice arr o l = Vector (V.unsafeFromArraySlice arr o l)
25592527

25602528

25612529
-- Conversions - Mutable vectors

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module Data.Vector.Strict.Mutable (
6767
-- ** Filling and copying
6868
set, copy, move, unsafeCopy, unsafeMove,
6969
-- ** Lazy arrays
70-
toLazy, fromLazy, lazyFromLazy,
70+
toLazy, fromLazy,
7171
-- ** Arrays
7272
fromMutableArray, toMutableArray,
7373

@@ -717,14 +717,7 @@ toLazy :: MVector s a -> MV.MVector s a
717717
{-# INLINE toLazy #-}
718718
toLazy (MVector vec) = vec
719719

720-
-- | /O(1)/ Convert lazy mutable vector to strict mutable
721-
-- vector. Vectors will share mutable buffer. This function does not
722-
-- evaluate vector elements to WHNF.
723-
lazyFromLazy :: MV.MVector s a -> MVector s a
724-
{-# INLINE lazyFromLazy #-}
725-
lazyFromLazy = MVector
726-
727-
-- | /O(1)/ Convert lazy mutable vector to strict mutable
720+
-- | /O(n)/ Convert lazy mutable vector to strict mutable
728721
-- vector. Vectors will share mutable buffer. This function evaluates
729722
-- vector elements to WHNF.
730723
fromLazy :: PrimMonad m => MV.MVector (PrimState m) a -> m (MVector (PrimState m) a)

0 commit comments

Comments
 (0)