@@ -9,7 +9,6 @@
99{-# LANGUAGE GADTs #-}
1010{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1111{-# LANGUAGE LambdaCase #-}
12−{-# LANGUAGE MultiWayIf #-}
1312{-# LANGUAGE RankNTypes #-}
1413{-# LANGUAGE RoleAnnotations #-}
1514{-# LANGUAGE ScopedTypeVariables #-}
@@ -20,7 +19,7 @@
2019{-# LANGUAGE DeriveFunctor #-}
2120{-# LANGUAGE StandaloneDeriving #-}
2221{-# LANGUAGE InstanceSigs #-}
23−{-# LANGUAGE RecursiveDo #-}
22+{-# LANGUAGE MultiWayIf #-}
2423
2524#ifdef USE_REFLEX_OPTIMIZER
2625{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
@@ -39,15 +38,17 @@ import Control.Monad hiding (forM, forM_, mapM, mapM_)
3938import Control.Monad.Exception
4039import Control.Monad.Identity hiding (forM, forM_, mapM, mapM_)
4140import Control.Monad.Primitive
42−--import Control.Monad.Reader hiding (forM, forM_, mapM, mapM_)
4341import Control.Monad.Reader.Class
4442import Control.Monad.IO.Class
4543import Control.Monad.ReaderIO
4644import 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, DSum (..))
49+import Data.Dependent.Map (DMap)
5050import qualified Data.Dependent.Map as DMap
51+import Data.Dependent.Sum (DSum (..))
5152import Data.FastMutableIntMap (FastMutableIntMap, PatchIntMap (..))
5253import qualified Data.FastMutableIntMap as FastMutableIntMap
5354import Data.Foldable hiding (concat, elem, sequence_)
@@ -64,6 +65,7 @@ import Data.Monoid (mempty, (<>))
6465import Data.Proxy
6566import Data.These
6667import Data.Traversable
68+import Data.Type.Equality ((:~:)(Refl))
6769import Data.Witherable (Filterable, mapMaybe)
6870import GHC.Exts hiding (toList)
6971import GHC.IORef (IORef (..))
@@ -73,17 +75,20 @@ import System.IO.Unsafe
7375import System.Mem.Weak
7476import Unsafe.Coerce
7577
76−#if defined(MIN_VERSION_semialign)
78+#ifdef MIN_VERSION_semialign
7779#if MIN_VERSION_these(0,8,0)
7880import Data.These.Combinators (justThese)
7981#endif
82+#if MIN_VERSION_semialign(1,1,0)
83+import Data.Zip (Zip (..))
84+#endif
8085#endif
8186
8287#ifdef DEBUG_CYCLES
8388import Control.Monad.State hiding (forM, forM_, mapM, mapM_, sequence)
84−import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
8589#endif
8690
91+import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
8792import qualified Data.List.NonEmpty as NonEmpty
8893import Data.Tree (Forest, Tree (..), drawForest)
8994import Data.List (isPrefixOf)
@@ -101,14 +106,21 @@ import qualified Reflex.Class
101106import qualified Reflex.Class as R
102107import qualified Reflex.Host.Class
103108import Reflex.NotReady.Class
104−import Reflex.Patch
105−import qualified Reflex.Patch.DMapWithMove as PatchDMapWithMove
109+import Data.Patch
110+import qualified Data.Patch.DMapWithMove as PatchDMapWithMove
111+import Reflex.PerformEvent.Base (PerformEventT)
106112
107113#ifdef DEBUG_TRACE_EVENTS
108114import qualified Data.ByteString.Char8 as BS8
109115import System.IO (stderr)
110116import Data.List (isPrefixOf)
117+#endif
111118
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
112124withStackOneLine :: (BS8.ByteString -> a) -> a
113125withStackOneLine expr = unsafePerformIO $ do
114126 stack <- currentCallStack
@@ -117,15 +129,39 @@ withStackOneLine expr = unsafePerformIO $ do
117129
118130#endif
119131
132+debugPropagate :: Bool
133+
134+debugInvalidateHeight :: Bool
135+
136+debugInvalidate :: Bool
137+
120138#ifdef DEBUG
121139#define DEBUG_NODEIDS
122140
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+
123159class HasNodeId a where
124160 getNodeId :: a -> Int
125161
126162instance HasNodeId (CacheSubscribed x a) where
127163 getNodeId = _cacheSubscribed_nodeId
128−
164+
129165instance HasNodeId (FanInt x a) where
130166 getNodeId = _fanInt_nodeId
131167
@@ -152,16 +188,24 @@ showNodeId :: HasNodeId a => a -> String
152188showNodeId = showNodeId' . getNodeId
153189
154190showNodeId' :: Int -> String
155−showNodeId' = ("#"<>) . show
191+showNodeId' = ("#"<>) . show
156192
157193
158194#else
159195
196+debugPropagate = False
197+debugInvalidateHeight = False
198+debugInvalidate = False
199+
160200-- This must be inline, or error messages will cause memory leaks due to retaining the node in question
161201{-# INLINE showNodeId #-}
162202showNodeId :: a -> String
163203showNodeId _ = ""
164204
205+{-# INLINE showNodeId' #-}
206+showNodeId' :: Int -> String
207+showNodeId' _ = ""
208+
165209#endif
166210
167211#ifdef DEBUG_NODEIDS
@@ -209,11 +253,11 @@ subscribeAndRead = unEvent
209253{-# INLINE [1] pushCheap #-}
210254pushCheap :: HasSpiderTimeline x => (a -> ComputeM x (Maybe b)) -> Event x a -> Event x b
211255pushCheap !f e = Event $ \sub -> do
212− (subscription, occ) <- subscribeAndRead e $ debugSubscriber' "push" (sub
256+ (subscription, occ) <- subscribeAndRead e $ debugSubscriber' "push" $ sub
213257 { subscriberPropagate = \a -> do
214258 mb <- f a
215259 mapM_ (subscriberPropagate sub) mb
216− })
260+ }
217261 occ' <- join <$> mapM f occ
218262 return (subscription, occ')
219263
@@ -249,9 +293,9 @@ headE originalE = do
249293 let clearParent = liftIO $ writeIORef parent Nothing
250294 (_, occ) <- subscribeAndReadHead originalE $ terminalSubscriber $ const clearParent
251295 when (isJust occ) clearParent
252− return $ Event $ \sub ->
296+ return $ Event $ \sub ->
253297 liftIO (readIORef parent) >>= \case
254− Nothing -> subscribeAndReadNever
298+ Nothing -> subscribeAndReadNever
255299 Just e -> subscribeAndReadHead e sub
256300
257301data CacheSubscribed x a
@@ -263,7 +307,20 @@ data CacheSubscribed x a
263307#endif
264308 }
265309
266−
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+ )
267324
268325-- | Construct an 'Event' whose value is guaranteed not to be recomputed
269326-- repeatedly
@@ -294,14 +351,17 @@ cacheEvent e =
294351#endif
295352 subscribers <- liftIO FastWeakBag.empty
296353 occRef <- liftIO $ newIORef Nothing -- This should never be read prior to being set below
354+#ifdef DEBUG_NODEIDS
297355 (parentSub, occ) <- subscribeAndRead e $ debugSubscriber' ("cacheEvent" <> showNodeId' nodeId) $ Subscriber
356+#else
357+ (parentSub, occ) <- subscribeAndRead e $ Subscriber
358+#endif
298359 { subscriberPropagate = \a -> do
299− -- checkCycle (_eventSubscription_subscribed parentSub)
300360 liftIO $ writeIORef occRef (Just a)
301361 scheduleClear occRef
302362 propagateFast a subscribers
303− , subscriberInvalidateHeight = FastWeakBag.traverse subscribers . invalidateSubscriberHeight
304− , subscriberRecalculateHeight = FastWeakBag.traverse subscribers . recalculateSubscriberHeight
363+ , subscriberInvalidateHeight = FastWeakBag.traverse_ subscribers . invalidateSubscriberHeight
364+ , subscriberRecalculateHeight = FastWeakBag.traverse_ subscribers . recalculateSubscriberHeight
305365 }
306366 when (isJust occ) $ do
307367 liftIO $ writeIORef occRef occ -- Set the initial value of occRef; we don't need to do this if occ is Nothing
@@ -312,20 +372,20 @@ cacheEvent e =
312372 , _cacheSubscribed_occurrence = occRef
313373#ifdef DEBUG_NODEIDS
314374 , _cacheSubscribed_nodeId = nodeId
315−#endif
375+#endif
316376 }
317377 subscribedTicket <- liftIO $ mkFastWeakTicket subscribed
318378 liftIO $ writeIORef mSubscribedRef =<< getFastWeakTicketWeak subscribedTicket
319379 return subscribedTicket
320380 liftIO $ cacheSubscription sub mSubscribedRef subscribedTicket
321381
322−cacheSubscription :: Subscriber x a -> IORef (FastWeak (CacheSubscribed x a))
382+cacheSubscription :: Subscriber x a -> IORef (FastWeak (CacheSubscribed x a))
323383 -> FastWeakTicket (CacheSubscribed x a) -> IO (EventSubscription x, Maybe a)
324−cacheSubscription sub mSubscribedRef subscribedTicket = do
384+cacheSubscription sub mSubscribedRef subscribedTicket = do
325385 subscribed <- getFastWeakTicketValue subscribedTicket
326386 ticket <- FastWeakBag.insert sub $ _cacheSubscribed_subscribers subscribed
327387 occ <- readIORef $ _cacheSubscribed_occurrence subscribed
328−
388+
329389 let parentSub = _cacheSubscribed_parent subscribed
330390 es = EventSubscription
331391 { _eventSubscription_unsubscribe = do
@@ -344,9 +404,9 @@ cacheSubscription sub mSubscribedRef subscribedTicket = do
344404 , eventSubscribedGetParents = return [_eventSubscription_subscribed parentSub]
345405 , eventSubscribedHasOwnHeightRef = False
346406 , eventSubscribedWhoCreated = whoCreatedIORef mSubscribedRef
347−#endif
407+#endif
348408 }
349− }
409+ }
350410 return (es, occ)
351411
352412
@@ -404,16 +464,6 @@ data Subscriber x a = Subscriber
404464 , subscriberRecalculateHeight :: !(Height -> IO ())
405465 }
406466
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−
417467newSubscriberHold :: (HasSpiderTimeline x, Patch p) => Hold x p -> IO (Subscriber x p)
418468newSubscriberHold h = return $ Subscriber
419469 { subscriberPropagate = {-# SCC "traverseHold" #-} propagateSubscriberHold h
@@ -435,14 +485,12 @@ newSubscriberFan subscribed = debugSubscriber ("SubscriberFan " <> showNodeId su
435485 return ()
436486 , subscriberInvalidateHeight = \old -> do
437487 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
438− forM_ (DMap.toList subscribers) $ \(_ :=> v) -> WeakBag.traverse (_fanSubscribedChildren_list v) $ invalidateSubscriberHeight old
439−
488+ forM_ (DMap.toList subscribers) $ \(_ :=> v) -> WeakBag.traverse_ (_fanSubscribedChildren_list v) $ invalidateSubscriberHeight old
440489 , subscriberRecalculateHeight = \new -> do
441490 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
442− forM_ (DMap.toList subscribers) $ \(_ :=> v) -> WeakBag.traverse (_fanSubscribedChildren_list v) $ recalculateSubscriberHeight new
491+ forM_ (DMap.toList subscribers) $ \(_ :=> v) -> WeakBag.traverse_ (_fanSubscribedChildren_list v) $ recalculateSubscriberHeight new
443492 }
444493
445−
446494newSubscriberSwitch :: forall x a. HasSpiderTimeline x => SwitchSubscribed x a -> IO (Subscriber x a)
447495newSubscriberSwitch subscribed = debugSubscriber ("SubscriberCoincidenceOuter" <> showNodeId subscribed) $ Subscriber
448496 { subscriberPropagate = \a -> {-# SCC "traverseSwitch" #-} do
@@ -453,7 +501,7 @@ newSubscriberSwitch subscribed = debugSubscriber ("SubscriberCoincidenceOuter" <
453501 oldHeight <- readIORef $ switchSubscribedHeight subscribed
454502 when (oldHeight /= invalidHeight) $ do
455503 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
456− WeakBag.traverse (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
504+ WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
457505 , subscriberRecalculateHeight = (`updateSwitchHeight` subscribed)
458506 }
459507
@@ -469,17 +517,17 @@ newSubscriberCoincidenceOuter subscribed = debugSubscriber ("SubscriberCoinciden
469517 liftIO $ writeIORef (coincidenceSubscribedInnerParent subscribed) $ Just innerSubd
470518 scheduleClear $ coincidenceSubscribedInnerParent subscribed
471519 case occ of
472− Nothing ->
520+ Nothing ->
473521 when (innerHeight > outerHeight) $ liftIO $ do -- If the event fires, it will fire at a later height
474522 writeIORef (coincidenceSubscribedHeight subscribed) $! innerHeight
475− WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight outerHeight
476− WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight innerHeight
523+ WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight outerHeight
524+ WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight innerHeight
477525 Just o -> do -- Since it's already firing, no need to adjust height
478526 liftIO $ writeIORef (coincidenceSubscribedOccurrence subscribed) occ
479527 scheduleClear $ coincidenceSubscribedOccurrence subscribed
480528 propagate o $ coincidenceSubscribedSubscribers subscribed
481529 , subscriberInvalidateHeight = \_ -> invalidateCoincidenceHeight subscribed
482− , subscriberRecalculateHeight = \_ -> recalculateCoincidenceHeight subscribed
530+ , subscriberRecalculateHeight = \_ -> recalculateCoincidenceHeight subscribed
483531 }
484532
485533newSubscriberCoincidenceInner :: forall x a. HasSpiderTimeline x => CoincidenceSubscribed x a -> IO (Subscriber x a)
@@ -500,21 +548,21 @@ invalidateSubscriberHeight :: Height -> Subscriber x a -> IO ()
500548invalidateSubscriberHeight = flip subscriberInvalidateHeight
501549
502550recalculateSubscriberHeight :: Height -> Subscriber x a -> IO ()
503−recalculateSubscriberHeight = flip subscriberRecalculateHeight
551+recalculateSubscriberHeight = flip subscriberRecalculateHeight
504552
505553-- | Propagate everything at the current height
506554propagate :: forall x a. HasSpiderTimeline x => a -> WeakBag (Subscriber x a) -> EventM x ()
507−propagate a subscribers = withIncreasedDepth (Proxy::Proxy x) $
555+propagate a subscribers = withIncreasedDepth (Proxy::Proxy x) $
508556 -- 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
509557 --TODO: Should we check if nodes already have their values before propagating? Maybe we're re-doing work
510− WeakBag.traverse subscribers $ \s -> subscriberPropagate s a
558+ WeakBag.traverse_ subscribers $ \s -> subscriberPropagate s a
511559
512560-- | Propagate everything at the current height
513561propagateFast :: forall x a. HasSpiderTimeline x => a -> FastWeakBag (Subscriber x a) -> EventM x ()
514−propagateFast a subscribers = withIncreasedDepth (Proxy::Proxy x) $
562+propagateFast a subscribers = withIncreasedDepth (Proxy::Proxy x) $
515563 -- 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
516564 --TODO: Should we check if nodes already have their values before propagating? Maybe we're re-doing work
517− FastWeakBag.traverse subscribers $ \s -> subscriberPropagate s a
565+ FastWeakBag.traverse_ subscribers $ \s -> subscriberPropagate s a
518566
519567--------------------------------------------------------------------------------
520568-- EventSubscribed
@@ -559,6 +607,16 @@ eventSubscribedNever = EventSubscribed
559607 , eventSubscribedWhoCreated = return ["never"]
560608#endif
561609 }
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+ }
562620
563621eventSubscribedFan :: FanSubscribed x k v -> EventSubscribed x
564622eventSubscribedFan !subscribed = EventSubscribed
@@ -936,8 +994,10 @@ instance Monad (BehaviorM x) where
936994 BehaviorM x >> BehaviorM y = BehaviorM $ x >> y
937995 {-# INLINE return #-}
938996 return x = BehaviorM $ return x
997+#if !MIN_VERSION_base(4,13,0)
939998 {-# INLINE fail #-}
940999 fail s = BehaviorM $ fail s
1000+#endif
9411001
9421002data BehaviorSubscribed x a
9431003 = forall p. BehaviorSubscribedHold (Hold x p)
@@ -997,7 +1057,7 @@ data SomeMergeUpdate x = SomeMergeUpdate
9971057newtype SomeMergeInit x = SomeMergeInit { unSomeMergeInit :: EventM x () }
9981058
9991059-- EventM can do everything BehaviorM can, plus create holds
1000−newtype EventM x a = EventM { unEventM :: IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadException, MonadAsyncException)
1060+newtype EventM x a = EventM { unEventM :: IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadException, MonadAsyncException)
10011061
10021062newtype MergeSubscribedParent x a = MergeSubscribedParent { unMergeSubscribedParent :: EventSubscription x }
10031063
@@ -1022,7 +1082,7 @@ heightBagFromList :: [Height] -> HeightBag
10221082heightBagFromList heights = heightBagVerify $ foldl' (flip heightBagAdd) heightBagEmpty heights
10231083
10241084heightBagAdd :: Height -> HeightBag -> HeightBag
1025−heightBagAdd (Height h) (HeightBag s c) = heightBagVerify $ HeightBag (succ s) $
1085+heightBagAdd (Height h) (HeightBag s c) = heightBagVerify $ HeightBag (succ s) $
10261086 IntMap.insertWithKey (\_ _ old -> succ old) h 0 c
10271087
10281088heightBagRemove :: Height -> HeightBag -> HeightBag
@@ -1033,11 +1093,11 @@ heightBagRemove (Height h) b@(HeightBag s c) = heightBagVerify $ case IntMap.loo
10331093 _ -> IntMap.insert h (pred old) c
10341094
10351095heightBagRemoveMaybe :: Height -> HeightBag -> Maybe HeightBag
1036−heightBagRemoveMaybe (Height h) b@(HeightBag s c) = heightBagVerify . removed <$> IntMap.lookup h c where
1096+heightBagRemoveMaybe (Height h) b@(HeightBag s c) = heightBagVerify . removed <$> IntMap.lookup h c where
10371097 removed old = HeightBag (pred s) $ case old of
10381098 0 -> IntMap.delete h c
10391099 _ -> IntMap.insert h (pred old) c
1040−
1100+
10411101
10421102heightBagMax :: HeightBag -> Height
10431103heightBagMax (HeightBag _ c) = case IntMap.maxViewWithKey c of
@@ -1139,7 +1199,10 @@ instance HasSpiderTimeline x => Semialign (Event x) where
11391199 align ea eb = mapMaybe dmapToThese $ mergeG coerce $ dynamicConst $
11401200 DMap.fromDistinctAscList [LeftTag :=> ea, RightTag :=> eb]
11411201
1142−#if defined(MIN_VERSION_semialign)
1202+#ifdef MIN_VERSION_semialign
1203+#if MIN_VERSION_semialign(1,1,0)
1204+instance HasSpiderTimeline x => Zip (Event x) where
1205+#endif
11431206 zip x y = mapMaybe justThese $ align x y
11441207#endif
11451208
@@ -1283,7 +1346,7 @@ mkWeakPtrWithDebug x debugNote = do
12831346 x' <- evaluate x
12841347 mkWeakPtr x' $
12851348 if debugFinalize
1286− then Just $ putStrLn $ "finalizing: " ++ debugNote
1349+ then Just $ debugStrLn $ "finalizing: " ++ debugNote
12871350 else Nothing
12881351
12891352type WeakList a = [Weak a]
@@ -1298,21 +1361,20 @@ type CanTrace x m = (HasSpiderTimeline x, MonadIO m)
12981361debugSubscriber :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> IO (Subscriber x a)
12991362debugSubscriber description = return . debugSubscriber' description
13001363
1301−
13021364debugSubscriber' :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> Subscriber x a
1303−debugSubscriber' description subscribed = Subscriber
1365+debugSubscriber' description subscribed = Subscriber
13041366 {
13051367 subscriberPropagate = \m -> do
13061368 tracePropagate (Proxy :: Proxy x) ("subscriberPropagate: " <> description)
13071369 subscriberPropagate subscribed m
13081370 , subscriberInvalidateHeight = \old -> do
1309− putStrLn $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
1371+ traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
13101372 subscriberInvalidateHeight subscribed old
1311− putStrLn $ "invalidateSubscriberHeight: " <> description <> ", done"
1373+ traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", done"
13121374 , subscriberRecalculateHeight = \new -> do
1313− putStrLn $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
1375+ traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
13141376 subscriberRecalculateHeight subscribed new
1315− putStrLn $ "subscriberRecalculateHeight: " <> description <> ", done"
1377+ traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", done"
13161378 }
13171379
13181380
@@ -1326,11 +1388,15 @@ withIncreasedDepth _ a = do
13261388
13271389{-# INLINE tracePropagate #-}
13281390tracePropagate :: (CanTrace x m) => proxy x -> String -> m ()
1329−tracePropagate p = trace p
1391+tracePropagate p = when debugPropagate . trace p
13301392
13311393{-# INLINE traceInvalidate #-}
13321394traceInvalidate :: String -> IO ()
1333−traceInvalidate = liftIO . putStrLn
1395+traceInvalidate = when debugInvalidate . liftIO . debugStrLn
1396+
1397+{-# INLINE traceInvalidateHeight #-}
1398+traceInvalidateHeight :: String -> IO ()
1399+traceInvalidateHeight = when debugInvalidateHeight . liftIO . debugStrLn
13341400
13351401{-# INLINE trace #-}
13361402trace :: (CanTrace x m) => proxy x -> String -> m ()
@@ -1341,7 +1407,7 @@ traceM :: forall x proxy m. (CanTrace x m) => proxy x -> m String -> m ()
13411407traceM _ getMessage = do
13421408 message <- getMessage
13431409 d <- liftIO $ readIORef $ _spiderTimeline_depth $ unSTE (spiderTimeline :: SpiderTimelineEnv x)
1344− liftIO $ putStrLn $ replicate d ' ' <> message
1410+ liftIO $ debugStrLn $ replicate d ' ' <> message
13451411
13461412#else
13471413
@@ -1357,10 +1423,20 @@ tracePropagate _ _ = return ()
13571423traceInvalidate :: String -> IO ()
13581424traceInvalidate _ = return ()
13591425
1426+{-# INLINE traceInvalidateHeight #-}
1427+traceInvalidateHeight :: String -> IO ()
1428+traceInvalidateHeight _ = return ()
1429+
13601430{-# INLINE debugSubscriber #-}
13611431debugSubscriber :: String -> Subscriber x a -> IO (Subscriber x a)
13621432debugSubscriber _ = return
13631433
1434+{-# INLINE debugSubscriber' #-}
1435+debugSubscriber' :: String -> Subscriber x a -> Subscriber x a
1436+debugSubscriber' _ = id
1437+
1438+
1439+
13641440{-# INLINE trace #-}
13651441trace :: (CanTrace x m) => proxy x -> String -> m ()
13661442trace _ _ = return ()
@@ -1391,17 +1467,20 @@ showStacks :: [[String]] -> String
13911467showStacks = drawForest . listsToForest . fmap (filterStack "Reflex.Spider.Internal")
13921468
13931469filterStack :: String -> [String] -> [String]
1470+#ifdef DEBUG_HIDE_INTERNALS
13941471filterStack prefix = filter (not . (prefix `isPrefixOf`))
1395−
1472+#else
1473+filterStack prefix = id
1474+#endif
13961475
13971476#ifdef DEBUG_CYCLES
13981477
1399−data EventLoopException = EventLoopException [[String]]
1478+data EventLoopException = EventLoopException [[String]]
14001479instance Exception EventLoopException
14011480
14021481instance Show EventLoopException where
1403− show (EventLoopException stacks) = "causality loop detected:\n" <> if null stacks
1404− then "no location information, compile with profiling enabled for stack tree"
1482+ show (EventLoopException stacks) = "causality loop detected:\n" <> if null stacks
1483+ then "no location information, compile with profiling enabled for stack tree"
14051484 else showStacks stacks
14061485
14071486#else
@@ -1419,7 +1498,7 @@ instance Show EventLoopException where
14191498{-# INLINE propagateSubscriberHold #-}
14201499propagateSubscriberHold :: forall x p. (HasSpiderTimeline x, Patch p) => Hold x p -> p -> EventM x ()
14211500propagateSubscriberHold h a = do
1422− traceM (Proxy :: Proxy x) $ liftIO $ do
1501+ {-# SCC "trace" #-} when debugPropagate $ traceM (Proxy :: Proxy x) $ liftIO $ do
14231502 invalidators <- liftIO $ readIORef $ holdInvalidators h
14241503 return $ "SubscriberHold" <> showNodeId h <> ": " ++ show (length invalidators)
14251504
@@ -1427,7 +1506,7 @@ propagateSubscriberHold h a = do
14271506 case {-# SCC "apply" #-} apply a v of
14281507 Nothing -> return ()
14291508 Just v' -> do
1430− withIncreasedDepth (Proxy :: Proxy x) $
1509+ {-# SCC "trace2" #-} withIncreasedDepth (Proxy :: Proxy x) $
14311510 tracePropagate (Proxy :: Proxy x) ("propagateSubscriberHold: assigning Hold" <> showNodeId h)
14321511 vRef <- {-# SCC "vRef" #-} liftIO $ evaluate $ holdValue h
14331512 iRef <- {-# SCC "iRef" #-} liftIO $ evaluate $ holdInvalidators h
@@ -1548,7 +1627,7 @@ data FanInt x a = FanInt
15481627 { _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
15491628 , _fanInt_subscriptionRef :: {-# UNPACK #-} !(IORef (EventSubscription x)) -- This should have a valid subscription iff subscribers is non-empty
15501629 , _fanInt_occRef :: {-# UNPACK #-} !(IORef (IntMap a))
1551−#ifdef DEBUG_NODEIDS
1630+#ifdef DEBUG_NODEIDS
15521631 , _fanInt_nodeId :: {-# UNPACK #-} !Int
15531632#endif
15541633 }
@@ -1558,15 +1637,15 @@ newFanInt = do
15581637 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
15591638 subscriptionRef <- newIORef $ error "fanInt: no subscription"
15601639 occRef <- newIORef $ error "fanInt: no occurrence"
1561−#ifdef DEBUG_NODEIDS
1640+#ifdef DEBUG_NODEIDS
15621641 nodeId <- newNodeId
15631642#endif
15641643 return $ FanInt
15651644 { _fanInt_subscribers = subscribers
15661645 , _fanInt_subscriptionRef = subscriptionRef
15671646 , _fanInt_occRef = occRef
1568−#ifdef DEBUG_NODEIDS
1569− , _fanInt_nodeId = nodeId
1647+#ifdef DEBUG_NODEIDS
1648+ , _fanInt_nodeId = nodeId
15701649#endif
15711650 }
15721651
@@ -1582,15 +1661,15 @@ fanInt p = unsafePerformIO $ do
15821661 liftIO $ writeIORef (_fanInt_occRef self) m
15831662 scheduleIntClear $ _fanInt_occRef self
15841663 FastMutableIntMap.forIntersectionWithImmutable_ (_fanInt_subscribers self) m $ \b v -> --TODO: Do we need to know that no subscribers are being added as we traverse?
1585− FastWeakBag.traverse b $ \s ->
1664+ FastWeakBag.traverse_ b $ \s ->
15861665 subscriberPropagate s v
1587− , subscriberInvalidateHeight = \old ->
1588− FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1589− FastWeakBag.traverse b $ \s ->
1666+ , subscriberInvalidateHeight = \old ->
1667+ FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1668+ FastWeakBag.traverse_ b $ \s ->
15901669 subscriberInvalidateHeight s old
15911670 , subscriberRecalculateHeight = \new ->
1592− FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1593− FastWeakBag.traverse b $ \s ->
1671+ FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1672+ FastWeakBag.traverse_ b $ \s ->
15941673 subscriberRecalculateHeight s new
15951674 }
15961675 liftIO $ do
@@ -1606,14 +1685,14 @@ fanInt p = unsafePerformIO $ do
16061685 Just b -> return b
16071686 ticket <- liftIO $ FastWeakBag.insert sub b
16081687 currentOcc <- readIORef (_fanInt_occRef self)
1609−
1688+
16101689 subscribed <- fanIntSubscribed ticket self
16111690 return (EventSubscription (FastWeakBag.remove ticket) subscribed, IntMap.lookup k currentOcc)
16121691
16131692fanIntSubscribed :: FastWeakBagTicket k -> FanInt x a -> IO (EventSubscribed x)
1614−fanIntSubscribed ticket self = do
1693+fanIntSubscribed ticket self = do
16151694 subscribedParent <- _eventSubscription_subscribed <$> readIORef (_fanInt_subscriptionRef self)
1616− return $ EventSubscribed
1695+ return $ EventSubscribed
16171696 { eventSubscribedHeightRef = eventSubscribedHeightRef subscribedParent
16181697 , eventSubscribedRetained = toAny (_fanInt_subscriptionRef self, ticket)
16191698#ifdef DEBUG_CYCLES
@@ -1622,7 +1701,7 @@ fanIntSubscribed ticket self = do
16221701 , eventSubscribedWhoCreated = whoCreatedIORef $ _fanInt_subscriptionRef self
16231702#endif
16241703 }
1625−
1704+
16261705
16271706{-# INLINABLE getFanSubscribed #-}
16281707getFanSubscribed :: (HasSpiderTimeline x, GCompare k) => k a -> Fan x k v -> Subscriber x (v a) -> EventM x (WeakBagTicket, FanSubscribed x k v, Maybe (v a))
@@ -1835,7 +1914,7 @@ mergeCheap nt = mergeGCheap' unMergeSubscribedParent getInitialSubscribers updat
18351914 liftIO $ modifyIORef' heightBagRef $ heightBagAdd newParentHeight
18361915 return $ DMap.insertLookupWithKey' (\_ new _ -> new) k newParent ps
18371916 forM_ mOldSubd $ \oldSubd -> do
1838− oldHeight <- liftIO $ getEventSubscribedHeight $
1917+ oldHeight <- liftIO $ getEventSubscribedHeight $
18391918 _eventSubscription_subscribed $ unMergeSubscribedParent oldSubd
18401919
18411920 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
@@ -1881,7 +1960,7 @@ mergeCheapWithMove nt = mergeGCheap' _mergeSubscribedParentWithMove_subscription
18811960 let moveOrDelete :: forall a. k a -> PatchDMapWithMove.NodeInfo k q a -> MergeSubscribedParentWithMove x k a -> Constant (EventM x (Maybe (EventSubscription x))) a
18821961 moveOrDelete _ ni parent = Constant $ case getComposeMaybe $ PatchDMapWithMove._nodeInfo_to ni of
18831962 Nothing -> do
1884− oldHeight <- liftIO $ getEventSubscribedHeight $ _eventSubscription_subscribed $
1963+ oldHeight <- liftIO $ getEventSubscribedHeight $ _eventSubscription_subscribed $
18851964 _mergeSubscribedParentWithMove_subscription parent
18861965
18871966 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
@@ -1889,7 +1968,7 @@ mergeCheapWithMove nt = mergeGCheap' _mergeSubscribedParentWithMove_subscription
18891968 Just toKey -> do
18901969 liftIO $ writeIORef (_mergeSubscribedParentWithMove_key parent) $! toKey
18911970 return Nothing
1892− toDelete <- fmap catMaybes $ mapM (\(_ :=> v) -> getConstant v) $ DMap.toList $
1971+ toDelete <- fmap catMaybes $ mapM (\(_ :=> v) -> getConstant v) $ DMap.toList $
18931972 DMap.intersectionWithKey moveOrDelete (unPatchDMapWithMove p) oldParents
18941973
18951974 return (toDelete, applyAlways p' oldParents)
@@ -1942,16 +2021,16 @@ invalidateMergeHeight' :: IORef Height -> Subscriber x a -> IO ()
19422021invalidateMergeHeight' heightRef sub = do
19432022 oldHeight <- readIORef heightRef
19442023 -- If the height used to be valid, it must be invalid now; we should never have *more* heights than we have parents
1945− when (oldHeight /= invalidHeight) $ do
2024+ when (oldHeight /= invalidHeight) $ do
19462025 writeIORef heightRef $! invalidHeight
19472026 subscriberInvalidateHeight sub oldHeight
19482027
19492028revalidateMergeHeight :: Merge x k v s -> IO ()
19502029revalidateMergeHeight m = do
19512030 currentHeight <- readIORef $ _merge_heightRef m
1952−
2031+
19532032 -- revalidateMergeHeight may be called multiple times; perhaps the's a way to finesse it to avoid this check
1954− when (currentHeight == invalidHeight) $ do
2033+ when (currentHeight == invalidHeight) $ do
19552034 heights <- readIORef $ _merge_heightBagRef m
19562035 parents <- readIORef $ _merge_parentsRef m
19572036 -- When the number of heights in the bag reaches the number of parents, we should have a valid height
@@ -1959,7 +2038,7 @@ revalidateMergeHeight m = do
19592038 LT -> return ()
19602039 EQ -> do
19612040 let height = succHeight $ heightBagMax heights
1962− traceInvalidate $ "recalculateSubscriberHeight: height: " <> show height
2041+ traceInvalidateHeight $ "recalculateSubscriberHeight: height: " <> show height
19632042 writeIORef (_merge_heightRef m) $! height
19642043 subscriberRecalculateHeight (_merge_sub m) height
19652044 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show (DMap.size parents) <> ") for Merge"
@@ -1967,22 +2046,22 @@ revalidateMergeHeight m = do
19672046scheduleMergeSelf :: HasSpiderTimeline x => Merge x k v s -> Height -> EventM x ()
19682047scheduleMergeSelf m height = scheduleMerge' height (_merge_heightRef m) $ do
19692048 vals <- liftIO $ readIORef $ _merge_accumRef m
1970− -- Once we're done with this, we can clear it immediately, because if there's a cacheEvent in front of us,
2049+ -- Once we're done with this, we can clear it immediately, because if there's a cacheEvent in front of us,
19712050 -- it'll handle subsequent subscribers, and if not, we won't get subsequent subscribers
1972− liftIO $ writeIORef (_merge_accumRef m) $! DMap.empty
2051+ liftIO $ writeIORef (_merge_accumRef m) $! DMap.empty
19732052 --TODO: Assert that m is not empty
19742053 subscriberPropagate (_merge_sub m) vals
19752054
19762055checkCycle :: HasSpiderTimeline x => EventSubscribed x -> EventM x ()
19772056checkCycle subscribed = liftIO $ do
19782057 height <- readIORef (eventSubscribedHeightRef subscribed)
1979−
2058+
19802059 -- currentHeight <- getCurrentHeight
19812060 -- when (height <= currentHeight) $ if height /= invalidHeight
19822061 -- then do
19832062 -- myStack <- liftIO $ whoCreatedIORef undefined --TODO
19842063 -- error $ "Height (" ++ show height ++ ") is not greater than current height (" ++ show currentHeight ++ ")\n" ++ unlines (reverse myStack)
1985− -- else liftIO $
2064+ -- else liftIO $
19862065 when (height == invalidHeight) $
19872066#ifdef DEBUG_CYCLES
19882067 do
@@ -2035,17 +2114,17 @@ mergeGCheap' getParent getInitialSubscribers updateFunc destroy d = Event $ \sub
20352114 parentsRef :: IORef (DMap k s) <- liftIO $ newIORef $ error "merge: parentsRef not yet initialized"
20362115 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
20372116
2038− let subscribed = EventSubscribed
2039− { eventSubscribedHeightRef = heightRef
2117+ let subscribed = EventSubscribed
2118+ { eventSubscribedHeightRef = heightRef
20402119 , eventSubscribedRetained = toAny (parentsRef, changeSubdRef)
20412120#ifdef DEBUG_CYCLES
20422121 , eventSubscribedGetParents = do
20432122 let getParent' (_ :=> v) = _eventSubscription_subscribed (getParent v)
2044− fmap getParent' . DMap.toList <$> readIORef parentsRef
2123+ fmap getParent' . DMap.toList <$> readIORef parentsRef
20452124 , eventSubscribedHasOwnHeightRef = False
20462125 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2047−#endif
2048− }
2126+#endif
2127+ }
20492128
20502129 m = Merge
20512130 { _merge_parentsRef = parentsRef
@@ -2083,9 +2162,9 @@ mergeGCheap' getParent getInitialSubscribers updateFunc destroy d = Event $ \sub
20832162 -- its subscription.
20842163 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
20852164 let unsubscribeAll = destroy =<< readIORef parentsRef
2086−
2165+
20872166 return (EventSubscription unsubscribeAll subscribed, occ)
2088−
2167+
20892168
20902169mergeInt :: forall x a. (HasSpiderTimeline x) => DynamicS x (PatchIntMap (Event x a)) -> Event x (IntMap a)
20912170mergeInt = cacheEvent . mergeIntCheap
@@ -2099,14 +2178,14 @@ mergeIntCheap d = Event $ \sub -> do
20992178 heightBagRef <- liftIO $ newIORef heightBagEmpty
21002179 parents <- liftIO $ FastMutableIntMap.newEmpty
21012180 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
2102− let subscribed = EventSubscribed
2103− { eventSubscribedHeightRef = heightRef
2181+ let subscribed = EventSubscribed
2182+ { eventSubscribedHeightRef = heightRef
21042183 , eventSubscribedRetained = toAny (parents, changeSubdRef)
21052184#ifdef DEBUG_CYCLES
21062185 , eventSubscribedGetParents = fmap (_eventSubscription_subscribed . snd) <$> FastMutableIntMap.toList parents
21072186 , eventSubscribedHasOwnHeightRef = False
21082187 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2109−#endif
2188+#endif
21102189 }
21112190 let scheduleSelf = do
21122191 height <- liftIO $ readIORef $ heightRef
@@ -2123,7 +2202,7 @@ mergeIntCheap d = Event $ \sub -> do
21232202 LT -> return ()
21242203 EQ -> do
21252204 let height = succHeight $ heightBagMax heights
2126− traceInvalidate $ "recalculateSubscriberHeight: height: " <> show height
2205+ traceInvalidateHeight $ "recalculateSubscriberHeight: height: " <> show height
21272206 writeIORef heightRef $! height
21282207 subscriberRecalculateHeight sub height
21292208 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show numParents <> ") for Merge"
@@ -2195,7 +2274,7 @@ mergeIntCheap d = Event $ \sub -> do
21952274 -- its subscription.
21962275 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
21972276 let unsubscribeAll = traverse_ unsubscribe =<< FastMutableIntMap.getFrozenAndClear parents
2198−
2277+
21992278
22002279 return (EventSubscription unsubscribeAll subscribed, occ)
22012280
@@ -2306,7 +2385,7 @@ runFrame a = SpiderHost $ do
23062385 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
23072386 {-
23082387 stackTrace <- liftIO $ fmap renderStack $ ccsToStrings =<< (getCCSOf $! switchSubscribedParent subscribed)
2309− liftIO $ putStrLn $ (++stackTrace) $ "subd' subscribed to " ++ case e of
2388+ liftIO $ debugStrLn $ (++stackTrace) $ "subd' subscribed to " ++ case e of
23102389 EventRoot _ -> "EventRoot"
23112390 EventNever -> "EventNever"
23122391 _ -> "something else"
@@ -2321,7 +2400,7 @@ runFrame a = SpiderHost $ do
23212400 myHeight <- readIORef $ switchSubscribedHeight subscribed
23222401 when (parentHeight /= myHeight) $ do
23232402 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
2324− WeakBag.traverse (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight myHeight
2403+ WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight myHeight
23252404 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
23262405 forM_ coincidenceInfos $ \(SomeResetCoincidence subscription mcs) -> do
23272406 unsubscribe subscription
@@ -2362,7 +2441,7 @@ invalidateCoincidenceHeight subscribed = do
23622441 oldHeight <- readIORef $ coincidenceSubscribedHeight subscribed
23632442 when (oldHeight /= invalidHeight) $ do
23642443 writeIORef (coincidenceSubscribedHeight subscribed) $! invalidHeight
2365− WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
2444+ WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
23662445
23672446updateSwitchHeight :: Height -> SwitchSubscribed x a -> IO ()
23682447updateSwitchHeight new subscribed = do
@@ -2370,7 +2449,7 @@ updateSwitchHeight new subscribed = do
23702449 when (oldHeight == invalidHeight) $ do --TODO: This 'when' should probably be an assertion
23712450 when (new /= invalidHeight) $ do --TODO: This 'when' should probably be an assertion
23722451 writeIORef (switchSubscribedHeight subscribed) $! new
2373− WeakBag.traverse (switchSubscribedSubscribers subscribed) $ recalculateSubscriberHeight new
2452+ WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ recalculateSubscriberHeight new
23742453
23752454recalculateCoincidenceHeight :: CoincidenceSubscribed x a -> IO ()
23762455recalculateCoincidenceHeight subscribed = do
@@ -2379,7 +2458,7 @@ recalculateCoincidenceHeight subscribed = do
23792458 height <- calculateCoincidenceHeight subscribed
23802459 when (height /= invalidHeight) $ do
23812460 writeIORef (coincidenceSubscribedHeight subscribed) $! height
2382− WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight height
2461+ WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight height
23832462
23842463calculateSwitchHeight :: SwitchSubscribed x a -> IO Height
23852464calculateSwitchHeight subscribed = getEventSubscribedHeight . _eventSubscription_subscribed =<< readIORef (switchSubscribedCurrentParent subscribed)
@@ -2441,6 +2520,8 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Event
24412520 {-# INLINABLE headE #-}
24422521 headE = R.slowHeadE
24432522-- headE (SpiderEvent e) = SpiderEvent <$> Reflex.Spider.Internal.headE e
2523+ {-# INLINABLE now #-}
2524+ now = nowSpiderEventM
24442525
24452526instance Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPullM x) where
24462527 {-# INLINABLE sample #-}
@@ -2462,6 +2543,9 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
24622543 {-# INLINABLE headE #-}
24632544 headE = R.slowHeadE
24642545-- headE (SpiderEvent e) = SpiderPushM $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2546+ {-# INLINABLE now #-}
2547+ now = SpiderPushM nowSpiderEventM
2548+
24652549
24662550instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
24672551 {-# INLINE return #-}
@@ -2470,8 +2554,10 @@ instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x))
24702554 x >>= f = SpiderDynamic $ dynamicDynIdentity $ newJoinDyn $ newMapDyn (unSpiderDynamic . f) $ unSpiderDynamic x
24712555 {-# INLINE (>>) #-}
24722556 (>>) = (*>)
2557+#if !MIN_VERSION_base(4,13,0)
24732558 {-# INLINE fail #-}
24742559 fail _ = error "Dynamic does not support 'fail'"
2560+#endif
24752561
24762562{-# INLINABLE newJoinDyn #-}
24772563newJoinDyn :: HasSpiderTimeline x => DynamicS x (Identity (DynamicS x (Identity a))) -> Reflex.Spider.Internal.Dyn x (Identity a)
@@ -2523,6 +2609,9 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
25232609 buildDynamic getV0 e = runFrame . runSpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
25242610 {-# INLINABLE headE #-}
25252611 headE e = runFrame . runSpiderHostFrame $ Reflex.Class.headE e
2612+ {-# INLINABLE now #-}
2613+ now = runFrame . runSpiderHostFrame $ Reflex.Class.now
2614+
25262615
25272616instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHostFrame x) where
25282617 sample = SpiderHostFrame . readBehaviorUntracked . unSpiderBehavior --TODO: This can cause problems with laziness, so we should get rid of it if we can
@@ -2539,6 +2628,8 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
25392628 {-# INLINABLE headE #-}
25402629 headE = R.slowHeadE
25412630-- headE (SpiderEvent e) = SpiderHostFrame $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2631+ {-# INLINABLE now #-}
2632+ now = SpiderHostFrame Reflex.Class.now
25422633
25432634instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHost x) where
25442635 {-# INLINABLE sample #-}
@@ -2559,6 +2650,8 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Refle
25592650 buildDynamic getV0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.buildDynamic getV0 e
25602651 {-# INLINABLE headE #-}
25612652 headE e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.headE e
2653+ {-# INLINABLE now #-}
2654+ now = Reflex.Spider.Internal.ReadPhase Reflex.Class.now
25622655
25632656--------------------------------------------------------------------------------
25642657-- Deprecated items
@@ -2682,7 +2775,7 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
26822775 fanG e = R.EventSelectorG $ SpiderEvent . selectG (fanG (unSpiderEvent e))
26832776 {-# INLINABLE mergeG #-}
26842777 mergeG
2685− :: forall (k :: k2 -> *) q (v :: k2 -> *). GCompare k
2778+ :: forall k2 (k :: k2 -> *) q (v :: k2 -> *). GCompare k
26862779 => (forall a. q a -> R.Event (SpiderTimeline x) (v a))
26872780 -> DMap k q
26882781 -> R.Event (SpiderTimeline x) (DMap k v)
@@ -2750,8 +2843,14 @@ instance Monad (SpiderHost x) where
27502843 SpiderHost x >> SpiderHost y = SpiderHost $ x >> y
27512844 {-# INLINABLE return #-}
27522845 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
27532852 {-# INLINABLE fail #-}
2754− fail s = SpiderHost $ fail s
2853+ fail s = SpiderHost $ MonadFail.fail s
27552854
27562855-- | Run an action affecting the global Spider timeline; this will be guarded by
27572856-- a mutex for that timeline
@@ -2773,8 +2872,10 @@ instance Monad (SpiderHostFrame x) where
27732872 SpiderHostFrame x >> SpiderHostFrame y = SpiderHostFrame $ x >> y
27742873 {-# INLINABLE return #-}
27752874 return x = SpiderHostFrame $ return x
2875+#if !MIN_VERSION_base(4,13,0)
27762876 {-# INLINABLE fail #-}
27772877 fail s = SpiderHostFrame $ fail s
2878+#endif
27782879
27792880instance NotReady (SpiderTimeline x) (SpiderHostFrame x) where
27802881 notReadyUntil _ = pure ()
@@ -2819,3 +2920,11 @@ instance MonadAtomicRef (SpiderHostFrame x) where
28192920instance PrimMonad (SpiderHostFrame x) where
28202921 type PrimState (SpiderHostFrame x) = PrimState IO
28212922 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 ()