@@ -29,6 +29,7 @@ import Control.Exception (Exception, SomeException, mask_)
2929import Control.Monad.Catch (MonadCatch)
3030import Control.Monad.IO.Class (MonadIO(..))
3131import Control.Monad.Trans.Control (MonadBaseControl, liftBaseOp_)
32+import GHC.Exts (inline)
3233import Streamly.Internal.Data.IOFinalizer
3334 (newIOFinalizer, runIOFinalizer, clearingIOFinalizer)
3435
@@ -231,7 +232,7 @@ after action (Stream step state) = Stream step' Nothing
231232{-# INLINE_NORMAL onException #-}
232233onException :: MonadCatch m => m b -> Stream m a -> Stream m a
233234onException action str =
234− gbracket_ (return ()) MC.try return
235+ gbracket_ (return ()) (inline MC.try) return
235236 (\_ (e :: MC.SomeException) _ -> nilM (action >> MC.throwM e))
236237 (\_ -> str)
237238
@@ -255,7 +256,7 @@ _onException action (Stream step state) = Stream step' state
255256bracket_ :: MonadCatch m
256257 => m b -> (b -> m c) -> (b -> Stream m a) -> Stream m a
257258bracket_ bef aft bet =
258− gbracket_ bef MC.try aft
259+ gbracket_ bef (inline MC.try) aft
259260 (\a (e :: SomeException) _ -> nilM (aft a >> MC.throwM e)) bet
260261
261262-- | See 'Streamly.Internal.Data.Stream.IsStream.bracket'.
@@ -264,7 +265,7 @@ bracket_ bef aft bet =
264265bracket :: (MonadAsync m, MonadCatch m)
265266 => m b -> (b -> m c) -> (b -> Stream m a) -> Stream m a
266267bracket bef aft bet =
267− gbracket bef MC.try aft
268+ gbracket bef (inline MC.try) aft
268269 (\a (e :: SomeException) _ -> aft a >> return (nilM (MC.throwM e))) bet
269270
270271data BracketState s v = BracketInit | BracketRun s v
@@ -285,7 +286,7 @@ _bracket bef aft bet = Stream step' BracketInit
285286 -- here, otherwise we get huge perf degradation, see note in concatMap.
286287 step' gst (BracketRun (UnStream step state) v) = do
287288 -- res <- step gst state `MC.onException` aft v
288− res <- MC.try $ step gst state
289+ res <- inline MC.try $ step gst state
289290 case res of
290291 Left (e :: SomeException) -> aft v >> MC.throwM e >> return Stop
291292 Right r -> case r of
@@ -313,7 +314,7 @@ finally action xs = bracket (return ()) (\_ -> action) (const xs)
313314ghandle :: (MonadCatch m, Exception e)
314315 => (e -> Stream m a -> Stream m a) -> Stream m a -> Stream m a
315316ghandle f str =
316− gbracket_ (return ()) MC.try return (\_ -> f) (\_ -> str)
317+ gbracket_ (return ()) (inline MC.try) return (\_ -> f) (\_ -> str)
317318
318319-- | See 'Streamly.Internal.Data.Stream.IsStream.handle'.
319320--
@@ -321,7 +322,7 @@ ghandle f str =
321322handle :: (MonadCatch m, Exception e)
322323 => (e -> Stream m a) -> Stream m a -> Stream m a
323324handle f str =
324− gbracket_ (return ()) MC.try return (\_ e _ -> f e) (\_ -> str)
325+ gbracket_ (return ()) (inline MC.try) return (\_ e _ -> f e) (\_ -> str)
325326
326327-- | Alternate (custom) implementation of 'handle'.
327328--
@@ -334,7 +335,7 @@ _handle f (Stream step state) = Stream step' (Left state)
334335
335336 {-# INLINE_LATE step' #-}
336337 step' gst (Left st) = do
337− res <- MC.try $ step gst st
338+ res <- inline MC.try $ step gst st
338339 case res of
339340 Left e -> return $ Skip $ Right (f e)
340341 Right r -> case r of