The throwSTM combinator exposed by GHC.Conc, GHC.Conc.Sync, and the stm package currently does not capture and attach a Backtraces annotation to the thrown exception. This functionality was requested in GHC #25365.
I propose that throwSTM gain a HasCallStack constraint and its body be adjusted to attach the appropriate annotation:
-throwSTM :: Exception e => e -> STM a
-throwSTM e = STM $ raiseIO# (toException e)
+throwSTM :: HasCallStack => Exception e => e -> STM a
+throwSTM e = do
+ -- N.B. Typically use of unsafeIOToSTM is very much frowned upon as this
+ -- is an easy way to end up with nested transactions. However, we can be
+ -- certain that toExceptionWithBacktrace will not initiate a transaction.
+ se <- unsafeIOToSTM (toExceptionWithBacktrace e)
+ STM $ raiseIO# se
The
throwSTM
combinator exposed byGHC.Conc
,GHC.Conc.Sync
, and thestm
package currently does not capture and attach aBacktraces
annotation to the thrown exception. This functionality was requested in GHC #25365.I propose that
throwSTM
gain aHasCallStack
constraint and its body be adjusted to attach the appropriate annotation:Implemented in GHC !13408.