diff options
author | David Feuer <david.feuer@gmail.com> | 2018-07-15 10:15:15 -0400 |
---|---|---|
committer | David Feuer <David.Feuer@gmail.com> | 2018-07-15 10:15:16 -0400 |
commit | af9b744bbf1c39078e561b19edd3c5234b361b27 (patch) | |
tree | 1e09db1499b2040043cd8d23ecb006539991a36c /compiler/prelude/primops.txt.pp | |
parent | 8a70ccbb552191e1972f3c5d7fce839176c4c0e3 (diff) | |
download | haskell-af9b744bbf1c39078e561b19edd3c5234b361b27.tar.gz |
Replace atomicModifyMutVar#
Reviewers: simonmar, hvr, bgamari, erikd, fryguybob, rrnewton
Reviewed By: simonmar
Subscribers: fryguybob, rwbarton, thomie, carter
GHC Trac Issues: #15364
Differential Revision: https://phabricator.haskell.org/D4884
Diffstat (limited to 'compiler/prelude/primops.txt.pp')
-rw-r--r-- | compiler/prelude/primops.txt.pp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp index 468299f5d2..b8c6811668 100644 --- a/compiler/prelude/primops.txt.pp +++ b/compiler/prelude/primops.txt.pp @@ -2224,25 +2224,37 @@ primop WriteMutVarOp "writeMutVar#" GenPrimOp primop SameMutVarOp "sameMutVar#" GenPrimOp MutVar# s a -> MutVar# s a -> Int# --- Note [Why not an unboxed tuple in atomicModifyMutVar#?] +-- Note [Why not an unboxed tuple in atomicModifyMutVar2#?] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- --- Looking at the type of atomicModifyMutVar#, one might wonder why +-- Looking at the type of atomicModifyMutVar2#, one might wonder why -- it doesn't return an unboxed tuple. e.g., -- --- MutVar# s a -> (a -> (# a, b #)) -> State# s -> (# State# s, b #) +-- MutVar# s a -> (a -> (# a, b #)) -> State# s -> (# State# s, a, (# a, b #) #) -- --- The reason is that atomicModifyMutVar# relies on laziness for its atomicity. --- Given a MutVar# containing x, atomicModifyMutVar# merely replaces the +-- The reason is that atomicModifyMutVar2# relies on laziness for its atomicity. +-- Given a MutVar# containing x, atomicModifyMutVar2# merely replaces -- its contents with a thunk of the form (fst (f x)). This can be done using an -- atomic compare-and-swap as it is merely replacing a pointer. -primop AtomicModifyMutVarOp "atomicModifyMutVar#" GenPrimOp - MutVar# s a -> (a -> b) -> State# s -> (# State# s, c #) - { Modify the contents of a {\tt MutVar\#}. Note that this isn't strictly - speaking the correct type for this function, it should really be - {\tt MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #)}, however - we don't know about pairs here. } +primop AtomicModifyMutVar2Op "atomicModifyMutVar2#" GenPrimOp + MutVar# s a -> (a -> c) -> State# s -> (# State# s, a, c #) + { Modify the contents of a {\tt MutVar\#}, returning the previous + contents and the result of applying the given function to the + previous contents. Note that this isn't strictly + speaking the correct type for this function; it should really be + {\tt MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, a, (a, b) #)}, + but we don't know about pairs here. } + with + out_of_line = True + has_side_effects = True + can_fail = True + +primop AtomicModifyMutVar_Op "atomicModifyMutVar_#" GenPrimOp + MutVar# s a -> (a -> a) -> State# s -> (# State# s, a, a #) + { Modify the contents of a {\tt MutVar\#}, returning the previous + contents and the result of applying the given function to the + previous contents. } with out_of_line = True has_side_effects = True |