@@ -9,6 +9,7 @@
99{-# LANGUAGE GADTs #-}
1010{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1111{-# LANGUAGE LambdaCase #-}
12+{-# LANGUAGE MultiWayIf #-}
1213{-# LANGUAGE RankNTypes #-}
1314{-# LANGUAGE RoleAnnotations #-}
1415{-# LANGUAGE ScopedTypeVariables #-}
@@ -19,7 +20,7 @@
1920{-# LANGUAGE DeriveFunctor #-}
2021{-# LANGUAGE StandaloneDeriving #-}
2122{-# LANGUAGE InstanceSigs #-}
22−{-# LANGUAGE MultiWayIf #-}
23+{-# LANGUAGE RecursiveDo #-}
2324
2425#ifdef USE_REFLEX_OPTIMIZER
2526{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
@@ -38,17 +39,15 @@ import Control.Monad hiding (forM, forM_, mapM, mapM_)
3839import Control.Monad.Exception
3940import Control.Monad.Identity hiding (forM, forM_, mapM, mapM_)
4041import Control.Monad.Primitive
42+--import Control.Monad.Reader hiding (forM, forM_, mapM, mapM_)
4143import Control.Monad.Reader.Class
4244import Control.Monad.IO.Class
4345import Control.Monad.ReaderIO
4446import Control.Monad.Ref
45−import Control.Monad.Fail (MonadFail)
46−import qualified Control.Monad.Fail as MonadFail
4747import Data.Align
4848import Data.Coerce
49−import Data.Dependent.Map (DMap)
49+import Data.Dependent.Map (DMap, DSum (..))
5050import qualified Data.Dependent.Map as DMap
51−import Data.Dependent.Sum (DSum (..))
5251import Data.FastMutableIntMap (FastMutableIntMap, PatchIntMap (..))
5352import qualified Data.FastMutableIntMap as FastMutableIntMap
5453import Data.Foldable hiding (concat, elem, sequence_)
@@ -65,7 +64,6 @@ import Data.Monoid (mempty, (<>))
6564import Data.Proxy
6665import Data.These
6766import Data.Traversable
68−import Data.Type.Equality ((:~:)(Refl))
6967import Data.Witherable (Filterable, mapMaybe)
7068import GHC.Exts hiding (toList)
7169import GHC.IORef (IORef (..))
@@ -75,20 +73,17 @@ import System.IO.Unsafe
7573import System.Mem.Weak
7674import Unsafe.Coerce
7775
78−#ifdef MIN_VERSION_semialign
76+#if defined(MIN_VERSION_semialign)
7977#if MIN_VERSION_these(0,8,0)
8078import Data.These.Combinators (justThese)
8179#endif
82−#if MIN_VERSION_semialign(1,1,0)
83−import Data.Zip (Zip (..))
84−#endif
8580#endif
8681
8782#ifdef DEBUG_CYCLES
8883import Control.Monad.State hiding (forM, forM_, mapM, mapM_, sequence)
84+import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
8985#endif
9086
91−import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
9287import qualified Data.List.NonEmpty as NonEmpty
9388import Data.Tree (Forest, Tree (..), drawForest)
9489import Data.List (isPrefixOf)
@@ -106,21 +101,14 @@ import qualified Reflex.Class
106101import qualified Reflex.Class as R
107102import qualified Reflex.Host.Class
108103import Reflex.NotReady.Class
109−import Data.Patch
110−import qualified Data.Patch.DMapWithMove as PatchDMapWithMove
111−import Reflex.PerformEvent.Base (PerformEventT)
104+import Reflex.Patch
105+import qualified Reflex.Patch.DMapWithMove as PatchDMapWithMove
112106
113107#ifdef DEBUG_TRACE_EVENTS
114108import qualified Data.ByteString.Char8 as BS8
115109import System.IO (stderr)
116110import Data.List (isPrefixOf)
117−#endif
118111
119−-- TODO stdout might not be the best channel for debug output
120−debugStrLn :: String -> IO ()
121−debugStrLn = putStrLn
122−
123−#ifdef DEBUG_TRACE_EVENTS
124112withStackOneLine :: (BS8.ByteString -> a) -> a
125113withStackOneLine expr = unsafePerformIO $ do
126114 stack <- currentCallStack
@@ -129,39 +117,15 @@ withStackOneLine expr = unsafePerformIO $ do
129117
130118#endif
131119
132−debugPropagate :: Bool
133−
134−debugInvalidateHeight :: Bool
135−
136−debugInvalidate :: Bool
137−
138120#ifdef DEBUG
139121#define DEBUG_NODEIDS
140122
141−#ifdef DEBUG_TRACE_PROPAGATION
142−debugPropagate = True
143−#else
144−debugPropagate = False
145−#endif
146−
147−#ifdef DEBUG_TRACE_HEIGHT
148−debugInvalidateHeight = True
149−#else
150−debugInvalidateHeight = False
151−#endif
152−
153−#ifdef DEBUG_TRACE_INVALIDATION
154−debugInvalidate = True
155−#else
156−debugInvalidate = False
157−#endif
158−
159123class HasNodeId a where
160124 getNodeId :: a -> Int
161125
162126instance HasNodeId (CacheSubscribed x a) where
163127 getNodeId = _cacheSubscribed_nodeId
164−
128+
165129instance HasNodeId (FanInt x a) where
166130 getNodeId = _fanInt_nodeId
167131
@@ -188,24 +152,16 @@ showNodeId :: HasNodeId a => a -> String
188152showNodeId = showNodeId' . getNodeId
189153
190154showNodeId' :: Int -> String
191−showNodeId' = ("#"<>) . show
155+showNodeId' = ("#"<>) . show
192156
193157
194158#else
195159
196−debugPropagate = False
197−debugInvalidateHeight = False
198−debugInvalidate = False
199−
200160-- This must be inline, or error messages will cause memory leaks due to retaining the node in question
201161{-# INLINE showNodeId #-}
202162showNodeId :: a -> String
203163showNodeId _ = ""
204164
205−{-# INLINE showNodeId' #-}
206−showNodeId' :: Int -> String
207−showNodeId' _ = ""
208−
209165#endif
210166
211167#ifdef DEBUG_NODEIDS
@@ -253,11 +209,11 @@ subscribeAndRead = unEvent
253209{-# INLINE [1] pushCheap #-}
254210pushCheap :: HasSpiderTimeline x => (a -> ComputeM x (Maybe b)) -> Event x a -> Event x b
255211pushCheap !f e = Event $ \sub -> do
256− (subscription, occ) <- subscribeAndRead e $ debugSubscriber' "push" $ sub
212+ (subscription, occ) <- subscribeAndRead e $ debugSubscriber' "push" (sub
257213 { subscriberPropagate = \a -> do
258214 mb <- f a
259215 mapM_ (subscriberPropagate sub) mb
260− }
216+ })
261217 occ' <- join <$> mapM f occ
262218 return (subscription, occ')
263219
@@ -293,9 +249,9 @@ headE originalE = do
293249 let clearParent = liftIO $ writeIORef parent Nothing
294250 (_, occ) <- subscribeAndReadHead originalE $ terminalSubscriber $ const clearParent
295251 when (isJust occ) clearParent
296− return $ Event $ \sub ->
252+ return $ Event $ \sub ->
297253 liftIO (readIORef parent) >>= \case
298− Nothing -> subscribeAndReadNever
254+ Nothing -> subscribeAndReadNever
299255 Just e -> subscribeAndReadHead e sub
300256
301257data CacheSubscribed x a
@@ -307,20 +263,7 @@ data CacheSubscribed x a
307263#endif
308264 }
309265
310−nowSpiderEventM :: (HasSpiderTimeline x) => EventM x (R.Event (SpiderTimeline x) ())
311−nowSpiderEventM =
312− SpiderEvent <$> now
313−
314−now :: (MonadIO m, Defer (Some Clear) m, HasSpiderTimeline x
315− ) => m (Event x ())
316−now = do
317− nowOrNot <- liftIO $ newIORef $ Just ()
318− scheduleClear nowOrNot
319− return . Event $ \_ -> do
320− occ <- liftIO . readIORef $ nowOrNot
321− return ( EventSubscription (return ()) eventSubscribedNow
322− , occ
323− )
266+
324267
325268-- | Construct an 'Event' whose value is guaranteed not to be recomputed
326269-- repeatedly
@@ -351,17 +294,14 @@ cacheEvent e =
351294#endif
352295 subscribers <- liftIO FastWeakBag.empty
353296 occRef <- liftIO $ newIORef Nothing -- This should never be read prior to being set below
354−#ifdef DEBUG_NODEIDS
355297 (parentSub, occ) <- subscribeAndRead e $ debugSubscriber' ("cacheEvent" <> showNodeId' nodeId) $ Subscriber
356−#else
357− (parentSub, occ) <- subscribeAndRead e $ Subscriber
358−#endif
359298 { subscriberPropagate = \a -> do
299+ -- checkCycle (_eventSubscription_subscribed parentSub)
360300 liftIO $ writeIORef occRef (Just a)
361301 scheduleClear occRef
362302 propagateFast a subscribers
363− , subscriberInvalidateHeight = FastWeakBag.traverse_ subscribers . invalidateSubscriberHeight
364− , subscriberRecalculateHeight = FastWeakBag.traverse_ subscribers . recalculateSubscriberHeight
303+ , subscriberInvalidateHeight = FastWeakBag.traverse subscribers . invalidateSubscriberHeight
304+ , subscriberRecalculateHeight = FastWeakBag.traverse subscribers . recalculateSubscriberHeight
365305 }
366306 when (isJust occ) $ do
367307 liftIO $ writeIORef occRef occ -- Set the initial value of occRef; we don't need to do this if occ is Nothing
@@ -372,20 +312,20 @@ cacheEvent e =
372312 , _cacheSubscribed_occurrence = occRef
373313#ifdef DEBUG_NODEIDS
374314 , _cacheSubscribed_nodeId = nodeId
375−#endif
315+#endif
376316 }
377317 subscribedTicket <- liftIO $ mkFastWeakTicket subscribed
378318 liftIO $ writeIORef mSubscribedRef =<< getFastWeakTicketWeak subscribedTicket
379319 return subscribedTicket
380320 liftIO $ cacheSubscription sub mSubscribedRef subscribedTicket
381321
382−cacheSubscription :: Subscriber x a -> IORef (FastWeak (CacheSubscribed x a))
322+cacheSubscription :: Subscriber x a -> IORef (FastWeak (CacheSubscribed x a))
383323 -> FastWeakTicket (CacheSubscribed x a) -> IO (EventSubscription x, Maybe a)
384−cacheSubscription sub mSubscribedRef subscribedTicket = do
324+cacheSubscription sub mSubscribedRef subscribedTicket = do
385325 subscribed <- getFastWeakTicketValue subscribedTicket
386326 ticket <- FastWeakBag.insert sub $ _cacheSubscribed_subscribers subscribed
387327 occ <- readIORef $ _cacheSubscribed_occurrence subscribed
388−
328+
389329 let parentSub = _cacheSubscribed_parent subscribed
390330 es = EventSubscription
391331 { _eventSubscription_unsubscribe = do
@@ -404,9 +344,9 @@ cacheSubscription sub mSubscribedRef subscribedTicket = do
404344 , eventSubscribedGetParents = return [_eventSubscription_subscribed parentSub]
405345 , eventSubscribedHasOwnHeightRef = False
406346 , eventSubscribedWhoCreated = whoCreatedIORef mSubscribedRef
407−#endif
347+#endif
408348 }
409− }
349+ }
410350 return (es, occ)
411351
412352
@@ -464,6 +404,16 @@ data Subscriber x a = Subscriber
464404 , subscriberRecalculateHeight :: !(Height -> IO ())
465405 }
466406
407+--TODO: Move this comment to WeakBag
408+-- These function are constructor functions that are marked NOINLINE so they are
409+-- opaque to GHC. If we do not do this, then GHC will sometimes fuse the constructor away
410+-- so any weak references that are attached to the constructors will have their
411+-- finalizer run. Using the opaque constructor, does not see the
412+-- constructor application, so it behaves like an IORef and cannot be fused away.
413+--
414+-- The result is also evaluated to WHNF, since forcing a thunk invalidates
415+-- the weak pointer to it in some cases.
416+
467417newSubscriberHold :: (HasSpiderTimeline x, Patch p) => Hold x p -> IO (Subscriber x p)
468418newSubscriberHold h = return $ Subscriber
469419 { subscriberPropagate = {-# SCC "traverseHold" #-} propagateSubscriberHold h
@@ -485,12 +435,14 @@ newSubscriberFan subscribed = debugSubscriber ("SubscriberFan " <> showNodeId su
485435 return ()
486436 , subscriberInvalidateHeight = \old -> do
487437 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
488− forM_ (DMap.toList subscribers) $ \(_ :=> v) -> WeakBag.traverse_ (_fanSubscribedChildren_list v) $ invalidateSubscriberHeight old
438+ forM_ (DMap.toList subscribers) $ \(_ :=> v) -> WeakBag.traverse (_fanSubscribedChildren_list v) $ invalidateSubscriberHeight old
439+
489440 , subscriberRecalculateHeight = \new -> do
490441 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
491− forM_ (DMap.toList subscribers) $ \(_ :=> v) -> WeakBag.traverse_ (_fanSubscribedChildren_list v) $ recalculateSubscriberHeight new
442+ forM_ (DMap.toList subscribers) $ \(_ :=> v) -> WeakBag.traverse (_fanSubscribedChildren_list v) $ recalculateSubscriberHeight new
492443 }
493444
445+
494446newSubscriberSwitch :: forall x a. HasSpiderTimeline x => SwitchSubscribed x a -> IO (Subscriber x a)
495447newSubscriberSwitch subscribed = debugSubscriber ("SubscriberCoincidenceOuter" <> showNodeId subscribed) $ Subscriber
496448 { subscriberPropagate = \a -> {-# SCC "traverseSwitch" #-} do
@@ -501,7 +453,7 @@ newSubscriberSwitch subscribed = debugSubscriber ("SubscriberCoincidenceOuter" <
501453 oldHeight <- readIORef $ switchSubscribedHeight subscribed
502454 when (oldHeight /= invalidHeight) $ do
503455 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
504− WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
456+ WeakBag.traverse (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
505457 , subscriberRecalculateHeight = (`updateSwitchHeight` subscribed)
506458 }
507459
@@ -517,17 +469,17 @@ newSubscriberCoincidenceOuter subscribed = debugSubscriber ("SubscriberCoinciden
517469 liftIO $ writeIORef (coincidenceSubscribedInnerParent subscribed) $ Just innerSubd
518470 scheduleClear $ coincidenceSubscribedInnerParent subscribed
519471 case occ of
520− Nothing ->
472+ Nothing ->
521473 when (innerHeight > outerHeight) $ liftIO $ do -- If the event fires, it will fire at a later height
522474 writeIORef (coincidenceSubscribedHeight subscribed) $! innerHeight
523− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight outerHeight
524− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight innerHeight
475+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight outerHeight
476+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight innerHeight
525477 Just o -> do -- Since it's already firing, no need to adjust height
526478 liftIO $ writeIORef (coincidenceSubscribedOccurrence subscribed) occ
527479 scheduleClear $ coincidenceSubscribedOccurrence subscribed
528480 propagate o $ coincidenceSubscribedSubscribers subscribed
529481 , subscriberInvalidateHeight = \_ -> invalidateCoincidenceHeight subscribed
530− , subscriberRecalculateHeight = \_ -> recalculateCoincidenceHeight subscribed
482+ , subscriberRecalculateHeight = \_ -> recalculateCoincidenceHeight subscribed
531483 }
532484
533485newSubscriberCoincidenceInner :: forall x a. HasSpiderTimeline x => CoincidenceSubscribed x a -> IO (Subscriber x a)
@@ -548,21 +500,21 @@ invalidateSubscriberHeight :: Height -> Subscriber x a -> IO ()
548500invalidateSubscriberHeight = flip subscriberInvalidateHeight
549501
550502recalculateSubscriberHeight :: Height -> Subscriber x a -> IO ()
551−recalculateSubscriberHeight = flip subscriberRecalculateHeight
503+recalculateSubscriberHeight = flip subscriberRecalculateHeight
552504
553505-- | Propagate everything at the current height
554506propagate :: forall x a. HasSpiderTimeline x => a -> WeakBag (Subscriber x a) -> EventM x ()
555−propagate a subscribers = withIncreasedDepth (Proxy::Proxy x) $
507+propagate a subscribers = withIncreasedDepth (Proxy::Proxy x) $
556508 -- Note: in the following traversal, we do not visit nodes that are added to the list during our traversal; they are new events, which will necessarily have full information already, so there is no need to traverse them
557509 --TODO: Should we check if nodes already have their values before propagating? Maybe we're re-doing work
558− WeakBag.traverse_ subscribers $ \s -> subscriberPropagate s a
510+ WeakBag.traverse subscribers $ \s -> subscriberPropagate s a
559511
560512-- | Propagate everything at the current height
561513propagateFast :: forall x a. HasSpiderTimeline x => a -> FastWeakBag (Subscriber x a) -> EventM x ()
562−propagateFast a subscribers = withIncreasedDepth (Proxy::Proxy x) $
514+propagateFast a subscribers = withIncreasedDepth (Proxy::Proxy x) $
563515 -- Note: in the following traversal, we do not visit nodes that are added to the list during our traversal; they are new events, which will necessarily have full information already, so there is no need to traverse them
564516 --TODO: Should we check if nodes already have their values before propagating? Maybe we're re-doing work
565− FastWeakBag.traverse_ subscribers $ \s -> subscriberPropagate s a
517+ FastWeakBag.traverse subscribers $ \s -> subscriberPropagate s a
566518
567519--------------------------------------------------------------------------------
568520-- EventSubscribed
@@ -607,16 +559,6 @@ eventSubscribedNever = EventSubscribed
607559 , eventSubscribedWhoCreated = return ["never"]
608560#endif
609561 }
610−eventSubscribedNow :: EventSubscribed x
611−eventSubscribedNow = EventSubscribed
612− { eventSubscribedHeightRef = zeroRef
613− , eventSubscribedRetained = toAny ()
614−#ifdef DEBUG_CYCLES
615− , eventSubscribedGetParents = return []
616− , eventSubscribedHasOwnHeightRef = False
617− , eventSubscribedWhoCreated = return ["now"]
618−#endif
619− }
620562
621563eventSubscribedFan :: FanSubscribed x k v -> EventSubscribed x
622564eventSubscribedFan !subscribed = EventSubscribed
@@ -994,10 +936,8 @@ instance Monad (BehaviorM x) where
994936 BehaviorM x >> BehaviorM y = BehaviorM $ x >> y
995937 {-# INLINE return #-}
996938 return x = BehaviorM $ return x
997−#if !MIN_VERSION_base(4,13,0)
998939 {-# INLINE fail #-}
999940 fail s = BehaviorM $ fail s
1000−#endif
1001941
1002942data BehaviorSubscribed x a
1003943 = forall p. BehaviorSubscribedHold (Hold x p)
@@ -1057,7 +997,7 @@ data SomeMergeUpdate x = SomeMergeUpdate
1057997newtype SomeMergeInit x = SomeMergeInit { unSomeMergeInit :: EventM x () }
1058998
1059999-- EventM can do everything BehaviorM can, plus create holds
1060−newtype EventM x a = EventM { unEventM :: IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadException, MonadAsyncException)
1000+newtype EventM x a = EventM { unEventM :: IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadException, MonadAsyncException)
10611001
10621002newtype MergeSubscribedParent x a = MergeSubscribedParent { unMergeSubscribedParent :: EventSubscription x }
10631003
@@ -1082,7 +1022,7 @@ heightBagFromList :: [Height] -> HeightBag
10821022heightBagFromList heights = heightBagVerify $ foldl' (flip heightBagAdd) heightBagEmpty heights
10831023
10841024heightBagAdd :: Height -> HeightBag -> HeightBag
1085−heightBagAdd (Height h) (HeightBag s c) = heightBagVerify $ HeightBag (succ s) $
1025+heightBagAdd (Height h) (HeightBag s c) = heightBagVerify $ HeightBag (succ s) $
10861026 IntMap.insertWithKey (\_ _ old -> succ old) h 0 c
10871027
10881028heightBagRemove :: Height -> HeightBag -> HeightBag
@@ -1093,11 +1033,11 @@ heightBagRemove (Height h) b@(HeightBag s c) = heightBagVerify $ case IntMap.loo
10931033 _ -> IntMap.insert h (pred old) c
10941034
10951035heightBagRemoveMaybe :: Height -> HeightBag -> Maybe HeightBag
1096−heightBagRemoveMaybe (Height h) b@(HeightBag s c) = heightBagVerify . removed <$> IntMap.lookup h c where
1036+heightBagRemoveMaybe (Height h) b@(HeightBag s c) = heightBagVerify . removed <$> IntMap.lookup h c where
10971037 removed old = HeightBag (pred s) $ case old of
10981038 0 -> IntMap.delete h c
10991039 _ -> IntMap.insert h (pred old) c
1100−
1040+
11011041
11021042heightBagMax :: HeightBag -> Height
11031043heightBagMax (HeightBag _ c) = case IntMap.maxViewWithKey c of
@@ -1199,10 +1139,7 @@ instance HasSpiderTimeline x => Semialign (Event x) where
11991139 align ea eb = mapMaybe dmapToThese $ mergeG coerce $ dynamicConst $
12001140 DMap.fromDistinctAscList [LeftTag :=> ea, RightTag :=> eb]
12011141
1202−#ifdef MIN_VERSION_semialign
1203−#if MIN_VERSION_semialign(1,1,0)
1204−instance HasSpiderTimeline x => Zip (Event x) where
1205−#endif
1142+#if defined(MIN_VERSION_semialign)
12061143 zip x y = mapMaybe justThese $ align x y
12071144#endif
12081145
@@ -1346,7 +1283,7 @@ mkWeakPtrWithDebug x debugNote = do
13461283 x' <- evaluate x
13471284 mkWeakPtr x' $
13481285 if debugFinalize
1349− then Just $ debugStrLn $ "finalizing: " ++ debugNote
1286+ then Just $ putStrLn $ "finalizing: " ++ debugNote
13501287 else Nothing
13511288
13521289type WeakList a = [Weak a]
@@ -1361,20 +1298,21 @@ type CanTrace x m = (HasSpiderTimeline x, MonadIO m)
13611298debugSubscriber :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> IO (Subscriber x a)
13621299debugSubscriber description = return . debugSubscriber' description
13631300
1301+
13641302debugSubscriber' :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> Subscriber x a
1365−debugSubscriber' description subscribed = Subscriber
1303+debugSubscriber' description subscribed = Subscriber
13661304 {
13671305 subscriberPropagate = \m -> do
13681306 tracePropagate (Proxy :: Proxy x) ("subscriberPropagate: " <> description)
13691307 subscriberPropagate subscribed m
13701308 , subscriberInvalidateHeight = \old -> do
1371− traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
1309+ putStrLn $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
13721310 subscriberInvalidateHeight subscribed old
1373− traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", done"
1311+ putStrLn $ "invalidateSubscriberHeight: " <> description <> ", done"
13741312 , subscriberRecalculateHeight = \new -> do
1375− traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
1313+ putStrLn $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
13761314 subscriberRecalculateHeight subscribed new
1377− traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", done"
1315+ putStrLn $ "subscriberRecalculateHeight: " <> description <> ", done"
13781316 }
13791317
13801318
@@ -1388,15 +1326,11 @@ withIncreasedDepth _ a = do
13881326
13891327{-# INLINE tracePropagate #-}
13901328tracePropagate :: (CanTrace x m) => proxy x -> String -> m ()
1391−tracePropagate p = when debugPropagate . trace p
1329+tracePropagate p = trace p
13921330
13931331{-# INLINE traceInvalidate #-}
13941332traceInvalidate :: String -> IO ()
1395−traceInvalidate = when debugInvalidate . liftIO . debugStrLn
1396−
1397−{-# INLINE traceInvalidateHeight #-}
1398−traceInvalidateHeight :: String -> IO ()
1399−traceInvalidateHeight = when debugInvalidateHeight . liftIO . debugStrLn
1333+traceInvalidate = liftIO . putStrLn
14001334
14011335{-# INLINE trace #-}
14021336trace :: (CanTrace x m) => proxy x -> String -> m ()
@@ -1407,7 +1341,7 @@ traceM :: forall x proxy m. (CanTrace x m) => proxy x -> m String -> m ()
14071341traceM _ getMessage = do
14081342 message <- getMessage
14091343 d <- liftIO $ readIORef $ _spiderTimeline_depth $ unSTE (spiderTimeline :: SpiderTimelineEnv x)
1410− liftIO $ debugStrLn $ replicate d ' ' <> message
1344+ liftIO $ putStrLn $ replicate d ' ' <> message
14111345
14121346#else
14131347
@@ -1423,20 +1357,10 @@ tracePropagate _ _ = return ()
14231357traceInvalidate :: String -> IO ()
14241358traceInvalidate _ = return ()
14251359
1426−{-# INLINE traceInvalidateHeight #-}
1427−traceInvalidateHeight :: String -> IO ()
1428−traceInvalidateHeight _ = return ()
1429−
14301360{-# INLINE debugSubscriber #-}
14311361debugSubscriber :: String -> Subscriber x a -> IO (Subscriber x a)
14321362debugSubscriber _ = return
14331363
1434−{-# INLINE debugSubscriber' #-}
1435−debugSubscriber' :: String -> Subscriber x a -> Subscriber x a
1436−debugSubscriber' _ = id
1437−
1438−
1439−
14401364{-# INLINE trace #-}
14411365trace :: (CanTrace x m) => proxy x -> String -> m ()
14421366trace _ _ = return ()
@@ -1467,20 +1391,17 @@ showStacks :: [[String]] -> String
14671391showStacks = drawForest . listsToForest . fmap (filterStack "Reflex.Spider.Internal")
14681392
14691393filterStack :: String -> [String] -> [String]
1470−#ifdef DEBUG_HIDE_INTERNALS
14711394filterStack prefix = filter (not . (prefix `isPrefixOf`))
1472−#else
1473−filterStack prefix = id
1474−#endif
1395+
14751396
14761397#ifdef DEBUG_CYCLES
14771398
1478−data EventLoopException = EventLoopException [[String]]
1399+data EventLoopException = EventLoopException [[String]]
14791400instance Exception EventLoopException
14801401
14811402instance Show EventLoopException where
1482− show (EventLoopException stacks) = "causality loop detected:\n" <> if null stacks
1483− then "no location information, compile with profiling enabled for stack tree"
1403+ show (EventLoopException stacks) = "causality loop detected:\n" <> if null stacks
1404+ then "no location information, compile with profiling enabled for stack tree"
14841405 else showStacks stacks
14851406
14861407#else
@@ -1498,7 +1419,7 @@ instance Show EventLoopException where
14981419{-# INLINE propagateSubscriberHold #-}
14991420propagateSubscriberHold :: forall x p. (HasSpiderTimeline x, Patch p) => Hold x p -> p -> EventM x ()
15001421propagateSubscriberHold h a = do
1501− {-# SCC "trace" #-} when debugPropagate $ traceM (Proxy :: Proxy x) $ liftIO $ do
1422+ traceM (Proxy :: Proxy x) $ liftIO $ do
15021423 invalidators <- liftIO $ readIORef $ holdInvalidators h
15031424 return $ "SubscriberHold" <> showNodeId h <> ": " ++ show (length invalidators)
15041425
@@ -1506,7 +1427,7 @@ propagateSubscriberHold h a = do
15061427 case {-# SCC "apply" #-} apply a v of
15071428 Nothing -> return ()
15081429 Just v' -> do
1509− {-# SCC "trace2" #-} withIncreasedDepth (Proxy :: Proxy x) $
1430+ withIncreasedDepth (Proxy :: Proxy x) $
15101431 tracePropagate (Proxy :: Proxy x) ("propagateSubscriberHold: assigning Hold" <> showNodeId h)
15111432 vRef <- {-# SCC "vRef" #-} liftIO $ evaluate $ holdValue h
15121433 iRef <- {-# SCC "iRef" #-} liftIO $ evaluate $ holdInvalidators h
@@ -1627,7 +1548,7 @@ data FanInt x a = FanInt
16271548 { _fanInt_subscribers :: {-# UNPACK #-} !(FastMutableIntMap (FastWeakBag (Subscriber x a))) --TODO: Clean up the keys in here when their child weak bags get empty --TODO: Remove our own subscription when the subscribers list is completely empty
16281549 , _fanInt_subscriptionRef :: {-# UNPACK #-} !(IORef (EventSubscription x)) -- This should have a valid subscription iff subscribers is non-empty
16291550 , _fanInt_occRef :: {-# UNPACK #-} !(IORef (IntMap a))
1630−#ifdef DEBUG_NODEIDS
1551+#ifdef DEBUG_NODEIDS
16311552 , _fanInt_nodeId :: {-# UNPACK #-} !Int
16321553#endif
16331554 }
@@ -1637,15 +1558,15 @@ newFanInt = do
16371558 subscribers <- FastMutableIntMap.newEmpty --TODO: Clean up the keys in here when their child weak bags get empty --TODO: Remove our own subscription when the subscribers list is completely empty
16381559 subscriptionRef <- newIORef $ error "fanInt: no subscription"
16391560 occRef <- newIORef $ error "fanInt: no occurrence"
1640−#ifdef DEBUG_NODEIDS
1561+#ifdef DEBUG_NODEIDS
16411562 nodeId <- newNodeId
16421563#endif
16431564 return $ FanInt
16441565 { _fanInt_subscribers = subscribers
16451566 , _fanInt_subscriptionRef = subscriptionRef
16461567 , _fanInt_occRef = occRef
1647−#ifdef DEBUG_NODEIDS
1648− , _fanInt_nodeId = nodeId
1568+#ifdef DEBUG_NODEIDS
1569+ , _fanInt_nodeId = nodeId
16491570#endif
16501571 }
16511572
@@ -1661,15 +1582,15 @@ fanInt p = unsafePerformIO $ do
16611582 liftIO $ writeIORef (_fanInt_occRef self) m
16621583 scheduleIntClear $ _fanInt_occRef self
16631584 FastMutableIntMap.forIntersectionWithImmutable_ (_fanInt_subscribers self) m $ \b v -> --TODO: Do we need to know that no subscribers are being added as we traverse?
1664− FastWeakBag.traverse_ b $ \s ->
1585+ FastWeakBag.traverse b $ \s ->
16651586 subscriberPropagate s v
1666− , subscriberInvalidateHeight = \old ->
1667− FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1668− FastWeakBag.traverse_ b $ \s ->
1587+ , subscriberInvalidateHeight = \old ->
1588+ FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1589+ FastWeakBag.traverse b $ \s ->
16691590 subscriberInvalidateHeight s old
16701591 , subscriberRecalculateHeight = \new ->
1671− FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1672− FastWeakBag.traverse_ b $ \s ->
1592+ FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1593+ FastWeakBag.traverse b $ \s ->
16731594 subscriberRecalculateHeight s new
16741595 }
16751596 liftIO $ do
@@ -1685,14 +1606,14 @@ fanInt p = unsafePerformIO $ do
16851606 Just b -> return b
16861607 ticket <- liftIO $ FastWeakBag.insert sub b
16871608 currentOcc <- readIORef (_fanInt_occRef self)
1688−
1609+
16891610 subscribed <- fanIntSubscribed ticket self
16901611 return (EventSubscription (FastWeakBag.remove ticket) subscribed, IntMap.lookup k currentOcc)
16911612
16921613fanIntSubscribed :: FastWeakBagTicket k -> FanInt x a -> IO (EventSubscribed x)
1693−fanIntSubscribed ticket self = do
1614+fanIntSubscribed ticket self = do
16941615 subscribedParent <- _eventSubscription_subscribed <$> readIORef (_fanInt_subscriptionRef self)
1695− return $ EventSubscribed
1616+ return $ EventSubscribed
16961617 { eventSubscribedHeightRef = eventSubscribedHeightRef subscribedParent
16971618 , eventSubscribedRetained = toAny (_fanInt_subscriptionRef self, ticket)
16981619#ifdef DEBUG_CYCLES
@@ -1701,7 +1622,7 @@ fanIntSubscribed ticket self = do
17011622 , eventSubscribedWhoCreated = whoCreatedIORef $ _fanInt_subscriptionRef self
17021623#endif
17031624 }
1704−
1625+
17051626
17061627{-# INLINABLE getFanSubscribed #-}
17071628getFanSubscribed :: (HasSpiderTimeline x, GCompare k) => k a -> Fan x k v -> Subscriber x (v a) -> EventM x (WeakBagTicket, FanSubscribed x k v, Maybe (v a))
@@ -1914,7 +1835,7 @@ mergeCheap nt = mergeGCheap' unMergeSubscribedParent getInitialSubscribers updat
19141835 liftIO $ modifyIORef' heightBagRef $ heightBagAdd newParentHeight
19151836 return $ DMap.insertLookupWithKey' (\_ new _ -> new) k newParent ps
19161837 forM_ mOldSubd $ \oldSubd -> do
1917− oldHeight <- liftIO $ getEventSubscribedHeight $
1838+ oldHeight <- liftIO $ getEventSubscribedHeight $
19181839 _eventSubscription_subscribed $ unMergeSubscribedParent oldSubd
19191840
19201841 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
@@ -1960,7 +1881,7 @@ mergeCheapWithMove nt = mergeGCheap' _mergeSubscribedParentWithMove_subscription
19601881 let moveOrDelete :: forall a. k a -> PatchDMapWithMove.NodeInfo k q a -> MergeSubscribedParentWithMove x k a -> Constant (EventM x (Maybe (EventSubscription x))) a
19611882 moveOrDelete _ ni parent = Constant $ case getComposeMaybe $ PatchDMapWithMove._nodeInfo_to ni of
19621883 Nothing -> do
1963− oldHeight <- liftIO $ getEventSubscribedHeight $ _eventSubscription_subscribed $
1884+ oldHeight <- liftIO $ getEventSubscribedHeight $ _eventSubscription_subscribed $
19641885 _mergeSubscribedParentWithMove_subscription parent
19651886
19661887 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
@@ -1968,7 +1889,7 @@ mergeCheapWithMove nt = mergeGCheap' _mergeSubscribedParentWithMove_subscription
19681889 Just toKey -> do
19691890 liftIO $ writeIORef (_mergeSubscribedParentWithMove_key parent) $! toKey
19701891 return Nothing
1971− toDelete <- fmap catMaybes $ mapM (\(_ :=> v) -> getConstant v) $ DMap.toList $
1892+ toDelete <- fmap catMaybes $ mapM (\(_ :=> v) -> getConstant v) $ DMap.toList $
19721893 DMap.intersectionWithKey moveOrDelete (unPatchDMapWithMove p) oldParents
19731894
19741895 return (toDelete, applyAlways p' oldParents)
@@ -2021,16 +1942,16 @@ invalidateMergeHeight' :: IORef Height -> Subscriber x a -> IO ()
20211942invalidateMergeHeight' heightRef sub = do
20221943 oldHeight <- readIORef heightRef
20231944 -- If the height used to be valid, it must be invalid now; we should never have *more* heights than we have parents
2024− when (oldHeight /= invalidHeight) $ do
1945+ when (oldHeight /= invalidHeight) $ do
20251946 writeIORef heightRef $! invalidHeight
20261947 subscriberInvalidateHeight sub oldHeight
20271948
20281949revalidateMergeHeight :: Merge x k v s -> IO ()
20291950revalidateMergeHeight m = do
20301951 currentHeight <- readIORef $ _merge_heightRef m
2031−
1952+
20321953 -- revalidateMergeHeight may be called multiple times; perhaps the's a way to finesse it to avoid this check
2033− when (currentHeight == invalidHeight) $ do
1954+ when (currentHeight == invalidHeight) $ do
20341955 heights <- readIORef $ _merge_heightBagRef m
20351956 parents <- readIORef $ _merge_parentsRef m
20361957 -- When the number of heights in the bag reaches the number of parents, we should have a valid height
@@ -2038,7 +1959,7 @@ revalidateMergeHeight m = do
20381959 LT -> return ()
20391960 EQ -> do
20401961 let height = succHeight $ heightBagMax heights
2041− traceInvalidateHeight $ "recalculateSubscriberHeight: height: " <> show height
1962+ traceInvalidate $ "recalculateSubscriberHeight: height: " <> show height
20421963 writeIORef (_merge_heightRef m) $! height
20431964 subscriberRecalculateHeight (_merge_sub m) height
20441965 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show (DMap.size parents) <> ") for Merge"
@@ -2046,22 +1967,22 @@ revalidateMergeHeight m = do
20461967scheduleMergeSelf :: HasSpiderTimeline x => Merge x k v s -> Height -> EventM x ()
20471968scheduleMergeSelf m height = scheduleMerge' height (_merge_heightRef m) $ do
20481969 vals <- liftIO $ readIORef $ _merge_accumRef m
2049− -- Once we're done with this, we can clear it immediately, because if there's a cacheEvent in front of us,
1970+ -- Once we're done with this, we can clear it immediately, because if there's a cacheEvent in front of us,
20501971 -- it'll handle subsequent subscribers, and if not, we won't get subsequent subscribers
2051− liftIO $ writeIORef (_merge_accumRef m) $! DMap.empty
1972+ liftIO $ writeIORef (_merge_accumRef m) $! DMap.empty
20521973 --TODO: Assert that m is not empty
20531974 subscriberPropagate (_merge_sub m) vals
20541975
20551976checkCycle :: HasSpiderTimeline x => EventSubscribed x -> EventM x ()
20561977checkCycle subscribed = liftIO $ do
20571978 height <- readIORef (eventSubscribedHeightRef subscribed)
2058−
1979+
20591980 -- currentHeight <- getCurrentHeight
20601981 -- when (height <= currentHeight) $ if height /= invalidHeight
20611982 -- then do
20621983 -- myStack <- liftIO $ whoCreatedIORef undefined --TODO
20631984 -- error $ "Height (" ++ show height ++ ") is not greater than current height (" ++ show currentHeight ++ ")\n" ++ unlines (reverse myStack)
2064− -- else liftIO $
1985+ -- else liftIO $
20651986 when (height == invalidHeight) $
20661987#ifdef DEBUG_CYCLES
20671988 do
@@ -2114,17 +2035,17 @@ mergeGCheap' getParent getInitialSubscribers updateFunc destroy d = Event $ \sub
21142035 parentsRef :: IORef (DMap k s) <- liftIO $ newIORef $ error "merge: parentsRef not yet initialized"
21152036 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
21162037
2117− let subscribed = EventSubscribed
2118− { eventSubscribedHeightRef = heightRef
2038+ let subscribed = EventSubscribed
2039+ { eventSubscribedHeightRef = heightRef
21192040 , eventSubscribedRetained = toAny (parentsRef, changeSubdRef)
21202041#ifdef DEBUG_CYCLES
21212042 , eventSubscribedGetParents = do
21222043 let getParent' (_ :=> v) = _eventSubscription_subscribed (getParent v)
2123− fmap getParent' . DMap.toList <$> readIORef parentsRef
2044+ fmap getParent' . DMap.toList <$> readIORef parentsRef
21242045 , eventSubscribedHasOwnHeightRef = False
21252046 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2126−#endif
2127− }
2047+#endif
2048+ }
21282049
21292050 m = Merge
21302051 { _merge_parentsRef = parentsRef
@@ -2162,9 +2083,9 @@ mergeGCheap' getParent getInitialSubscribers updateFunc destroy d = Event $ \sub
21622083 -- its subscription.
21632084 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
21642085 let unsubscribeAll = destroy =<< readIORef parentsRef
2165−
2086+
21662087 return (EventSubscription unsubscribeAll subscribed, occ)
2167−
2088+
21682089
21692090mergeInt :: forall x a. (HasSpiderTimeline x) => DynamicS x (PatchIntMap (Event x a)) -> Event x (IntMap a)
21702091mergeInt = cacheEvent . mergeIntCheap
@@ -2178,14 +2099,14 @@ mergeIntCheap d = Event $ \sub -> do
21782099 heightBagRef <- liftIO $ newIORef heightBagEmpty
21792100 parents <- liftIO $ FastMutableIntMap.newEmpty
21802101 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
2181− let subscribed = EventSubscribed
2182− { eventSubscribedHeightRef = heightRef
2102+ let subscribed = EventSubscribed
2103+ { eventSubscribedHeightRef = heightRef
21832104 , eventSubscribedRetained = toAny (parents, changeSubdRef)
21842105#ifdef DEBUG_CYCLES
21852106 , eventSubscribedGetParents = fmap (_eventSubscription_subscribed . snd) <$> FastMutableIntMap.toList parents
21862107 , eventSubscribedHasOwnHeightRef = False
21872108 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2188−#endif
2109+#endif
21892110 }
21902111 let scheduleSelf = do
21912112 height <- liftIO $ readIORef $ heightRef
@@ -2202,7 +2123,7 @@ mergeIntCheap d = Event $ \sub -> do
22022123 LT -> return ()
22032124 EQ -> do
22042125 let height = succHeight $ heightBagMax heights
2205− traceInvalidateHeight $ "recalculateSubscriberHeight: height: " <> show height
2126+ traceInvalidate $ "recalculateSubscriberHeight: height: " <> show height
22062127 writeIORef heightRef $! height
22072128 subscriberRecalculateHeight sub height
22082129 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show numParents <> ") for Merge"
@@ -2274,7 +2195,7 @@ mergeIntCheap d = Event $ \sub -> do
22742195 -- its subscription.
22752196 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
22762197 let unsubscribeAll = traverse_ unsubscribe =<< FastMutableIntMap.getFrozenAndClear parents
2277−
2198+
22782199
22792200 return (EventSubscription unsubscribeAll subscribed, occ)
22802201
@@ -2385,7 +2306,7 @@ runFrame a = SpiderHost $ do
23852306 subscription <- unSpiderHost $ runFrame $ {-# SCC "subscribeSwitch" #-} subscribe e sub --TODO: Assert that the event isn't firing --TODO: This should not loop because none of the events should be firing, but still, it is inefficient
23862307 {-
23872308 stackTrace <- liftIO $ fmap renderStack $ ccsToStrings =<< (getCCSOf $! switchSubscribedParent subscribed)
2388− liftIO $ debugStrLn $ (++stackTrace) $ "subd' subscribed to " ++ case e of
2309+ liftIO $ putStrLn $ (++stackTrace) $ "subd' subscribed to " ++ case e of
23892310 EventRoot _ -> "EventRoot"
23902311 EventNever -> "EventNever"
23912312 _ -> "something else"
@@ -2400,7 +2321,7 @@ runFrame a = SpiderHost $ do
24002321 myHeight <- readIORef $ switchSubscribedHeight subscribed
24012322 when (parentHeight /= myHeight) $ do
24022323 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
2403− WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight myHeight
2324+ WeakBag.traverse (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight myHeight
24042325 mapM_ _someMergeUpdate_invalidateHeight mergeUpdates --TODO: In addition to when the patch is completely empty, we should also not run this if it has some Nothing values, but none of them have actually had any effect; potentially, we could even check for Just values with no effect (e.g. by comparing their IORefs and ignoring them if they are unchanged); actually, we could just check if the new height is different
24052326 forM_ coincidenceInfos $ \(SomeResetCoincidence subscription mcs) -> do
24062327 unsubscribe subscription
@@ -2441,7 +2362,7 @@ invalidateCoincidenceHeight subscribed = do
24412362 oldHeight <- readIORef $ coincidenceSubscribedHeight subscribed
24422363 when (oldHeight /= invalidHeight) $ do
24432364 writeIORef (coincidenceSubscribedHeight subscribed) $! invalidHeight
2444− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
2365+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
24452366
24462367updateSwitchHeight :: Height -> SwitchSubscribed x a -> IO ()
24472368updateSwitchHeight new subscribed = do
@@ -2449,7 +2370,7 @@ updateSwitchHeight new subscribed = do
24492370 when (oldHeight == invalidHeight) $ do --TODO: This 'when' should probably be an assertion
24502371 when (new /= invalidHeight) $ do --TODO: This 'when' should probably be an assertion
24512372 writeIORef (switchSubscribedHeight subscribed) $! new
2452− WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ recalculateSubscriberHeight new
2373+ WeakBag.traverse (switchSubscribedSubscribers subscribed) $ recalculateSubscriberHeight new
24532374
24542375recalculateCoincidenceHeight :: CoincidenceSubscribed x a -> IO ()
24552376recalculateCoincidenceHeight subscribed = do
@@ -2458,7 +2379,7 @@ recalculateCoincidenceHeight subscribed = do
24582379 height <- calculateCoincidenceHeight subscribed
24592380 when (height /= invalidHeight) $ do
24602381 writeIORef (coincidenceSubscribedHeight subscribed) $! height
2461− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight height
2382+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight height
24622383
24632384calculateSwitchHeight :: SwitchSubscribed x a -> IO Height
24642385calculateSwitchHeight subscribed = getEventSubscribedHeight . _eventSubscription_subscribed =<< readIORef (switchSubscribedCurrentParent subscribed)
@@ -2520,8 +2441,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Event
25202441 {-# INLINABLE headE #-}
25212442 headE = R.slowHeadE
25222443-- headE (SpiderEvent e) = SpiderEvent <$> Reflex.Spider.Internal.headE e
2523− {-# INLINABLE now #-}
2524− now = nowSpiderEventM
25252444
25262445instance Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPullM x) where
25272446 {-# INLINABLE sample #-}
@@ -2543,9 +2462,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
25432462 {-# INLINABLE headE #-}
25442463 headE = R.slowHeadE
25452464-- headE (SpiderEvent e) = SpiderPushM $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2546− {-# INLINABLE now #-}
2547− now = SpiderPushM nowSpiderEventM
2548−
25492465
25502466instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
25512467 {-# INLINE return #-}
@@ -2554,10 +2470,8 @@ instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x))
25542470 x >>= f = SpiderDynamic $ dynamicDynIdentity $ newJoinDyn $ newMapDyn (unSpiderDynamic . f) $ unSpiderDynamic x
25552471 {-# INLINE (>>) #-}
25562472 (>>) = (*>)
2557−#if !MIN_VERSION_base(4,13,0)
25582473 {-# INLINE fail #-}
25592474 fail _ = error "Dynamic does not support 'fail'"
2560−#endif
25612475
25622476{-# INLINABLE newJoinDyn #-}
25632477newJoinDyn :: HasSpiderTimeline x => DynamicS x (Identity (DynamicS x (Identity a))) -> Reflex.Spider.Internal.Dyn x (Identity a)
@@ -2609,9 +2523,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
26092523 buildDynamic getV0 e = runFrame . runSpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
26102524 {-# INLINABLE headE #-}
26112525 headE e = runFrame . runSpiderHostFrame $ Reflex.Class.headE e
2612− {-# INLINABLE now #-}
2613− now = runFrame . runSpiderHostFrame $ Reflex.Class.now
2614−
26152526
26162527instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHostFrame x) where
26172528 sample = SpiderHostFrame . readBehaviorUntracked . unSpiderBehavior --TODO: This can cause problems with laziness, so we should get rid of it if we can
@@ -2628,8 +2539,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
26282539 {-# INLINABLE headE #-}
26292540 headE = R.slowHeadE
26302541-- headE (SpiderEvent e) = SpiderHostFrame $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2631− {-# INLINABLE now #-}
2632− now = SpiderHostFrame Reflex.Class.now
26332542
26342543instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHost x) where
26352544 {-# INLINABLE sample #-}
@@ -2650,8 +2559,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Refle
26502559 buildDynamic getV0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.buildDynamic getV0 e
26512560 {-# INLINABLE headE #-}
26522561 headE e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.headE e
2653− {-# INLINABLE now #-}
2654− now = Reflex.Spider.Internal.ReadPhase Reflex.Class.now
26552562
26562563--------------------------------------------------------------------------------
26572564-- Deprecated items
@@ -2775,7 +2682,7 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
27752682 fanG e = R.EventSelectorG $ SpiderEvent . selectG (fanG (unSpiderEvent e))
27762683 {-# INLINABLE mergeG #-}
27772684 mergeG
2778− :: forall k2 (k :: k2 -> *) q (v :: k2 -> *). GCompare k
2685+ :: forall (k :: k2 -> *) q (v :: k2 -> *). GCompare k
27792686 => (forall a. q a -> R.Event (SpiderTimeline x) (v a))
27802687 -> DMap k q
27812688 -> R.Event (SpiderTimeline x) (DMap k v)
@@ -2843,14 +2750,8 @@ instance Monad (SpiderHost x) where
28432750 SpiderHost x >> SpiderHost y = SpiderHost $ x >> y
28442751 {-# INLINABLE return #-}
28452752 return x = SpiderHost $ return x
2846−#if !MIN_VERSION_base(4,13,0)
2847− {-# INLINABLE fail #-}
2848− fail = MonadFail.fail
2849−#endif
2850−
2851−instance MonadFail (SpiderHost x) where
28522753 {-# INLINABLE fail #-}
2853− fail s = SpiderHost $ MonadFail.fail s
2754+ fail s = SpiderHost $ fail s
28542755
28552756-- | Run an action affecting the global Spider timeline; this will be guarded by
28562757-- a mutex for that timeline
@@ -2872,10 +2773,8 @@ instance Monad (SpiderHostFrame x) where
28722773 SpiderHostFrame x >> SpiderHostFrame y = SpiderHostFrame $ x >> y
28732774 {-# INLINABLE return #-}
28742775 return x = SpiderHostFrame $ return x
2875−#if !MIN_VERSION_base(4,13,0)
28762776 {-# INLINABLE fail #-}
28772777 fail s = SpiderHostFrame $ fail s
2878−#endif
28792778
28802779instance NotReady (SpiderTimeline x) (SpiderHostFrame x) where
28812780 notReadyUntil _ = pure ()
@@ -2920,11 +2819,3 @@ instance MonadAtomicRef (SpiderHostFrame x) where
29202819instance PrimMonad (SpiderHostFrame x) where
29212820 type PrimState (SpiderHostFrame x) = PrimState IO
29222821 primitive = SpiderHostFrame . EventM . primitive
2923−
2924−instance NotReady (SpiderTimeline x) (SpiderHost x) where
2925− notReadyUntil _ = return ()
2926− notReady = return ()
2927−
2928−instance HasSpiderTimeline x => NotReady (SpiderTimeline x) (PerformEventT (SpiderTimeline x) (SpiderHost x)) where
2929− notReadyUntil _ = return ()
2930− notReady = return ()