Skip to content

Commit 7ef301e

Browse files
committed
Move compatibility patterns into Unsafe module
In this case DEPRECATED must explicitly mention that it's deprecates name from data namespace ExplicitNamespaces extension is require for GHC < 9.10
1 parent fa2b1e1 commit 7ef301e

11 files changed

Lines changed: 62 additions & 51 deletions

File tree

vector/src/Data/Vector/Mutable.hs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
module Data.Vector.Mutable (
2323
-- * Mutable boxed vectors
24-
MVector, IOVector, STVector,
25-
pattern MVector,
24+
MVector(MVector), IOVector, STVector,
2625

2726
-- * Accessors
2827

@@ -74,20 +73,14 @@ module Data.Vector.Mutable (
7473
) where
7574

7675
import qualified Data.Vector.Generic.Mutable as G
77-
import Data.Vector.Mutable.Unsafe (MVector)
78-
import qualified Data.Vector.Mutable.Unsafe as U
76+
import Data.Vector.Mutable.Unsafe (MVector(..), pattern MVector)
7977
import Data.Primitive.Array
8078
import Control.Monad.Primitive
8179

8280
import Prelude( Ord, Bool, Ordering(..), Int, Maybe, (<$>) )
8381

8482
#include "vector.h"
8583

86-
pattern MVector :: Int -> Int -> MutableArray s a -> MVector s a
87-
pattern MVector i j arr = U.UnsafeMVector i j arr
88-
{-# COMPLETE MVector #-}
89-
{-# DEPRECATED MVector "Use MVector exported from \"Data.Vector.Mutable.Unsafe\"" #-}
90-
9184
type IOVector = MVector RealWorld
9285
type STVector s = MVector s
9386

@@ -102,14 +95,14 @@ fromMutableArray :: PrimMonad m => MutableArray (PrimState m) a -> m (MVector (P
10295
{-# INLINE fromMutableArray #-}
10396
fromMutableArray marr =
10497
let size = sizeofMutableArray marr
105-
in MVector 0 size <$> cloneMutableArray marr 0 size
98+
in UnsafeMVector 0 size <$> cloneMutableArray marr 0 size
10699

107100
-- | /O(n)/ Make a copy of a mutable vector into a new mutable array.
108101
--
109102
-- @since 0.12.2.0
110103
toMutableArray :: PrimMonad m => MVector (PrimState m) a -> m (MutableArray (PrimState m) a)
111104
{-# INLINE toMutableArray #-}
112-
toMutableArray (MVector offset size marr) = cloneMutableArray marr offset size
105+
toMutableArray (UnsafeMVector offset size marr) = cloneMutableArray marr offset size
113106

114107

115108
-- Length information

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE MultiParamTypeClasses #-}
55
{-# LANGUAGE RoleAnnotations #-}
66
{-# LANGUAGE TypeFamilies #-}
7+
{-# LANGUAGE PatternSynonyms #-}
78
-- |
89
-- This module exposes internal representation of mutable lazy boxed
910
-- vector and functions that work on that representation directly (as
@@ -13,6 +14,8 @@
1314
-- generally unsafe and may violate memory safety
1415
module Data.Vector.Mutable.Unsafe
1516
( MVector(..)
17+
-- * Deprecated
18+
, pattern MVector
1619
) where
1720

1821
import Control.Monad (when)
@@ -38,6 +41,11 @@ data MVector s a = UnsafeMVector
3841
-- ^ Underlying mutable array
3942
}
4043

44+
pattern MVector :: Int -> Int -> MutableArray s a -> MVector s a
45+
pattern MVector i j arr = UnsafeMVector i j arr
46+
{-# COMPLETE MVector #-}
47+
{-# DEPRECATED data MVector "Use MVector exported from \"Data.Vector.Mutable.Unsafe\"" #-}
48+
4149

4250
-- NOTE: This seems unsafe, see http://trac.haskell.org/vector/ticket/54
4351
{-

vector/src/Data/Vector/Primitive.hs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
module Data.Vector.Primitive (
2727
-- * Primitive vectors
28-
Vector, MVector(MVector), pattern Vector,
28+
Vector(Vector), MVector(MVector),
2929

3030
-- * Accessors
3131

@@ -166,10 +166,9 @@ import Control.Applicative (Applicative)
166166
import qualified Data.Vector.Generic as G
167167
import Data.Vector.Primitive.Unsafe (Vector,unsafeCoerceVector,unsafeCast)
168168
import qualified Data.Vector.Primitive.Unsafe as U
169-
import Data.Vector.Primitive.Mutable.Unsafe (MVector)
170-
import Data.Vector.Primitive.Mutable (pattern MVector)
169+
import Data.Vector.Primitive.Mutable.Unsafe (MVector,pattern MVector)
170+
171171
import Data.Primitive ( Prim )
172-
import Data.Primitive.ByteArray
173172

174173
import Control.Monad.ST ( ST )
175174
import Control.Monad.Primitive
@@ -178,11 +177,6 @@ import Prelude
178177
( Eq, Ord, Num, Enum, Monoid, Traversable, Monad, Bool, Ordering(..), Int, Maybe, Either
179178
, (==))
180179

181-
pattern Vector :: Int -> Int -> ByteArray -> Vector a
182-
pattern Vector i j arr = U.UnsafeVector i j arr
183-
{-# COMPLETE Vector #-}
184-
{-# DEPRECATED Vector "Use Vector constructor exported from \"Data.Vector.Primitive.Unsafe\"" #-}
185-
186180
-- Length
187181
-- ------
188182

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{-# LANGUAGE MultiParamTypeClasses #-}
44
{-# LANGUAGE RoleAnnotations #-}
55
{-# LANGUAGE ScopedTypeVariables #-}
6-
{-# LANGUAGE PatternSynonyms #-}
76
-- |
87
-- Module : Data.Vector.Primitive.Mutable
98
-- Copyright : (c) Roman Leshchinskiy 2008-2010
@@ -20,8 +19,7 @@
2019

2120
module Data.Vector.Primitive.Mutable (
2221
-- * Mutable vectors of primitive types
23-
MVector, IOVector, STVector,
24-
pattern MVector,
22+
MVector(MVector), IOVector, STVector,
2523

2624
-- * Accessors
2725

@@ -73,7 +71,6 @@ module Data.Vector.Primitive.Mutable (
7371

7472
import qualified Data.Vector.Generic.Mutable as G
7573
import Data.Primitive ( Prim )
76-
import Data.Primitive.ByteArray
7774
import Data.Vector.Primitive.Mutable.Unsafe
7875
(MVector,unsafeCoerceMVector,unsafeCast)
7976
import qualified Data.Vector.Primitive.Mutable.Unsafe as U
@@ -84,11 +81,6 @@ import Prelude ( Ord, Bool, Int, Maybe, Ordering(..) )
8481
#include "vector.h"
8582

8683

87-
pattern MVector :: Int -> Int -> MutableByteArray s -> MVector s a
88-
pattern MVector i j arr = U.UnsafeMVector i j arr
89-
{-# COMPLETE MVector #-}
90-
{-# DEPRECATED MVector "Use MVector exported from \"Data.Vector.Primitive.Mutable.Unsafe\"" #-}
91-
9284
type IOVector = MVector RealWorld
9385
type STVector s = MVector s
9486

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE TypeFamilies #-}
55
{-# LANGUAGE RoleAnnotations #-}
66
{-# LANGUAGE ScopedTypeVariables #-}
7+
{-# LANGUAGE PatternSynonyms #-}
78
-- |
89
-- This module exposes internal representation of mutable vectors backed by
910
-- single 'ByteArray' and functions that work on that representation
@@ -15,6 +16,8 @@ module Data.Vector.Primitive.Mutable.Unsafe
1516
( MVector(..)
1617
, unsafeCoerceMVector
1718
, unsafeCast
19+
-- * Deprecated
20+
, pattern MVector
1821
) where
1922

2023
import qualified Data.Vector.Generic.Mutable as MG
@@ -52,6 +55,12 @@ data MVector s a = UnsafeMVector
5255
-- ^ Underlying mutable byte array
5356
}
5457

58+
pattern MVector :: Int -> Int -> MutableByteArray s -> MVector s a
59+
pattern MVector i j arr = UnsafeMVector i j arr
60+
{-# COMPLETE MVector #-}
61+
{-# DEPRECATED data MVector "Use MVector exported from \"Data.Vector.Primitive.Mutable.Unsafe\"" #-}
62+
63+
5564
-- | /O(1)/ Unsafely coerce a mutable vector from one element type to another,
5665
-- representationally equal type. The operation just changes the type of the
5766
-- underlying pointer and does not modify the elements.

vector/src/Data/Vector/Primitive/Unsafe.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE TypeFamilies #-}
55
{-# LANGUAGE RoleAnnotations #-}
66
{-# LANGUAGE ScopedTypeVariables #-}
7+
{-# LANGUAGE PatternSynonyms #-}
78
-- |
89
-- This module exposes internal representation of vectors backed by
910
-- single 'ByteArray' and functions that work on that representation
@@ -16,6 +17,8 @@ module Data.Vector.Primitive.Unsafe
1617
Vector(..)
1718
, unsafeCoerceVector
1819
, unsafeCast
20+
-- * Deprecated
21+
, pattern Vector
1922
) where
2023

2124
import qualified Data.Vector.Generic as G
@@ -41,6 +44,8 @@ import Data.Coerce
4144
import Unsafe.Coerce
4245

4346
import Data.Vector.Primitive.Mutable.Unsafe (MVector(..))
47+
48+
4449
----------------------------------------------------------------
4550
-- Immutable
4651
----------------------------------------------------------------
@@ -59,6 +64,12 @@ data Vector a = UnsafeVector
5964

6065
type instance G.Mutable Vector = MVector
6166

67+
pattern Vector :: Int -> Int -> ByteArray -> Vector a
68+
pattern Vector i j arr = UnsafeVector i j arr
69+
{-# COMPLETE Vector #-}
70+
{-# DEPRECATED data Vector "Use Vector constructor exported from \"Data.Vector.Primitive.Unsafe\"" #-}
71+
72+
6273
-- | /O(1)/ Unsafely coerce an immutable vector from one element type to another,
6374
-- representationally equal type. The operation just changes the type of the
6475
-- underlying pointer and does not modify the elements.

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
module Data.Vector.Storable.Mutable(
2323
-- * Mutable vectors of 'Storable' types
24-
MVector, IOVector, STVector,
25-
pattern MVector,
24+
MVector(MVector), IOVector, STVector,
2625

2726
-- * Accessors
2827

@@ -86,19 +85,12 @@ import qualified Data.Vector.Storable.Mutable.Unsafe as U
8685
import Foreign.Storable
8786

8887
import Control.Monad.Primitive
89-
import Foreign.ForeignPtr (ForeignPtr)
9088

9189
import Prelude (Int, Ord, Bool, Maybe, Ordering(..) )
9290

9391
#include "vector.h"
9492

9593

96-
pattern MVector :: Int -> ForeignPtr a -> MVector s a
97-
pattern MVector i ptr = U.UnsafeMVector i ptr
98-
{-# COMPLETE MVector #-}
99-
{-# DEPRECATED MVector "Use MVector exported from Data.Vector.Strict.Mutable.Unsafe" #-}
100-
101-
10294
-- Length information
10395
-- ------------------
10496

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
{-# LANGUAGE MultiParamTypeClasses #-}
55
{-# LANGUAGE RoleAnnotations #-}
66
{-# LANGUAGE ScopedTypeVariables #-}
7+
{-# LANGUAGE PatternSynonyms #-}
8+
{-# LANGUAGE ExplicitNamespaces #-}
79
-- |
810
-- This module exposes internal representation of mutable vectors
911
-- based on 'Storable' and functions that work on that representation
@@ -22,6 +24,8 @@ module Data.Vector.Storable.Mutable.Unsafe
2224
, unsafeFromForeignPtr, unsafeFromForeignPtr0
2325
, unsafeToForeignPtr, unsafeToForeignPtr0
2426
, unsafeWith
27+
-- * Deprecated
28+
, pattern MVector
2529
) where
2630

2731
import Control.DeepSeq (NFData(rnf), NFData1(liftRnf))
@@ -65,6 +69,12 @@ data MVector s a = UnsafeMVector
6569
-- ^ Underlying buffer as a `ForeignPtr`, which is allowed to be mutated
6670
}
6771

72+
pattern MVector :: Int -> ForeignPtr a -> MVector s a
73+
pattern MVector i ptr = UnsafeMVector i ptr
74+
{-# COMPLETE MVector #-}
75+
{-# DEPRECATED data MVector "Use MVector exported from Data.Vector.Strict.Mutable.Unsafe" #-}
76+
77+
6878
type IOVector = MVector RealWorld
6979
type STVector s = MVector s
7080

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
-- are set to ⊥.
2626
module Data.Vector.Strict.Mutable (
2727
-- * Mutable boxed vectors
28-
MVector, IOVector, STVector,
29-
pattern MVector,
28+
MVector(U.MVector), IOVector, STVector,
3029

3130
-- * Accessors
3231

@@ -81,19 +80,13 @@ module Data.Vector.Strict.Mutable (
8180
import Data.Primitive.Array
8281
import qualified Data.Vector.Generic.Mutable as G
8382
import qualified Data.Vector.Mutable as MV
84-
import Data.Vector.Strict.Mutable.Unsafe (MVector)
85-
import qualified Data.Vector.Strict.Mutable.Unsafe as U
83+
import Data.Vector.Strict.Mutable.Unsafe as U (MVector(..), pattern MVector)
8684
import Control.Monad.Primitive
8785

8886
import Prelude ( Ord, Bool, Int, Maybe, Ordering(..), Monad(..), (<$>), ($))
8987

9088
#include "vector.h"
9189

92-
pattern MVector :: MV.MVector s a -> MVector s a
93-
pattern MVector v = U.UnsafeMVector v
94-
{-# COMPLETE MVector #-}
95-
{-# DEPRECATED MVector "Use MVector constructor exported from \"Data.Vector.Strict.Unsafe\"" #-}
96-
9790
type IOVector = MVector RealWorld
9891
type STVector s = MVector s
9992

@@ -105,15 +98,15 @@ type STVector s = MVector s
10598
-- vector. Vectors will share mutable buffer
10699
toLazy :: MVector s a -> MV.MVector s a
107100
{-# INLINE toLazy #-}
108-
toLazy (MVector vec) = vec
101+
toLazy (UnsafeMVector vec) = vec
109102

110103
-- | /O(n)/ Convert lazy mutable vector to strict mutable
111104
-- vector. Vectors will share mutable buffer. This function evaluates
112105
-- vector elements to WHNF.
113106
fromLazy :: PrimMonad m => MV.MVector (PrimState m) a -> m (MVector (PrimState m) a)
114107
fromLazy mvec = stToPrim $ do
115108
G.foldM' (\_ !_ -> return ()) () mvec
116-
return $ MVector mvec
109+
return $ UnsafeMVector mvec
117110

118111

119112
-- Conversions - Arrays
@@ -126,7 +119,7 @@ fromLazy mvec = stToPrim $ do
126119
fromMutableArray :: PrimMonad m => MutableArray (PrimState m) a -> m (MVector (PrimState m) a)
127120
{-# INLINE fromMutableArray #-}
128121
fromMutableArray marr = stToPrim $ do
129-
mvec <- MVector <$> MV.fromMutableArray marr
122+
mvec <- UnsafeMVector <$> MV.fromMutableArray marr
130123
G.foldM' (\_ !_ -> return ()) () mvec
131124
return mvec
132125

@@ -135,7 +128,7 @@ fromMutableArray marr = stToPrim $ do
135128
-- @since 0.13.2.0
136129
toMutableArray :: PrimMonad m => MVector (PrimState m) a -> m (MutableArray (PrimState m) a)
137130
{-# INLINE toMutableArray #-}
138-
toMutableArray (MVector v) = MV.toMutableArray v
131+
toMutableArray (UnsafeMVector v) = MV.toMutableArray v
139132

140133

141134
-- Length information

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{-# LANGUAGE TypeFamilies #-}
77
{-# LANGUAGE TypeApplications #-}
88
{-# LANGUAGE ScopedTypeVariables #-}
9+
{-# LANGUAGE PatternSynonyms #-}
910
-- |
1011
-- This module exposes internal representation of mutable strict boxed
1112
-- vector and functions that work on that representation directly (as
@@ -15,6 +16,8 @@
1516
-- generally unsafe and may violate memory safety
1617
module Data.Vector.Strict.Mutable.Unsafe
1718
( MVector(..)
19+
-- * Deprecated
20+
, pattern MVector
1821
) where
1922

2023
import Data.Coerce
@@ -56,3 +59,8 @@ instance G.MVector MVector a where
5659
basicUnsafeMove = coerce (G.basicUnsafeMove @MV.MVector @a)
5760
{-# INLINE basicClear #-}
5861
basicClear = coerce (G.basicClear @MV.MVector @a)
62+
63+
pattern MVector :: MV.MVector s a -> MVector s a
64+
pattern MVector v = UnsafeMVector v
65+
{-# COMPLETE MVector #-}
66+
{-# DEPRECATED data MVector "Use MVector constructor exported from \"Data.Vector.Strict.Unsafe\"" #-}

0 commit comments

Comments
 (0)