@@ -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
118−
119−-- TODO stdout might not be the best channel for debug output
120−debugStrLn :: String -> IO ()
121−debugStrLn = putStrLn
122111
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]
@@ -1362,19 +1299,19 @@ debugSubscriber :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -
13621299debugSubscriber description = return . debugSubscriber' description
13631300
13641301debugSubscriber' :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> Subscriber x a
1365−debugSubscriber' description subscribed = Subscriber
1302+debugSubscriber' description subscribed = Subscriber
13661303 {
13671304 subscriberPropagate = \m -> do
13681305 tracePropagate (Proxy :: Proxy x) ("subscriberPropagate: " <> description)
13691306 subscriberPropagate subscribed m
13701307 , subscriberInvalidateHeight = \old -> do
1371− traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
1308+ putStrLn $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
13721309 subscriberInvalidateHeight subscribed old
1373− traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", done"
1310+ putStrLn $ "invalidateSubscriberHeight: " <> description <> ", done"
13741311 , subscriberRecalculateHeight = \new -> do
1375− traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
1312+ putStrLn $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
13761313 subscriberRecalculateHeight subscribed new
1377− traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", done"
1314+ putStrLn $ "subscriberRecalculateHeight: " <> description <> ", done"
13781315 }
13791316
13801317
@@ -1388,15 +1325,11 @@ withIncreasedDepth _ a = do
13881325
13891326{-# INLINE tracePropagate #-}
13901327tracePropagate :: (CanTrace x m) => proxy x -> String -> m ()
1391−tracePropagate p = when debugPropagate . trace p
1328+tracePropagate p = trace p
13921329
13931330{-# INLINE traceInvalidate #-}
13941331traceInvalidate :: String -> IO ()
1395−traceInvalidate = when debugInvalidate . liftIO . debugStrLn
1396−
1397−{-# INLINE traceInvalidateHeight #-}
1398−traceInvalidateHeight :: String -> IO ()
1399−traceInvalidateHeight = when debugInvalidateHeight . liftIO . debugStrLn
1332+traceInvalidate = liftIO . putStrLn
14001333
14011334{-# INLINE trace #-}
14021335trace :: (CanTrace x m) => proxy x -> String -> m ()
@@ -1407,7 +1340,7 @@ traceM :: forall x proxy m. (CanTrace x m) => proxy x -> m String -> m ()
14071340traceM _ getMessage = do
14081341 message <- getMessage
14091342 d <- liftIO $ readIORef $ _spiderTimeline_depth $ unSTE (spiderTimeline :: SpiderTimelineEnv x)
1410− liftIO $ debugStrLn $ replicate d ' ' <> message
1343+ liftIO $ putStrLn $ replicate d ' ' <> message
14111344
14121345#else
14131346
@@ -1423,10 +1356,6 @@ tracePropagate _ _ = return ()
14231356traceInvalidate :: String -> IO ()
14241357traceInvalidate _ = return ()
14251358
1426−{-# INLINE traceInvalidateHeight #-}
1427−traceInvalidateHeight :: String -> IO ()
1428−traceInvalidateHeight _ = return ()
1429−
14301359{-# INLINE debugSubscriber #-}
14311360debugSubscriber :: String -> Subscriber x a -> IO (Subscriber x a)
14321361debugSubscriber _ = return
@@ -1467,20 +1396,17 @@ showStacks :: [[String]] -> String
14671396showStacks = drawForest . listsToForest . fmap (filterStack "Reflex.Spider.Internal")
14681397
14691398filterStack :: String -> [String] -> [String]
1470−#ifdef DEBUG_HIDE_INTERNALS
14711399filterStack prefix = filter (not . (prefix `isPrefixOf`))
1472−#else
1473−filterStack prefix = id
1474−#endif
1400+
14751401
14761402#ifdef DEBUG_CYCLES
14771403
1478−data EventLoopException = EventLoopException [[String]]
1404+data EventLoopException = EventLoopException [[String]]
14791405instance Exception EventLoopException
14801406
14811407instance 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"
1408+ show (EventLoopException stacks) = "causality loop detected:\n" <> if null stacks
1409+ then "no location information, compile with profiling enabled for stack tree"
14841410 else showStacks stacks
14851411
14861412#else
@@ -1498,7 +1424,7 @@ instance Show EventLoopException where
14981424{-# INLINE propagateSubscriberHold #-}
14991425propagateSubscriberHold :: forall x p. (HasSpiderTimeline x, Patch p) => Hold x p -> p -> EventM x ()
15001426propagateSubscriberHold h a = do
1501− {-# SCC "trace" #-} when debugPropagate $ traceM (Proxy :: Proxy x) $ liftIO $ do
1427+ traceM (Proxy :: Proxy x) $ liftIO $ do
15021428 invalidators <- liftIO $ readIORef $ holdInvalidators h
15031429 return $ "SubscriberHold" <> showNodeId h <> ": " ++ show (length invalidators)
15041430
@@ -1506,7 +1432,7 @@ propagateSubscriberHold h a = do
15061432 case {-# SCC "apply" #-} apply a v of
15071433 Nothing -> return ()
15081434 Just v' -> do
1509− {-# SCC "trace2" #-} withIncreasedDepth (Proxy :: Proxy x) $
1435+ withIncreasedDepth (Proxy :: Proxy x) $
15101436 tracePropagate (Proxy :: Proxy x) ("propagateSubscriberHold: assigning Hold" <> showNodeId h)
15111437 vRef <- {-# SCC "vRef" #-} liftIO $ evaluate $ holdValue h
15121438 iRef <- {-# SCC "iRef" #-} liftIO $ evaluate $ holdInvalidators h
@@ -1627,7 +1553,7 @@ data FanInt x a = FanInt
16271553 { _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
16281554 , _fanInt_subscriptionRef :: {-# UNPACK #-} !(IORef (EventSubscription x)) -- This should have a valid subscription iff subscribers is non-empty
16291555 , _fanInt_occRef :: {-# UNPACK #-} !(IORef (IntMap a))
1630−#ifdef DEBUG_NODEIDS
1556+#ifdef DEBUG_NODEIDS
16311557 , _fanInt_nodeId :: {-# UNPACK #-} !Int
16321558#endif
16331559 }
@@ -1637,15 +1563,15 @@ newFanInt = do
16371563 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
16381564 subscriptionRef <- newIORef $ error "fanInt: no subscription"
16391565 occRef <- newIORef $ error "fanInt: no occurrence"
1640−#ifdef DEBUG_NODEIDS
1566+#ifdef DEBUG_NODEIDS
16411567 nodeId <- newNodeId
16421568#endif
16431569 return $ FanInt
16441570 { _fanInt_subscribers = subscribers
16451571 , _fanInt_subscriptionRef = subscriptionRef
16461572 , _fanInt_occRef = occRef
1647−#ifdef DEBUG_NODEIDS
1648− , _fanInt_nodeId = nodeId
1573+#ifdef DEBUG_NODEIDS
1574+ , _fanInt_nodeId = nodeId
16491575#endif
16501576 }
16511577
@@ -1661,15 +1587,15 @@ fanInt p = unsafePerformIO $ do
16611587 liftIO $ writeIORef (_fanInt_occRef self) m
16621588 scheduleIntClear $ _fanInt_occRef self
16631589 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 ->
1590+ FastWeakBag.traverse b $ \s ->
16651591 subscriberPropagate s v
1666− , subscriberInvalidateHeight = \old ->
1667− FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1668− FastWeakBag.traverse_ b $ \s ->
1592+ , subscriberInvalidateHeight = \old ->
1593+ FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1594+ FastWeakBag.traverse b $ \s ->
16691595 subscriberInvalidateHeight s old
16701596 , subscriberRecalculateHeight = \new ->
1671− FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1672− FastWeakBag.traverse_ b $ \s ->
1597+ FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1598+ FastWeakBag.traverse b $ \s ->
16731599 subscriberRecalculateHeight s new
16741600 }
16751601 liftIO $ do
@@ -1685,14 +1611,14 @@ fanInt p = unsafePerformIO $ do
16851611 Just b -> return b
16861612 ticket <- liftIO $ FastWeakBag.insert sub b
16871613 currentOcc <- readIORef (_fanInt_occRef self)
1688−
1614+
16891615 subscribed <- fanIntSubscribed ticket self
16901616 return (EventSubscription (FastWeakBag.remove ticket) subscribed, IntMap.lookup k currentOcc)
16911617
16921618fanIntSubscribed :: FastWeakBagTicket k -> FanInt x a -> IO (EventSubscribed x)
1693−fanIntSubscribed ticket self = do
1619+fanIntSubscribed ticket self = do
16941620 subscribedParent <- _eventSubscription_subscribed <$> readIORef (_fanInt_subscriptionRef self)
1695− return $ EventSubscribed
1621+ return $ EventSubscribed
16961622 { eventSubscribedHeightRef = eventSubscribedHeightRef subscribedParent
16971623 , eventSubscribedRetained = toAny (_fanInt_subscriptionRef self, ticket)
16981624#ifdef DEBUG_CYCLES
@@ -1701,7 +1627,7 @@ fanIntSubscribed ticket self = do
17011627 , eventSubscribedWhoCreated = whoCreatedIORef $ _fanInt_subscriptionRef self
17021628#endif
17031629 }
1704−
1630+
17051631
17061632{-# INLINABLE getFanSubscribed #-}
17071633getFanSubscribed :: (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 +1840,7 @@ mergeCheap nt = mergeGCheap' unMergeSubscribedParent getInitialSubscribers updat
19141840 liftIO $ modifyIORef' heightBagRef $ heightBagAdd newParentHeight
19151841 return $ DMap.insertLookupWithKey' (\_ new _ -> new) k newParent ps
19161842 forM_ mOldSubd $ \oldSubd -> do
1917− oldHeight <- liftIO $ getEventSubscribedHeight $
1843+ oldHeight <- liftIO $ getEventSubscribedHeight $
19181844 _eventSubscription_subscribed $ unMergeSubscribedParent oldSubd
19191845
19201846 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
@@ -1960,7 +1886,7 @@ mergeCheapWithMove nt = mergeGCheap' _mergeSubscribedParentWithMove_subscription
19601886 let moveOrDelete :: forall a. k a -> PatchDMapWithMove.NodeInfo k q a -> MergeSubscribedParentWithMove x k a -> Constant (EventM x (Maybe (EventSubscription x))) a
19611887 moveOrDelete _ ni parent = Constant $ case getComposeMaybe $ PatchDMapWithMove._nodeInfo_to ni of
19621888 Nothing -> do
1963− oldHeight <- liftIO $ getEventSubscribedHeight $ _eventSubscription_subscribed $
1889+ oldHeight <- liftIO $ getEventSubscribedHeight $ _eventSubscription_subscribed $
19641890 _mergeSubscribedParentWithMove_subscription parent
19651891
19661892 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
@@ -1968,7 +1894,7 @@ mergeCheapWithMove nt = mergeGCheap' _mergeSubscribedParentWithMove_subscription
19681894 Just toKey -> do
19691895 liftIO $ writeIORef (_mergeSubscribedParentWithMove_key parent) $! toKey
19701896 return Nothing
1971− toDelete <- fmap catMaybes $ mapM (\(_ :=> v) -> getConstant v) $ DMap.toList $
1897+ toDelete <- fmap catMaybes $ mapM (\(_ :=> v) -> getConstant v) $ DMap.toList $
19721898 DMap.intersectionWithKey moveOrDelete (unPatchDMapWithMove p) oldParents
19731899
19741900 return (toDelete, applyAlways p' oldParents)
@@ -2021,16 +1947,16 @@ invalidateMergeHeight' :: IORef Height -> Subscriber x a -> IO ()
20211947invalidateMergeHeight' heightRef sub = do
20221948 oldHeight <- readIORef heightRef
20231949 -- 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
1950+ when (oldHeight /= invalidHeight) $ do
20251951 writeIORef heightRef $! invalidHeight
20261952 subscriberInvalidateHeight sub oldHeight
20271953
20281954revalidateMergeHeight :: Merge x k v s -> IO ()
20291955revalidateMergeHeight m = do
20301956 currentHeight <- readIORef $ _merge_heightRef m
2031−
1957+
20321958 -- revalidateMergeHeight may be called multiple times; perhaps the's a way to finesse it to avoid this check
2033− when (currentHeight == invalidHeight) $ do
1959+ when (currentHeight == invalidHeight) $ do
20341960 heights <- readIORef $ _merge_heightBagRef m
20351961 parents <- readIORef $ _merge_parentsRef m
20361962 -- When the number of heights in the bag reaches the number of parents, we should have a valid height
@@ -2038,7 +1964,7 @@ revalidateMergeHeight m = do
20381964 LT -> return ()
20391965 EQ -> do
20401966 let height = succHeight $ heightBagMax heights
2041− traceInvalidateHeight $ "recalculateSubscriberHeight: height: " <> show height
1967+ traceInvalidate $ "recalculateSubscriberHeight: height: " <> show height
20421968 writeIORef (_merge_heightRef m) $! height
20431969 subscriberRecalculateHeight (_merge_sub m) height
20441970 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show (DMap.size parents) <> ") for Merge"
@@ -2046,22 +1972,22 @@ revalidateMergeHeight m = do
20461972scheduleMergeSelf :: HasSpiderTimeline x => Merge x k v s -> Height -> EventM x ()
20471973scheduleMergeSelf m height = scheduleMerge' height (_merge_heightRef m) $ do
20481974 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,
1975+ -- Once we're done with this, we can clear it immediately, because if there's a cacheEvent in front of us,
20501976 -- it'll handle subsequent subscribers, and if not, we won't get subsequent subscribers
2051− liftIO $ writeIORef (_merge_accumRef m) $! DMap.empty
1977+ liftIO $ writeIORef (_merge_accumRef m) $! DMap.empty
20521978 --TODO: Assert that m is not empty
20531979 subscriberPropagate (_merge_sub m) vals
20541980
20551981checkCycle :: HasSpiderTimeline x => EventSubscribed x -> EventM x ()
20561982checkCycle subscribed = liftIO $ do
20571983 height <- readIORef (eventSubscribedHeightRef subscribed)
2058−
1984+
20591985 -- currentHeight <- getCurrentHeight
20601986 -- when (height <= currentHeight) $ if height /= invalidHeight
20611987 -- then do
20621988 -- myStack <- liftIO $ whoCreatedIORef undefined --TODO
20631989 -- error $ "Height (" ++ show height ++ ") is not greater than current height (" ++ show currentHeight ++ ")\n" ++ unlines (reverse myStack)
2064− -- else liftIO $
1990+ -- else liftIO $
20651991 when (height == invalidHeight) $
20661992#ifdef DEBUG_CYCLES
20671993 do
@@ -2114,17 +2040,17 @@ mergeGCheap' getParent getInitialSubscribers updateFunc destroy d = Event $ \sub
21142040 parentsRef :: IORef (DMap k s) <- liftIO $ newIORef $ error "merge: parentsRef not yet initialized"
21152041 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
21162042
2117− let subscribed = EventSubscribed
2118− { eventSubscribedHeightRef = heightRef
2043+ let subscribed = EventSubscribed
2044+ { eventSubscribedHeightRef = heightRef
21192045 , eventSubscribedRetained = toAny (parentsRef, changeSubdRef)
21202046#ifdef DEBUG_CYCLES
21212047 , eventSubscribedGetParents = do
21222048 let getParent' (_ :=> v) = _eventSubscription_subscribed (getParent v)
2123− fmap getParent' . DMap.toList <$> readIORef parentsRef
2049+ fmap getParent' . DMap.toList <$> readIORef parentsRef
21242050 , eventSubscribedHasOwnHeightRef = False
21252051 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2126−#endif
2127− }
2052+#endif
2053+ }
21282054
21292055 m = Merge
21302056 { _merge_parentsRef = parentsRef
@@ -2162,9 +2088,9 @@ mergeGCheap' getParent getInitialSubscribers updateFunc destroy d = Event $ \sub
21622088 -- its subscription.
21632089 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
21642090 let unsubscribeAll = destroy =<< readIORef parentsRef
2165−
2091+
21662092 return (EventSubscription unsubscribeAll subscribed, occ)
2167−
2093+
21682094
21692095mergeInt :: forall x a. (HasSpiderTimeline x) => DynamicS x (PatchIntMap (Event x a)) -> Event x (IntMap a)
21702096mergeInt = cacheEvent . mergeIntCheap
@@ -2178,14 +2104,14 @@ mergeIntCheap d = Event $ \sub -> do
21782104 heightBagRef <- liftIO $ newIORef heightBagEmpty
21792105 parents <- liftIO $ FastMutableIntMap.newEmpty
21802106 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
2181− let subscribed = EventSubscribed
2182− { eventSubscribedHeightRef = heightRef
2107+ let subscribed = EventSubscribed
2108+ { eventSubscribedHeightRef = heightRef
21832109 , eventSubscribedRetained = toAny (parents, changeSubdRef)
21842110#ifdef DEBUG_CYCLES
21852111 , eventSubscribedGetParents = fmap (_eventSubscription_subscribed . snd) <$> FastMutableIntMap.toList parents
21862112 , eventSubscribedHasOwnHeightRef = False
21872113 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2188−#endif
2114+#endif
21892115 }
21902116 let scheduleSelf = do
21912117 height <- liftIO $ readIORef $ heightRef
@@ -2202,7 +2128,7 @@ mergeIntCheap d = Event $ \sub -> do
22022128 LT -> return ()
22032129 EQ -> do
22042130 let height = succHeight $ heightBagMax heights
2205− traceInvalidateHeight $ "recalculateSubscriberHeight: height: " <> show height
2131+ traceInvalidate $ "recalculateSubscriberHeight: height: " <> show height
22062132 writeIORef heightRef $! height
22072133 subscriberRecalculateHeight sub height
22082134 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show numParents <> ") for Merge"
@@ -2274,7 +2200,7 @@ mergeIntCheap d = Event $ \sub -> do
22742200 -- its subscription.
22752201 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
22762202 let unsubscribeAll = traverse_ unsubscribe =<< FastMutableIntMap.getFrozenAndClear parents
2277−
2203+
22782204
22792205 return (EventSubscription unsubscribeAll subscribed, occ)
22802206
@@ -2385,7 +2311,7 @@ runFrame a = SpiderHost $ do
23852311 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
23862312 {-
23872313 stackTrace <- liftIO $ fmap renderStack $ ccsToStrings =<< (getCCSOf $! switchSubscribedParent subscribed)
2388− liftIO $ debugStrLn $ (++stackTrace) $ "subd' subscribed to " ++ case e of
2314+ liftIO $ putStrLn $ (++stackTrace) $ "subd' subscribed to " ++ case e of
23892315 EventRoot _ -> "EventRoot"
23902316 EventNever -> "EventNever"
23912317 _ -> "something else"
@@ -2400,7 +2326,7 @@ runFrame a = SpiderHost $ do
24002326 myHeight <- readIORef $ switchSubscribedHeight subscribed
24012327 when (parentHeight /= myHeight) $ do
24022328 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
2403− WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight myHeight
2329+ WeakBag.traverse (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight myHeight
24042330 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
24052331 forM_ coincidenceInfos $ \(SomeResetCoincidence subscription mcs) -> do
24062332 unsubscribe subscription
@@ -2441,7 +2367,7 @@ invalidateCoincidenceHeight subscribed = do
24412367 oldHeight <- readIORef $ coincidenceSubscribedHeight subscribed
24422368 when (oldHeight /= invalidHeight) $ do
24432369 writeIORef (coincidenceSubscribedHeight subscribed) $! invalidHeight
2444− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
2370+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
24452371
24462372updateSwitchHeight :: Height -> SwitchSubscribed x a -> IO ()
24472373updateSwitchHeight new subscribed = do
@@ -2449,7 +2375,7 @@ updateSwitchHeight new subscribed = do
24492375 when (oldHeight == invalidHeight) $ do --TODO: This 'when' should probably be an assertion
24502376 when (new /= invalidHeight) $ do --TODO: This 'when' should probably be an assertion
24512377 writeIORef (switchSubscribedHeight subscribed) $! new
2452− WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ recalculateSubscriberHeight new
2378+ WeakBag.traverse (switchSubscribedSubscribers subscribed) $ recalculateSubscriberHeight new
24532379
24542380recalculateCoincidenceHeight :: CoincidenceSubscribed x a -> IO ()
24552381recalculateCoincidenceHeight subscribed = do
@@ -2458,7 +2384,7 @@ recalculateCoincidenceHeight subscribed = do
24582384 height <- calculateCoincidenceHeight subscribed
24592385 when (height /= invalidHeight) $ do
24602386 writeIORef (coincidenceSubscribedHeight subscribed) $! height
2461− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight height
2387+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight height
24622388
24632389calculateSwitchHeight :: SwitchSubscribed x a -> IO Height
24642390calculateSwitchHeight subscribed = getEventSubscribedHeight . _eventSubscription_subscribed =<< readIORef (switchSubscribedCurrentParent subscribed)
@@ -2520,8 +2446,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Event
25202446 {-# INLINABLE headE #-}
25212447 headE = R.slowHeadE
25222448-- headE (SpiderEvent e) = SpiderEvent <$> Reflex.Spider.Internal.headE e
2523− {-# INLINABLE now #-}
2524− now = nowSpiderEventM
25252449
25262450instance Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPullM x) where
25272451 {-# INLINABLE sample #-}
@@ -2543,9 +2467,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
25432467 {-# INLINABLE headE #-}
25442468 headE = R.slowHeadE
25452469-- headE (SpiderEvent e) = SpiderPushM $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2546− {-# INLINABLE now #-}
2547− now = SpiderPushM nowSpiderEventM
2548−
25492470
25502471instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
25512472 {-# INLINE return #-}
@@ -2554,10 +2475,8 @@ instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x))
25542475 x >>= f = SpiderDynamic $ dynamicDynIdentity $ newJoinDyn $ newMapDyn (unSpiderDynamic . f) $ unSpiderDynamic x
25552476 {-# INLINE (>>) #-}
25562477 (>>) = (*>)
2557−#if !MIN_VERSION_base(4,13,0)
25582478 {-# INLINE fail #-}
25592479 fail _ = error "Dynamic does not support 'fail'"
2560−#endif
25612480
25622481{-# INLINABLE newJoinDyn #-}
25632482newJoinDyn :: HasSpiderTimeline x => DynamicS x (Identity (DynamicS x (Identity a))) -> Reflex.Spider.Internal.Dyn x (Identity a)
@@ -2609,9 +2528,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
26092528 buildDynamic getV0 e = runFrame . runSpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
26102529 {-# INLINABLE headE #-}
26112530 headE e = runFrame . runSpiderHostFrame $ Reflex.Class.headE e
2612− {-# INLINABLE now #-}
2613− now = runFrame . runSpiderHostFrame $ Reflex.Class.now
2614−
26152531
26162532instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHostFrame x) where
26172533 sample = SpiderHostFrame . readBehaviorUntracked . unSpiderBehavior --TODO: This can cause problems with laziness, so we should get rid of it if we can
@@ -2628,8 +2544,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
26282544 {-# INLINABLE headE #-}
26292545 headE = R.slowHeadE
26302546-- headE (SpiderEvent e) = SpiderHostFrame $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2631− {-# INLINABLE now #-}
2632− now = SpiderHostFrame Reflex.Class.now
26332547
26342548instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHost x) where
26352549 {-# INLINABLE sample #-}
@@ -2650,8 +2564,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Refle
26502564 buildDynamic getV0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.buildDynamic getV0 e
26512565 {-# INLINABLE headE #-}
26522566 headE e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.headE e
2653− {-# INLINABLE now #-}
2654− now = Reflex.Spider.Internal.ReadPhase Reflex.Class.now
26552567
26562568--------------------------------------------------------------------------------
26572569-- Deprecated items
@@ -2775,7 +2687,7 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
27752687 fanG e = R.EventSelectorG $ SpiderEvent . selectG (fanG (unSpiderEvent e))
27762688 {-# INLINABLE mergeG #-}
27772689 mergeG
2778− :: forall k2 (k :: k2 -> *) q (v :: k2 -> *). GCompare k
2690+ :: forall (k :: k2 -> *) q (v :: k2 -> *). GCompare k
27792691 => (forall a. q a -> R.Event (SpiderTimeline x) (v a))
27802692 -> DMap k q
27812693 -> R.Event (SpiderTimeline x) (DMap k v)
@@ -2843,14 +2755,8 @@ instance Monad (SpiderHost x) where
28432755 SpiderHost x >> SpiderHost y = SpiderHost $ x >> y
28442756 {-# INLINABLE return #-}
28452757 return x = SpiderHost $ return x
2846−#if !MIN_VERSION_base(4,13,0)
28472758 {-# INLINABLE fail #-}
2848− fail = MonadFail.fail
2849−#endif
2850−
2851−instance MonadFail (SpiderHost x) where
2852− {-# INLINABLE fail #-}
2853− fail s = SpiderHost $ MonadFail.fail s
2759+ fail s = SpiderHost $ fail s
28542760
28552761-- | Run an action affecting the global Spider timeline; this will be guarded by
28562762-- a mutex for that timeline
@@ -2872,10 +2778,8 @@ instance Monad (SpiderHostFrame x) where
28722778 SpiderHostFrame x >> SpiderHostFrame y = SpiderHostFrame $ x >> y
28732779 {-# INLINABLE return #-}
28742780 return x = SpiderHostFrame $ return x
2875−#if !MIN_VERSION_base(4,13,0)
28762781 {-# INLINABLE fail #-}
28772782 fail s = SpiderHostFrame $ fail s
2878−#endif
28792783
28802784instance NotReady (SpiderTimeline x) (SpiderHostFrame x) where
28812785 notReadyUntil _ = pure ()
@@ -2920,11 +2824,3 @@ instance MonadAtomicRef (SpiderHostFrame x) where
29202824instance PrimMonad (SpiderHostFrame x) where
29212825 type PrimState (SpiderHostFrame x) = PrimState IO
29222826 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 ()