@@ -58,7 +58,13 @@ import GHC.IO hiding (finally, onException)
5858import GHC.Conc (ThreadId (.. ))
5959
6060#ifdef DEBUG_AUTO_LABEL
61- import GHC.Stack
61+ import qualified GHC.Stack
62+ #endif
63+
64+ #ifdef DEBUG_AUTO_LABEL
65+ #define CALLSTACK GHC.Stack.HasCallStack =>
66+ #else
67+ #define CALLSTACK
6268#endif
6369
6470-- -----------------------------------------------------------------------------
@@ -100,53 +106,41 @@ compareAsyncs (Async t1 _) (Async t2 _) = compare t1 t2
100106--
101107-- __Use 'withAsync' style functions wherever you can instead!__
102108async ::
103- #ifdef DEBUG_AUTO_LABEL
104- HasCallStack =>
105- #endif
109+ CALLSTACK
106110 IO a -> IO (Async a )
107111async = inline asyncUsing rawForkIO
108112
109113-- | Like 'async' but using 'forkOS' internally.
110114asyncBound ::
111- #ifdef DEBUG_AUTO_LABEL
112- HasCallStack =>
113- #endif
115+ CALLSTACK
114116 IO a -> IO (Async a )
115117asyncBound = asyncUsing forkOS
116118
117119-- | Like 'async' but using 'forkOn' internally.
118120asyncOn ::
119- #ifdef DEBUG_AUTO_LABEL
120- HasCallStack =>
121- #endif
121+ CALLSTACK
122122 Int -> IO a -> IO (Async a )
123123asyncOn = asyncUsing . rawForkOn
124124
125125-- | Like 'async' but using 'forkIOWithUnmask' internally. The child
126126-- thread is passed a function that can be used to unmask asynchronous
127127-- exceptions.
128128asyncWithUnmask ::
129- #ifdef DEBUG_AUTO_LABEL
130- HasCallStack =>
131- #endif
129+ CALLSTACK
132130 ((forall b . IO b -> IO b ) -> IO a ) -> IO (Async a )
133131asyncWithUnmask actionWith = asyncUsing rawForkIO (actionWith unsafeUnmask)
134132
135133-- | Like 'asyncOn' but using 'forkOnWithUnmask' internally. The
136134-- child thread is passed a function that can be used to unmask
137135-- asynchronous exceptions.
138136asyncOnWithUnmask ::
139- #ifdef DEBUG_AUTO_LABEL
140- HasCallStack =>
141- #endif
137+ CALLSTACK
142138 Int -> ((forall b . IO b -> IO b ) -> IO a ) -> IO (Async a )
143139asyncOnWithUnmask cpu actionWith =
144140 asyncUsing (rawForkOn cpu) (actionWith unsafeUnmask)
145141
146142asyncUsing ::
147- #ifdef DEBUG_AUTO_LABEL
148- HasCallStack =>
149- #endif
143+ CALLSTACK
150144 (IO () -> IO ThreadId ) -> IO a -> IO (Async a )
151145asyncUsing doFork = \ action -> do
152146 var <- newEmptyTMVarIO
@@ -174,35 +168,27 @@ asyncUsing doFork = \action -> do
174168-- linear memory.
175169--
176170withAsync ::
177- #ifdef DEBUG_AUTO_LABEL
178- HasCallStack =>
179- #endif
171+ CALLSTACK
180172 IO a -> (Async a -> IO b ) -> IO b
181173withAsync = inline withAsyncUsing rawForkIO
182174
183175-- | Like 'withAsync' but uses 'forkOS' internally.
184176withAsyncBound ::
185- #ifdef DEBUG_AUTO_LABEL
186- HasCallStack =>
187- #endif
177+ CALLSTACK
188178 IO a -> (Async a -> IO b ) -> IO b
189179withAsyncBound = withAsyncUsing forkOS
190180
191181-- | Like 'withAsync' but uses 'forkOn' internally.
192182withAsyncOn ::
193- #ifdef DEBUG_AUTO_LABEL
194- HasCallStack =>
195- #endif
183+ CALLSTACK
196184 Int -> IO a -> (Async a -> IO b ) -> IO b
197185withAsyncOn = withAsyncUsing . rawForkOn
198186
199187-- | Like 'withAsync' but uses 'forkIOWithUnmask' internally. The
200188-- child thread is passed a function that can be used to unmask
201189-- asynchronous exceptions.
202190withAsyncWithUnmask ::
203- #ifdef DEBUG_AUTO_LABEL
204- HasCallStack =>
205- #endif
191+ CALLSTACK
206192 ((forall c . IO c -> IO c ) -> IO a ) -> (Async a -> IO b ) -> IO b
207193withAsyncWithUnmask actionWith =
208194 withAsyncUsing rawForkIO (actionWith unsafeUnmask)
@@ -211,17 +197,13 @@ withAsyncWithUnmask actionWith =
211197-- child thread is passed a function that can be used to unmask
212198-- asynchronous exceptions
213199withAsyncOnWithUnmask ::
214- #ifdef DEBUG_AUTO_LABEL
215- HasCallStack =>
216- #endif
200+ CALLSTACK
217201 Int -> ((forall c . IO c -> IO c ) -> IO a ) -> (Async a -> IO b ) -> IO b
218202withAsyncOnWithUnmask cpu actionWith =
219203 withAsyncUsing (rawForkOn cpu) (actionWith unsafeUnmask)
220204
221205withAsyncUsing ::
222- #ifdef DEBUG_AUTO_LABEL
223- HasCallStack =>
224- #endif
206+ CALLSTACK
225207 (IO () -> IO ThreadId ) -> IO a -> (Async a -> IO b ) -> IO b
226208-- The bracket version works, but is slow. We can do better by
227209-- hand-coding it:
@@ -606,17 +588,13 @@ isCancel e
606588-- > waitEither a b
607589--
608590race ::
609- #ifdef DEBUG_AUTO_LABEL
610- HasCallStack =>
611- #endif
591+ CALLSTACK
612592 IO a -> IO b -> IO (Either a b )
613593
614594-- | Like 'race', but the result is ignored.
615595--
616596race_ ::
617- #ifdef DEBUG_AUTO_LABEL
618- HasCallStack =>
619- #endif
597+ CALLSTACK
620598 IO a -> IO b -> IO ()
621599
622600
@@ -630,9 +608,7 @@ race_ ::
630608-- > withAsync right $ \b ->
631609-- > waitBoth a b
632610concurrently ::
633- #ifdef DEBUG_AUTO_LABEL
634- HasCallStack =>
635- #endif
611+ CALLSTACK
636612 IO a -> IO b -> IO (a ,b )
637613
638614
@@ -641,18 +617,14 @@ concurrently ::
641617-- action and return the @Left@.
642618--
643619concurrentlyE ::
644- #ifdef DEBUG_AUTO_LABEL
645- HasCallStack =>
646- #endif
620+ CALLSTACK
647621 IO (Either e a ) -> IO (Either e b ) -> IO (Either e (a , b ))
648622
649623-- | 'concurrently', but ignore the result values
650624--
651625-- @since 2.1.1
652626concurrently_ ::
653- #ifdef DEBUG_AUTO_LABEL
654- HasCallStack =>
655- #endif
627+ CALLSTACK
656628 IO a -> IO b -> IO ()
657629
658630#define USE_ASYNC_VERSIONS 0
@@ -715,9 +687,7 @@ concurrentlyE left right = concurrently' left right (collect [])
715687 Right r -> collect (r: xs) m
716688
717689concurrently' ::
718- #ifdef DEBUG_AUTO_LABEL
719- HasCallStack =>
720- #endif
690+ CALLSTACK
721691 IO a -> IO b
722692 -> (IO (Either SomeException (Either a b )) -> IO r )
723693 -> IO r
@@ -797,9 +767,7 @@ concurrently_ left right = concurrently' left right (collect 0)
797767-- inputs without care may lead to resource exhaustion (of memory,
798768-- file descriptors, or other limited resources).
799769mapConcurrently ::
800- #ifdef DEBUG_AUTO_LABEL
801- HasCallStack =>
802- #endif
770+ CALLSTACK
803771 Traversable t => (a -> IO b ) -> t a -> IO (t b )
804772mapConcurrently f = runConcurrently . traverse (Concurrently . f)
805773
@@ -809,47 +777,37 @@ mapConcurrently f = runConcurrently . traverse (Concurrently . f)
809777--
810778-- @since 2.1.0
811779forConcurrently ::
812- #ifdef DEBUG_AUTO_LABEL
813- HasCallStack =>
814- #endif
780+ CALLSTACK
815781 Traversable t => t a -> (a -> IO b ) -> IO (t b )
816782forConcurrently = flip mapConcurrently
817783
818784-- | `mapConcurrently_` is `mapConcurrently` with the return value discarded;
819785-- a concurrent equivalent of 'mapM_'.
820786mapConcurrently_ ::
821- #ifdef DEBUG_AUTO_LABEL
822- HasCallStack =>
823- #endif
787+ CALLSTACK
824788 F. Foldable f => (a -> IO b ) -> f a -> IO ()
825789mapConcurrently_ f = runConcurrently . F. foldMap (Concurrently . void . f)
826790
827791-- | `forConcurrently_` is `forConcurrently` with the return value discarded;
828792-- a concurrent equivalent of 'forM_'.
829793forConcurrently_ ::
830- #ifdef DEBUG_AUTO_LABEL
831- HasCallStack =>
832- #endif
794+ CALLSTACK
833795 F. Foldable f => f a -> (a -> IO b ) -> IO ()
834796forConcurrently_ = flip mapConcurrently_
835797
836798-- | Perform the action in the given number of threads.
837799--
838800-- @since 2.1.1
839801replicateConcurrently ::
840- #ifdef DEBUG_AUTO_LABEL
841- HasCallStack =>
842- #endif
802+ CALLSTACK
843803 Int -> IO a -> IO [a ]
844804replicateConcurrently cnt = runConcurrently . sequenceA . replicate cnt . Concurrently
845805
846806-- | Same as 'replicateConcurrently', but ignore the results.
847807--
848808-- @since 2.1.1
849809replicateConcurrently_ ::
850- #ifdef DEBUG_AUTO_LABEL
851- HasCallStack =>
852- #endif
810+ CALLSTACK
853811 Int -> IO a -> IO ()
854812replicateConcurrently_ cnt = runConcurrently . F. fold . replicate cnt . Concurrently . void
855813
@@ -945,9 +903,7 @@ instance (Semigroup a, Monoid a) => Monoid (ConcurrentlyE e a) where
945903-- exception, re-runs the action. The thread terminates only when the
946904-- action runs to completion without raising an exception.
947905forkRepeat ::
948- #ifdef DEBUG_AUTO_LABEL
949- HasCallStack =>
950- #endif
906+ CALLSTACK
951907 IO a -> IO ThreadId
952908forkRepeat action =
953909 mask $ \ restore ->
@@ -968,9 +924,7 @@ tryAll = try
968924-- exception handler.
969925{-# INLINE rawForkIO #-}
970926rawForkIO ::
971- #ifdef DEBUG_AUTO_LABEL
972- HasCallStack =>
973- #endif
927+ CALLSTACK
974928 IO () -> IO ThreadId
975929rawForkIO action = IO $ \ s ->
976930 case (fork# action_plus s) of (# s1, tid # ) -> (# s1, ThreadId tid # )
@@ -979,24 +933,19 @@ rawForkIO action = IO $ \ s ->
979933
980934{-# INLINE rawForkOn #-}
981935rawForkOn ::
982- #ifdef DEBUG_AUTO_LABEL
983- HasCallStack =>
984- #endif
936+ CALLSTACK
985937 Int -> IO () -> IO ThreadId
986938rawForkOn (I # cpu) action = IO $ \ s ->
987939 case (forkOn# cpu action_plus s) of (# s1, tid # ) -> (# s1, ThreadId tid # )
988940 where
989941 (IO action_plus) = debugLabelMe >> action
990942
991-
992943debugLabelMe ::
993- #ifdef DEBUG_AUTO_LABEL
994- HasCallStack =>
995- #endif
944+ CALLSTACK
996945 IO ()
997946debugLabelMe =
998947#ifdef DEBUG_AUTO_LABEL
999- myThreadId >>= flip labelThread (prettyCallStack callStack)
948+ myThreadId >>= flip labelThread (GHC.Stack. prettyCallStack callStack)
1000949#else
1001950 pure ()
1002951#endif
0 commit comments