11{-# LANGUAGE CPP, MagicHash, UnboxedTuples, RankNTypes,
2- ExistentialQuantification #-}
2+ ExistentialQuantification, ConstraintKinds, KindSignatures #-}
33#if __GLASGOW_HASKELL__ >= 701
44{-# LANGUAGE Trustworthy #-}
55#endif
@@ -58,7 +58,15 @@ import GHC.IO hiding (finally, onException)
5858import GHC.Conc (ThreadId (.. ), labelThread )
5959
6060#ifdef DEBUG_AUTO_LABEL
61- import GHC.Stack
61+ import qualified GHC.Stack
62+ #else
63+ import qualified GHC.Exts
64+ #endif
65+
66+ #ifdef DEBUG_AUTO_LABEL
67+ type DebugCallStack = GHC.Stack. HasCallStack
68+ #else
69+ type DebugCallStack = () :: GHC.Exts. Constraint
6270#endif
6371
6472-- -----------------------------------------------------------------------------
@@ -100,53 +108,41 @@ compareAsyncs (Async t1 _) (Async t2 _) = compare t1 t2
100108--
101109-- __Use 'withAsync' style functions wherever you can instead!__
102110async ::
103- #ifdef DEBUG_AUTO_LABEL
104- HasCallStack =>
105- #endif
111+ DebugCallStack =>
106112 IO a -> IO (Async a )
107113async = inline asyncUsing rawForkIO
108114
109115-- | Like 'async' but using 'forkOS' internally.
110116asyncBound ::
111- #ifdef DEBUG_AUTO_LABEL
112- HasCallStack =>
113- #endif
117+ DebugCallStack =>
114118 IO a -> IO (Async a )
115119asyncBound = asyncUsing forkOS
116120
117121-- | Like 'async' but using 'forkOn' internally.
118122asyncOn ::
119- #ifdef DEBUG_AUTO_LABEL
120- HasCallStack =>
121- #endif
123+ DebugCallStack =>
122124 Int -> IO a -> IO (Async a )
123125asyncOn = asyncUsing . rawForkOn
124126
125127-- | Like 'async' but using 'forkIOWithUnmask' internally. The child
126128-- thread is passed a function that can be used to unmask asynchronous
127129-- exceptions.
128130asyncWithUnmask ::
129- #ifdef DEBUG_AUTO_LABEL
130- HasCallStack =>
131- #endif
131+ DebugCallStack =>
132132 ((forall b . IO b -> IO b ) -> IO a ) -> IO (Async a )
133133asyncWithUnmask actionWith = asyncUsing rawForkIO (actionWith unsafeUnmask)
134134
135135-- | Like 'asyncOn' but using 'forkOnWithUnmask' internally. The
136136-- child thread is passed a function that can be used to unmask
137137-- asynchronous exceptions.
138138asyncOnWithUnmask ::
139- #ifdef DEBUG_AUTO_LABEL
140- HasCallStack =>
141- #endif
139+ DebugCallStack =>
142140 Int -> ((forall b . IO b -> IO b ) -> IO a ) -> IO (Async a )
143141asyncOnWithUnmask cpu actionWith =
144142 asyncUsing (rawForkOn cpu) (actionWith unsafeUnmask)
145143
146144asyncUsing ::
147- #ifdef DEBUG_AUTO_LABEL
148- HasCallStack =>
149- #endif
145+ DebugCallStack =>
150146 (IO () -> IO ThreadId ) -> IO a -> IO (Async a )
151147asyncUsing doFork = \ action -> do
152148 var <- newEmptyTMVarIO
@@ -174,35 +170,27 @@ asyncUsing doFork = \action -> do
174170-- linear memory.
175171--
176172withAsync ::
177- #ifdef DEBUG_AUTO_LABEL
178- HasCallStack =>
179- #endif
173+ DebugCallStack =>
180174 IO a -> (Async a -> IO b ) -> IO b
181175withAsync = inline withAsyncUsing rawForkIO
182176
183177-- | Like 'withAsync' but uses 'forkOS' internally.
184178withAsyncBound ::
185- #ifdef DEBUG_AUTO_LABEL
186- HasCallStack =>
187- #endif
179+ DebugCallStack =>
188180 IO a -> (Async a -> IO b ) -> IO b
189181withAsyncBound = withAsyncUsing forkOS
190182
191183-- | Like 'withAsync' but uses 'forkOn' internally.
192184withAsyncOn ::
193- #ifdef DEBUG_AUTO_LABEL
194- HasCallStack =>
195- #endif
185+ DebugCallStack =>
196186 Int -> IO a -> (Async a -> IO b ) -> IO b
197187withAsyncOn = withAsyncUsing . rawForkOn
198188
199189-- | Like 'withAsync' but uses 'forkIOWithUnmask' internally. The
200190-- child thread is passed a function that can be used to unmask
201191-- asynchronous exceptions.
202192withAsyncWithUnmask ::
203- #ifdef DEBUG_AUTO_LABEL
204- HasCallStack =>
205- #endif
193+ DebugCallStack =>
206194 ((forall c . IO c -> IO c ) -> IO a ) -> (Async a -> IO b ) -> IO b
207195withAsyncWithUnmask actionWith =
208196 withAsyncUsing rawForkIO (actionWith unsafeUnmask)
@@ -211,17 +199,13 @@ withAsyncWithUnmask actionWith =
211199-- child thread is passed a function that can be used to unmask
212200-- asynchronous exceptions
213201withAsyncOnWithUnmask ::
214- #ifdef DEBUG_AUTO_LABEL
215- HasCallStack =>
216- #endif
202+ DebugCallStack =>
217203 Int -> ((forall c . IO c -> IO c ) -> IO a ) -> (Async a -> IO b ) -> IO b
218204withAsyncOnWithUnmask cpu actionWith =
219205 withAsyncUsing (rawForkOn cpu) (actionWith unsafeUnmask)
220206
221207withAsyncUsing ::
222- #ifdef DEBUG_AUTO_LABEL
223- HasCallStack =>
224- #endif
208+ DebugCallStack =>
225209 (IO () -> IO ThreadId ) -> IO a -> (Async a -> IO b ) -> IO b
226210-- The bracket version works, but is slow. We can do better by
227211-- hand-coding it:
@@ -607,17 +591,13 @@ isCancel e
607591-- > waitEither a b
608592--
609593race ::
610- #ifdef DEBUG_AUTO_LABEL
611- HasCallStack =>
612- #endif
594+ DebugCallStack =>
613595 IO a -> IO b -> IO (Either a b )
614596
615597-- | Like 'race', but the result is ignored.
616598--
617599race_ ::
618- #ifdef DEBUG_AUTO_LABEL
619- HasCallStack =>
620- #endif
600+ DebugCallStack =>
621601 IO a -> IO b -> IO ()
622602
623603
@@ -631,9 +611,7 @@ race_ ::
631611-- > withAsync right $ \b ->
632612-- > waitBoth a b
633613concurrently ::
634- #ifdef DEBUG_AUTO_LABEL
635- HasCallStack =>
636- #endif
614+ DebugCallStack =>
637615 IO a -> IO b -> IO (a ,b )
638616
639617
@@ -642,18 +620,14 @@ concurrently ::
642620-- action and return the @Left@.
643621--
644622concurrentlyE ::
645- #ifdef DEBUG_AUTO_LABEL
646- HasCallStack =>
647- #endif
623+ DebugCallStack =>
648624 IO (Either e a ) -> IO (Either e b ) -> IO (Either e (a , b ))
649625
650626-- | 'concurrently', but ignore the result values
651627--
652628-- @since 2.1.1
653629concurrently_ ::
654- #ifdef DEBUG_AUTO_LABEL
655- HasCallStack =>
656- #endif
630+ DebugCallStack =>
657631 IO a -> IO b -> IO ()
658632
659633#define USE_ASYNC_VERSIONS 0
@@ -716,9 +690,7 @@ concurrentlyE left right = concurrently' left right (collect [])
716690 Right r -> collect (r: xs) m
717691
718692concurrently' ::
719- #ifdef DEBUG_AUTO_LABEL
720- HasCallStack =>
721- #endif
693+ DebugCallStack =>
722694 IO a -> IO b
723695 -> (IO (Either SomeException (Either a b )) -> IO r )
724696 -> IO r
@@ -799,9 +771,7 @@ concurrently_ left right = concurrently' left right (collect 0)
799771-- inputs without care may lead to resource exhaustion (of memory,
800772-- file descriptors, or other limited resources).
801773mapConcurrently ::
802- #ifdef DEBUG_AUTO_LABEL
803- HasCallStack =>
804- #endif
774+ DebugCallStack =>
805775 Traversable t => (a -> IO b ) -> t a -> IO (t b )
806776mapConcurrently f = runConcurrently . traverse (Concurrently . f)
807777
@@ -811,47 +781,37 @@ mapConcurrently f = runConcurrently . traverse (Concurrently . f)
811781--
812782-- @since 2.1.0
813783forConcurrently ::
814- #ifdef DEBUG_AUTO_LABEL
815- HasCallStack =>
816- #endif
784+ DebugCallStack =>
817785 Traversable t => t a -> (a -> IO b ) -> IO (t b )
818786forConcurrently = flip mapConcurrently
819787
820788-- | `mapConcurrently_` is `mapConcurrently` with the return value discarded;
821789-- a concurrent equivalent of 'mapM_'.
822790mapConcurrently_ ::
823- #ifdef DEBUG_AUTO_LABEL
824- HasCallStack =>
825- #endif
791+ DebugCallStack =>
826792 F. Foldable f => (a -> IO b ) -> f a -> IO ()
827793mapConcurrently_ f = runConcurrently . F. foldMap (Concurrently . void . f)
828794
829795-- | `forConcurrently_` is `forConcurrently` with the return value discarded;
830796-- a concurrent equivalent of 'forM_'.
831797forConcurrently_ ::
832- #ifdef DEBUG_AUTO_LABEL
833- HasCallStack =>
834- #endif
798+ DebugCallStack =>
835799 F. Foldable f => f a -> (a -> IO b ) -> IO ()
836800forConcurrently_ = flip mapConcurrently_
837801
838802-- | Perform the action in the given number of threads.
839803--
840804-- @since 2.1.1
841805replicateConcurrently ::
842- #ifdef DEBUG_AUTO_LABEL
843- HasCallStack =>
844- #endif
806+ DebugCallStack =>
845807 Int -> IO a -> IO [a ]
846808replicateConcurrently cnt = runConcurrently . sequenceA . replicate cnt . Concurrently
847809
848810-- | Same as 'replicateConcurrently', but ignore the results.
849811--
850812-- @since 2.1.1
851813replicateConcurrently_ ::
852- #ifdef DEBUG_AUTO_LABEL
853- HasCallStack =>
854- #endif
814+ DebugCallStack =>
855815 Int -> IO a -> IO ()
856816replicateConcurrently_ cnt = runConcurrently . F. fold . replicate cnt . Concurrently . void
857817
@@ -947,9 +907,7 @@ instance (Semigroup a, Monoid a) => Monoid (ConcurrentlyE e a) where
947907-- exception, re-runs the action. The thread terminates only when the
948908-- action runs to completion without raising an exception.
949909forkRepeat ::
950- #ifdef DEBUG_AUTO_LABEL
951- HasCallStack =>
952- #endif
910+ DebugCallStack =>
953911 IO a -> IO ThreadId
954912forkRepeat action =
955913 mask $ \ restore ->
@@ -970,9 +928,7 @@ tryAll = try
970928-- exception handler.
971929{-# INLINE rawForkIO #-}
972930rawForkIO ::
973- #ifdef DEBUG_AUTO_LABEL
974- HasCallStack =>
975- #endif
931+ DebugCallStack =>
976932 IO () -> IO ThreadId
977933rawForkIO action = IO $ \ s ->
978934 case (fork# action_plus s) of (# s1, tid # ) -> (# s1, ThreadId tid # )
@@ -981,24 +937,19 @@ rawForkIO action = IO $ \ s ->
981937
982938{-# INLINE rawForkOn #-}
983939rawForkOn ::
984- #ifdef DEBUG_AUTO_LABEL
985- HasCallStack =>
986- #endif
940+ DebugCallStack =>
987941 Int -> IO () -> IO ThreadId
988942rawForkOn (I # cpu) action = IO $ \ s ->
989943 case (forkOn# cpu action_plus s) of (# s1, tid # ) -> (# s1, ThreadId tid # )
990944 where
991945 (IO action_plus) = debugLabelMe >> action
992946
993-
994947debugLabelMe ::
995- #ifdef DEBUG_AUTO_LABEL
996- HasCallStack =>
997- #endif
948+ DebugCallStack =>
998949 IO ()
999950debugLabelMe =
1000951#ifdef DEBUG_AUTO_LABEL
1001- myThreadId >>= flip labelThread (prettyCallStack callStack)
952+ myThreadId >>= flip labelThread (GHC.Stack. prettyCallStack callStack)
1002953#else
1003954 pure ()
1004955#endif
0 commit comments