Skip to content

Commit 2b1636f

Browse files
fix PrimUnlifted's version of copy# which was broken. This fixes correctness issue with Mergesort (only)
1 parent 616ad10 commit 2b1636f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Array/Mutable.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ set (Array lo'@(GHC.I# lo) hi !arr) i'@(GHC.I# i) !a =
117117

118118
{-# INLINE copy #-}
119119
copy :: HasPrim a => Array a -> Int -> Array a -> Int -> Int -> Array a
120-
copy s@(Array (GHC.I# lo1) _hi1 src) (GHC.I# src_offset)
121-
d@(Array (GHC.I# lo2) _hi2 dst) (GHC.I# dst_offset)
122-
(GHC.I# n) =
120+
copy s@(Array lo1'@(GHC.I# lo1) _hi1 src) (GHC.I# src_offset)
121+
d@(Array (GHC.I# lo2) _hi2 dst) (GHC.I# dst_offset)
122+
(GHC.I# n) =
123123
#ifdef PRIM_MUTABLE_ARRAYS
124-
case copy# (get s 0) src (lo1 GHC.+# src_offset) dst (lo2 GHC.+# dst_offset) n of
124+
case copy# (get# src lo1) src (lo1 GHC.+# src_offset) dst (lo2 GHC.+# dst_offset) n of
125125
dst_arr' -> d { array = dst_arr' }
126126
#else
127-
case copy# src (lo1 GHC.+# src_offset) dst (lo2 GHC.+# dst_offset) n of
127+
case copy# src (lo1 GHC.+# src_offset) dst (lo2 GHC.+# dst_offset) n of
128128
dst_arr' -> d { array = dst_arr' }
129129
#endif
130130

src/Array/Mutable/PrimUnlifted.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ set# (Array# !arr) i !a =
5353
{-# NOINLINE copy# #-}
5454
copy# :: P.Prim a => a -> Array# a -> GHC.Int# -> Array# a -> GHC.Int# -> GHC.Int# -> Array# a
5555
copy# elt (Array# !src) src_offset (Array# !dst) dst_offset n =
56-
case GHC.runRW# (GHC.copyMutableByteArray# src src_offset_bytes dst dst_offset_bytes n) of
56+
case GHC.runRW# (GHC.copyMutableByteArray# src src_offset_bytes dst dst_offset_bytes n_bytes) of
5757
_ -> Array# dst
5858
where
5959
src_offset_bytes = (P.sizeOf# elt) GHC.*# src_offset
6060
dst_offset_bytes = (P.sizeOf# elt) GHC.*# dst_offset
61+
n_bytes = (P.sizeOf# elt) GHC.*# n
6162

6263

6364
size# :: Array# a -> GHC.Int#

0 commit comments

Comments
 (0)