Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach WhileHandling annotations in exceptions thrown from catchSTM handlers #298

Open
bgamari opened this issue Oct 10, 2024 · 0 comments

Comments

@bgamari
Copy link

bgamari commented Oct 10, 2024

The catchSTM combinator exposed by GHC.Conc, GHC.Conc.Sync, and the stm package currently does not attach WhileHandling annotations to exceptions thrown from its handler, as described in #202. This functionality was requested in GHC #25365.

I propose that we introduce an annotateSTM combinator to GHC.Conc and GHC.Conc.Sync:

+-- | Execute an 'STM' action, adding the given 'ExceptionContext'
+-- to any thrown synchronous exceptions.
+annotateSTM :: forall e a. ExceptionAnnotation e => e -> STM a -> STM a
+annotateSTM ann (STM io) = STM (catch# io handler)
+  where
+    handler se = raiseIO# (addExceptionContext ann se)

and use it from catchSTM:

 catchSTM (STM m) handler = STM $ catchSTM# m handler'
     where
       handler' e = case fromException e of
-                     Just e' -> unSTM (handler e')
+                     Just e' -> unSTM (annotateSTM (WhileHandling e) (handler e'))
                      Nothing -> raiseIO# e

Implemented in GHC !13408.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant