<div dir="ltr">Hi Tom,<div><br></div><div>I think the implementation choices around exceptions in STM are well informed and reasoned choices, but other choices could have been made. One motivating reason for exceptions having abort semantics, for instance, is asynchronous exceptions (see the <b>Exceptions</b> section of <i>Composable Memory Transactions</i>). Caught exceptions thrown within a transaction have the same abort semantics for the nested transaction (as your example shows), but there is no way to know that `MyEx` isn't thrown asynchronously leading to rather difficult to reason about outcomes. I think it would be straight forward to modify this behavior in the RTS, simply do not discard the transactional record of the nested transaction (<a href="https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm#L1390">https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm#L1390</a>).</div><div><br></div><div>Ryan</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Dec 17, 2024 at 3:33 AM Tom Ellis <<a href="mailto:tom-lists-haskell-cafe-2023@jaguarpaw.co.uk">tom-lists-haskell-cafe-2023@jaguarpaw.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear Cafe,<br>
<br>
Is it possible to throw an exception in STM without rolling back<br>
state? (See program below for an demonstration that throwing an<br>
exception does roll back state.)<br>
<br>
I'm having a great deal of success using exceptions in my effect<br>
system Bluefin, to simulate early return and jumps:<br>
<br>
* <a href="https://hackage.haskell.org/package/bluefin-0.0.14.0/docs/Bluefin-EarlyReturn.html" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/bluefin-0.0.14.0/docs/Bluefin-EarlyReturn.html</a><br>
<br>
* <a href="https://hackage.haskell.org/package/bluefin-0.0.14.0/docs/Bluefin-Jump.html" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/bluefin-0.0.14.0/docs/Bluefin-Jump.html</a><br>
<br>
I'm interested in making a Bluefin interface to STM too, but the<br>
value of that would be significantly diminished if all exceptions roll<br>
back state.<br>
<br>
Instead I would like to be able to say "throwing this exception<br>
_shouldn't_ roll back state". Is that possible? If not in practice,<br>
is it possible in theory, if I were to modify the RTS somehow?<br>
<br>
Thanks,<br>
<br>
Tom<br>
<br>
<br>
<br>
<br>
<br>
<br>
{-# LANGUAGE GHC2021 #-}<br>
<br>
import GHC.Conc<br>
import GHC.Exception<br>
<br>
data MyEx = MyEx deriving Show<br>
<br>
instance Exception MyEx<br>
<br>
-- > main<br>
-- False<br>
main = do<br>
r <- atomically $ do<br>
v <- newTVar False<br>
<br>
catchSTM @MyEx<br>
(do<br>
writeTVar v True<br>
-- same with throw MyEx`<br>
throwSTM MyEx<br>
)<br>
(\_ -> pure ())<br>
<br>
readTVar v<br>
<br>
print r<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>