Skip to content
Snippets Groups Projects
Commit d91b1045 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

primops: Add comment describing type of atomicModifyMutVar#

This resolves #13130. It's not entirely clear to me why we don't use an
unboxed tuple here but this is at least better than the status quo.

[skip ci]

Test Plan: Read it

Reviewers: simonmar, austin, dfeuer

Reviewed By: dfeuer

Subscribers: dfeuer, rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3288
parent 1686f309
No related branches found
No related tags found
No related merge requests found
......@@ -1924,13 +1924,25 @@ primop WriteMutVarOp "writeMutVar#" GenPrimOp
primop SameMutVarOp "sameMutVar#" GenPrimOp
MutVar# s a -> MutVar# s a -> Int#
-- not really the right type, but we don't know about pairs here. The
-- correct type is
-- Note [Why not an unboxed tuple in atomicModifyMutVar#?]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #)
-- Looking at the type of atomicModifyMutVar#, one might wonder why
-- it doesn't return an unboxed tuple. e.g.,
--
-- MutVar# s a -> (a -> (# a, b #)) -> State# s -> (# State# s, b #)
--
-- The reason is that atomicModifyMutVar# relies on laziness for its atomicity.
-- Given a MutVar# containing x, atomicModifyMutVar# merely replaces the
-- 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. }
with
out_of_line = True
has_side_effects = True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment