You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: alternate implementation for exception context
This implementation works differently than the previous one. It actually
implements all the standard function based on the GHC 9.12 api (e.g.
`tryWithContext`, `catchNoPropagate`, `rethrowIO`) and provides a simple
and localise compatibility layer which reimplements these function for
older `base`.
The implementation should be easier to read with less CPP and subtle
logic scattered everywhere.
It also implements `xxxWithContext` version for most of the functions
used to return `SomeException`: they are now returning
`ExceptionWithContext SomeException`, based on the `tryWithContext`
semantic.
@@ -223,7 +222,7 @@ withAsyncUsing doFork action inner = do
223
222
var <- newEmptyTMVarIO
224
223
mask $\restore ->do
225
224
let action_plus = debugLabelMe >> action
226
-
t <- doFork $try (restore action_plus) >>= atomically . putTMVar var
225
+
t <- doFork $tryWithContext (restore action_plus) >>= atomically . putTMVar var
227
226
let a =Async t (readTMVar var)
228
227
-- Using catch/no/propagate and rethrowIO, we do not wrap the exception
229
228
-- with a `WhileWaiting`
@@ -232,37 +231,47 @@ withAsyncUsing doFork action inner = do
232
231
rethrowIO (e ::ExceptionWithContextSomeException)
233
232
uninterruptibleCancel a
234
233
return r
234
+
235
+
-- * Compatibilty logic with base 4.21 for exception context. The rational here is that this module is implemented with 'ExceptionWithContext' as the basic building block with the following special cases:
236
+
--
237
+
-- - With base >= 4.21 (GHC 9.12), exception context is propagated correctly using the 'rethrowIO', 'catchNoPropagate', ... functions.
238
+
-- - With base >= 4.20 (GHC 9.10), exception context logic exists, but not the 'rethrow' logic. We reimplemented these function which are basically discarding the context
239
+
-- - With base < 4.20 (GHC 9.8 and older), we just use the old functions which does not know anything about exception context. We implement an alias 'ExceptionWithContext' which is actually bare exception.
240
+
--
241
+
-- For all version we implement 'dropContext' which is able to drop the
242
+
-- context, for all the function such as 'poll' which returns an exception without context.
243
+
244
+
245
+
--| Drop the exception context
246
+
dropContext::ExceptionWithContextt->t
247
+
248
+
--| Rethrow an exception inside 'STM' context, while preserving the 'ExceptionContext'. See 'rethrowIO' for details.
0 commit comments