diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-02-02 14:43:53 -0500 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-02-10 13:55:37 +0000 |
commit | d5194ab29cad0530196b2efa6a6c4687c889d709 (patch) | |
tree | a0f547594f892f2b92c29f2bae9a7ff929d9d4e5 | |
parent | 2a3b312ad0067f6875c162ccc7a13e220c1ece5c (diff) | |
download | haskell-d5194ab29cad0530196b2efa6a6c4687c889d709.tar.gz |
primops: Fix documentation of setByteArray#
Previously the documentation was subtly incorrect regarding the bounds
of the operation. Fix this and add a test asserting that a zero-length
operation is in fact a no-op.
(cherry picked from commit 8c18feba88aaa20b75b82c3fee7e8f742299461e)
-rw-r--r-- | compiler/GHC/Builtin/primops.txt.pp | 2 | ||||
-rw-r--r-- | testsuite/tests/codeGen/should_run/setByteArray.hs | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/compiler/GHC/Builtin/primops.txt.pp b/compiler/GHC/Builtin/primops.txt.pp index 3f31b72bca..e2b5c5ab09 100644 --- a/compiler/GHC/Builtin/primops.txt.pp +++ b/compiler/GHC/Builtin/primops.txt.pp @@ -1868,7 +1868,7 @@ primop CopyAddrToByteArrayOp "copyAddrToByteArray#" GenPrimOp primop SetByteArrayOp "setByteArray#" GenPrimOp MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s - {{\tt setByteArray# ba off len c} sets the byte range {\tt [off, off+len]} of + {{\tt setByteArray# ba off len c} sets the byte range {\tt [off, off+len)} of the {\tt MutableByteArray#} to the byte {\tt c}.} with has_side_effects = True diff --git a/testsuite/tests/codeGen/should_run/setByteArray.hs b/testsuite/tests/codeGen/should_run/setByteArray.hs index 099376cb4b..c9a1012ccd 100644 --- a/testsuite/tests/codeGen/should_run/setByteArray.hs +++ b/testsuite/tests/codeGen/should_run/setByteArray.hs @@ -12,12 +12,15 @@ main :: IO () main = do BA ba <- IO $ \s0 -> case newByteArray# 8# s0 of (# !s1, !mba #) -> - case setByteArray# mba 0# 8# 65# s1 of + case setByteArray# mba 0# 8# 65# s1 of -- ASCII 'A' !s2 -> - case setByteArray# mba 1# 6# 67# s2 of + case setByteArray# mba 1# 6# 67# s2 of -- ASCII 'B' !s3 -> - case unsafeFreezeByteArray# mba s3 of - (# s4, ba #) -> (# s4, BA ba #) + -- N.B. 0-length should be a no-op + case setByteArray# mba 2# 0# 68# s3 of -- ASCII 'C' + !s4 -> + case unsafeFreezeByteArray# mba s4 of + (# s5, ba #) -> (# s5, BA ba #) let f (I# i) = putStrLn [C# (indexCharArray# ba i)] mapM_ f [0..7] |