@@ -9,6 +9,7 @@
9{-# LANGUAGE GADTs #-}
9{-# LANGUAGE GADTs #-}
10{-# LANGUAGE GeneralizedNewtypeDeriving #-}
10{-# LANGUAGE GeneralizedNewtypeDeriving #-}
11{-# LANGUAGE LambdaCase #-}
11{-# LANGUAGE LambdaCase #-}
12+{-# LANGUAGE MultiWayIf #-}
12{-# LANGUAGE RankNTypes #-}
13{-# LANGUAGE RankNTypes #-}
13{-# LANGUAGE RoleAnnotations #-}
14{-# LANGUAGE RoleAnnotations #-}
14{-# LANGUAGE ScopedTypeVariables #-}
15{-# LANGUAGE ScopedTypeVariables #-}
@@ -19,7 +20,7 @@
19{-# LANGUAGE DeriveFunctor #-}
20{-# LANGUAGE DeriveFunctor #-}
20{-# LANGUAGE StandaloneDeriving #-}
21{-# LANGUAGE StandaloneDeriving #-}
21{-# LANGUAGE InstanceSigs #-}
22{-# LANGUAGE InstanceSigs #-}
22−{-# LANGUAGE MultiWayIf #-}
23+{-# LANGUAGE RecursiveDo #-}
24#ifdef USE_REFLEX_OPTIMIZER
25#ifdef USE_REFLEX_OPTIMIZER
25{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
26{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
@@ -38,17 +39,15 @@ import Control.Monad hiding (forM, forM_, mapM, mapM_)
38import Control.Monad.Exception
39import Control.Monad.Exception
39import Control.Monad.Identity hiding (forM, forM_, mapM, mapM_)
40import Control.Monad.Identity hiding (forM, forM_, mapM, mapM_)
40import Control.Monad.Primitive
41import Control.Monad.Primitive
42+--import Control.Monad.Reader hiding (forM, forM_, mapM, mapM_)
41import Control.Monad.Reader.Class
43import Control.Monad.Reader.Class
42import Control.Monad.IO.Class
44import Control.Monad.IO.Class
43import Control.Monad.ReaderIO
45import Control.Monad.ReaderIO
44import Control.Monad.Ref
46import Control.Monad.Ref
45−import Control.Monad.Fail (MonadFail)
46−import qualified Control.Monad.Fail as MonadFail
47import Data.Align
47import Data.Align
48import Data.Coerce
48import Data.Coerce
49−import Data.Dependent.Map (DMap)
49+import Data.Dependent.Map (DMap, DSum (..))
50import qualified Data.Dependent.Map as DMap
50import qualified Data.Dependent.Map as DMap
51−import Data.Dependent.Sum (DSum (..))
52import Data.FastMutableIntMap (FastMutableIntMap, PatchIntMap (..))
51import Data.FastMutableIntMap (FastMutableIntMap, PatchIntMap (..))
53import qualified Data.FastMutableIntMap as FastMutableIntMap
52import qualified Data.FastMutableIntMap as FastMutableIntMap
54import Data.Foldable hiding (concat, elem, sequence_)
53import Data.Foldable hiding (concat, elem, sequence_)
@@ -65,7 +64,6 @@ import Data.Monoid (mempty, (<>))
65import Data.Proxy
64import Data.Proxy
66import Data.These
65import Data.These
67import Data.Traversable
66import Data.Traversable
68−import Data.Type.Equality ((:~:)(Refl))
69import Data.Witherable (Filterable, mapMaybe)
67import Data.Witherable (Filterable, mapMaybe)
70import GHC.Exts hiding (toList)
68import GHC.Exts hiding (toList)
71import GHC.IORef (IORef (..))
69import GHC.IORef (IORef (..))
@@ -75,20 +73,17 @@ import System.IO.Unsafe
75import System.Mem.Weak
73import System.Mem.Weak
76import Unsafe.Coerce
74import Unsafe.Coerce
78−#ifdef MIN_VERSION_semialign
76+#if defined(MIN_VERSION_semialign)
79#if MIN_VERSION_these(0,8,0)
77#if MIN_VERSION_these(0,8,0)
80import Data.These.Combinators (justThese)
78import Data.These.Combinators (justThese)
82−#if MIN_VERSION_semialign(1,1,0)
83−import Data.Zip (Zip (..))
87#ifdef DEBUG_CYCLES
82#ifdef DEBUG_CYCLES
88import Control.Monad.State hiding (forM, forM_, mapM, mapM_, sequence)
83import Control.Monad.State hiding (forM, forM_, mapM, mapM_, sequence)
84+import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
91−import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
92import qualified Data.List.NonEmpty as NonEmpty
87import qualified Data.List.NonEmpty as NonEmpty
93import Data.Tree (Forest, Tree (..), drawForest)
88import Data.Tree (Forest, Tree (..), drawForest)
94import Data.List (isPrefixOf)
89import Data.List (isPrefixOf)
@@ -106,21 +101,14 @@ import qualified Reflex.Class
106import qualified Reflex.Class as R
101import qualified Reflex.Class as R
107import qualified Reflex.Host.Class
102import qualified Reflex.Host.Class
108import Reflex.NotReady.Class
103import Reflex.NotReady.Class
109−import Data.Patch
104+import Reflex.Patch
110−import qualified Data.Patch.DMapWithMove as PatchDMapWithMove
105+import qualified Reflex.Patch.DMapWithMove as PatchDMapWithMove
111−import Reflex.PerformEvent.Base (PerformEventT)
113#ifdef DEBUG_TRACE_EVENTS
107#ifdef DEBUG_TRACE_EVENTS
114import qualified Data.ByteString.Char8 as BS8
108import qualified Data.ByteString.Char8 as BS8
115import System.IO (stderr)
109import System.IO (stderr)
116import Data.List (isPrefixOf)
110import Data.List (isPrefixOf)
119−-- TODO stdout might not be the best channel for debug output
120−debugStrLn :: String -> IO ()
121−debugStrLn = putStrLn
123−#ifdef DEBUG_TRACE_EVENTS
124withStackOneLine :: (BS8.ByteString -> a) -> a
112withStackOneLine :: (BS8.ByteString -> a) -> a
125withStackOneLine expr = unsafePerformIO $ do
113withStackOneLine expr = unsafePerformIO $ do
126 stack <- currentCallStack
114 stack <- currentCallStack
@@ -129,39 +117,15 @@ withStackOneLine expr = unsafePerformIO $ do
132−debugPropagate :: Bool
134−debugInvalidateHeight :: Bool
136−debugInvalidate :: Bool
138#ifdef DEBUG
120#ifdef DEBUG
139#define DEBUG_NODEIDS
121#define DEBUG_NODEIDS
141−#ifdef DEBUG_TRACE_PROPAGATION
142−debugPropagate = True
144−debugPropagate = False
147−#ifdef DEBUG_TRACE_HEIGHT
148−debugInvalidateHeight = True
150−debugInvalidateHeight = False
153−#ifdef DEBUG_TRACE_INVALIDATION
154−debugInvalidate = True
156−debugInvalidate = False
159class HasNodeId a where
123class HasNodeId a where
160 getNodeId :: a -> Int
124 getNodeId :: a -> Int
162instance HasNodeId (CacheSubscribed x a) where
126instance HasNodeId (CacheSubscribed x a) where
163 getNodeId = _cacheSubscribed_nodeId
127 getNodeId = _cacheSubscribed_nodeId
165instance HasNodeId (FanInt x a) where
129instance HasNodeId (FanInt x a) where
166 getNodeId = _fanInt_nodeId
130 getNodeId = _fanInt_nodeId
@@ -188,24 +152,16 @@ showNodeId :: HasNodeId a => a -> String
188showNodeId = showNodeId' . getNodeId
152showNodeId = showNodeId' . getNodeId
190showNodeId' :: Int -> String
154showNodeId' :: Int -> String
191−showNodeId' = ("#"<>) . show
155+showNodeId' = ("#"<>) . show
196−debugPropagate = False
197−debugInvalidateHeight = False
198−debugInvalidate = False
200-- This must be inline, or error messages will cause memory leaks due to retaining the node in question
160-- This must be inline, or error messages will cause memory leaks due to retaining the node in question
201{-# INLINE showNodeId #-}
161{-# INLINE showNodeId #-}
202showNodeId :: a -> String
162showNodeId :: a -> String
203showNodeId _ = ""
163showNodeId _ = ""
205−{-# INLINE showNodeId' #-}
206−showNodeId' :: Int -> String
211#ifdef DEBUG_NODEIDS
167#ifdef DEBUG_NODEIDS
@@ -253,11 +209,11 @@ subscribeAndRead = unEvent
253{-# INLINE [1] pushCheap #-}
209{-# INLINE [1] pushCheap #-}
254pushCheap :: HasSpiderTimeline x => (a -> ComputeM x (Maybe b)) -> Event x a -> Event x b
210pushCheap :: HasSpiderTimeline x => (a -> ComputeM x (Maybe b)) -> Event x a -> Event x b
255pushCheap !f e = Event $ \sub -> do
211pushCheap !f e = Event $ \sub -> do
256− (subscription, occ) <- subscribeAndRead e $ debugSubscriber' "push" $ sub
212+ (subscription, occ) <- subscribeAndRead e $ debugSubscriber' "push" (sub
257 { subscriberPropagate = \a -> do
213 { subscriberPropagate = \a -> do
258 mb <- f a
214 mb <- f a
259 mapM_ (subscriberPropagate sub) mb
215 mapM_ (subscriberPropagate sub) mb
261 occ' <- join <$> mapM f occ
217 occ' <- join <$> mapM f occ
262 return (subscription, occ')
218 return (subscription, occ')
@@ -293,9 +249,9 @@ headE originalE = do
293 let clearParent = liftIO $ writeIORef parent Nothing
249 let clearParent = liftIO $ writeIORef parent Nothing
294 (_, occ) <- subscribeAndReadHead originalE $ terminalSubscriber $ const clearParent
250 (_, occ) <- subscribeAndReadHead originalE $ terminalSubscriber $ const clearParent
295 when (isJust occ) clearParent
251 when (isJust occ) clearParent
296− return $ Event $ \sub ->
252+ return $ Event $ \sub ->
297 liftIO (readIORef parent) >>= \case
253 liftIO (readIORef parent) >>= \case
298− Nothing -> subscribeAndReadNever
254+ Nothing -> subscribeAndReadNever
299 Just e -> subscribeAndReadHead e sub
255 Just e -> subscribeAndReadHead e sub
301data CacheSubscribed x a
257data CacheSubscribed x a
@@ -307,20 +263,7 @@ data CacheSubscribed x a
310−nowSpiderEventM :: (HasSpiderTimeline x) => EventM x (R.Event (SpiderTimeline x) ())
266+
314−now :: (MonadIO m, Defer (Some Clear) m, HasSpiderTimeline x
317− nowOrNot <- liftIO $ newIORef $ Just ()
318− scheduleClear nowOrNot
319− return . Event $ \_ -> do
320− occ <- liftIO . readIORef $ nowOrNot
321− return ( EventSubscription (return ()) eventSubscribedNow
325-- | Construct an 'Event' whose value is guaranteed not to be recomputed
268-- | Construct an 'Event' whose value is guaranteed not to be recomputed
326-- repeatedly
269-- repeatedly
@@ -351,17 +294,14 @@ cacheEvent e =
352 subscribers <- liftIO FastWeakBag.empty
295 subscribers <- liftIO FastWeakBag.empty
353 occRef <- liftIO $ newIORef Nothing -- This should never be read prior to being set below
296 occRef <- liftIO $ newIORef Nothing -- This should never be read prior to being set below
355 (parentSub, occ) <- subscribeAndRead e $ debugSubscriber' ("cacheEvent" <> showNodeId' nodeId) $ Subscriber
297 (parentSub, occ) <- subscribeAndRead e $ debugSubscriber' ("cacheEvent" <> showNodeId' nodeId) $ Subscriber
357− (parentSub, occ) <- subscribeAndRead e $ Subscriber
359 { subscriberPropagate = \a -> do
298 { subscriberPropagate = \a -> do
299+ -- checkCycle (_eventSubscription_subscribed parentSub)
360 liftIO $ writeIORef occRef (Just a)
300 liftIO $ writeIORef occRef (Just a)
361 scheduleClear occRef
301 scheduleClear occRef
362 propagateFast a subscribers
302 propagateFast a subscribers
363− , subscriberInvalidateHeight = FastWeakBag.traverse_ subscribers . invalidateSubscriberHeight
303+ , subscriberInvalidateHeight = FastWeakBag.traverse subscribers . invalidateSubscriberHeight
364− , subscriberRecalculateHeight = FastWeakBag.traverse_ subscribers . recalculateSubscriberHeight
304+ , subscriberRecalculateHeight = FastWeakBag.traverse subscribers . recalculateSubscriberHeight
366 when (isJust occ) $ do
306 when (isJust occ) $ do
367 liftIO $ writeIORef occRef occ -- Set the initial value of occRef; we don't need to do this if occ is Nothing
307 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 =
372 , _cacheSubscribed_occurrence = occRef
312 , _cacheSubscribed_occurrence = occRef
373#ifdef DEBUG_NODEIDS
313#ifdef DEBUG_NODEIDS
374 , _cacheSubscribed_nodeId = nodeId
314 , _cacheSubscribed_nodeId = nodeId
377 subscribedTicket <- liftIO $ mkFastWeakTicket subscribed
317 subscribedTicket <- liftIO $ mkFastWeakTicket subscribed
378 liftIO $ writeIORef mSubscribedRef =<< getFastWeakTicketWeak subscribedTicket
318 liftIO $ writeIORef mSubscribedRef =<< getFastWeakTicketWeak subscribedTicket
379 return subscribedTicket
319 return subscribedTicket
380 liftIO $ cacheSubscription sub mSubscribedRef subscribedTicket
320 liftIO $ cacheSubscription sub mSubscribedRef subscribedTicket
382−cacheSubscription :: Subscriber x a -> IORef (FastWeak (CacheSubscribed x a))
322+cacheSubscription :: Subscriber x a -> IORef (FastWeak (CacheSubscribed x a))
383 -> FastWeakTicket (CacheSubscribed x a) -> IO (EventSubscription x, Maybe a)
323 -> FastWeakTicket (CacheSubscribed x a) -> IO (EventSubscription x, Maybe a)
384−cacheSubscription sub mSubscribedRef subscribedTicket = do
324+cacheSubscription sub mSubscribedRef subscribedTicket = do
385 subscribed <- getFastWeakTicketValue subscribedTicket
325 subscribed <- getFastWeakTicketValue subscribedTicket
386 ticket <- FastWeakBag.insert sub $ _cacheSubscribed_subscribers subscribed
326 ticket <- FastWeakBag.insert sub $ _cacheSubscribed_subscribers subscribed
387 occ <- readIORef $ _cacheSubscribed_occurrence subscribed
327 occ <- readIORef $ _cacheSubscribed_occurrence subscribed
389 let parentSub = _cacheSubscribed_parent subscribed
329 let parentSub = _cacheSubscribed_parent subscribed
390 es = EventSubscription
330 es = EventSubscription
391 { _eventSubscription_unsubscribe = do
331 { _eventSubscription_unsubscribe = do
@@ -404,9 +344,9 @@ cacheSubscription sub mSubscribedRef subscribedTicket = do
404 , eventSubscribedGetParents = return [_eventSubscription_subscribed parentSub]
344 , eventSubscribedGetParents = return [_eventSubscription_subscribed parentSub]
405 , eventSubscribedHasOwnHeightRef = False
345 , eventSubscribedHasOwnHeightRef = False
406 , eventSubscribedWhoCreated = whoCreatedIORef mSubscribedRef
346 , eventSubscribedWhoCreated = whoCreatedIORef mSubscribedRef
410 return (es, occ)
350 return (es, occ)
@@ -464,6 +404,16 @@ data Subscriber x a = Subscriber
464 , subscriberRecalculateHeight :: !(Height -> IO ())
404 , subscriberRecalculateHeight :: !(Height -> IO ())
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.
414+-- The result is also evaluated to WHNF, since forcing a thunk invalidates
415+-- the weak pointer to it in some cases.
467newSubscriberHold :: (HasSpiderTimeline x, Patch p) => Hold x p -> IO (Subscriber x p)
417newSubscriberHold :: (HasSpiderTimeline x, Patch p) => Hold x p -> IO (Subscriber x p)
468newSubscriberHold h = return $ Subscriber
418newSubscriberHold h = return $ Subscriber
469 { subscriberPropagate = {-# SCC "traverseHold" #-} propagateSubscriberHold h
419 { subscriberPropagate = {-# SCC "traverseHold" #-} propagateSubscriberHold h
@@ -485,12 +435,14 @@ newSubscriberFan subscribed = debugSubscriber ("SubscriberFan " <> showNodeId su
485 return ()
435 return ()
486 , subscriberInvalidateHeight = \old -> do
436 , subscriberInvalidateHeight = \old -> do
487 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
437 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
489 , subscriberRecalculateHeight = \new -> do
440 , subscriberRecalculateHeight = \new -> do
490 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
441 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
494newSubscriberSwitch :: forall x a. HasSpiderTimeline x => SwitchSubscribed x a -> IO (Subscriber x a)
446newSubscriberSwitch :: forall x a. HasSpiderTimeline x => SwitchSubscribed x a -> IO (Subscriber x a)
495newSubscriberSwitch subscribed = debugSubscriber ("SubscriberCoincidenceOuter" <> showNodeId subscribed) $ Subscriber
447newSubscriberSwitch subscribed = debugSubscriber ("SubscriberCoincidenceOuter" <> showNodeId subscribed) $ Subscriber
496 { subscriberPropagate = \a -> {-# SCC "traverseSwitch" #-} do
448 { subscriberPropagate = \a -> {-# SCC "traverseSwitch" #-} do
@@ -501,7 +453,7 @@ newSubscriberSwitch subscribed = debugSubscriber ("SubscriberCoincidenceOuter" <
501 oldHeight <- readIORef $ switchSubscribedHeight subscribed
453 oldHeight <- readIORef $ switchSubscribedHeight subscribed
502 when (oldHeight /= invalidHeight) $ do
454 when (oldHeight /= invalidHeight) $ do
503 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
455 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
504− WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
456+ WeakBag.traverse (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
505 , subscriberRecalculateHeight = (`updateSwitchHeight` subscribed)
457 , subscriberRecalculateHeight = (`updateSwitchHeight` subscribed)
@@ -517,17 +469,17 @@ newSubscriberCoincidenceOuter subscribed = debugSubscriber ("SubscriberCoinciden
517 liftIO $ writeIORef (coincidenceSubscribedInnerParent subscribed) $ Just innerSubd
469 liftIO $ writeIORef (coincidenceSubscribedInnerParent subscribed) $ Just innerSubd
518 scheduleClear $ coincidenceSubscribedInnerParent subscribed
470 scheduleClear $ coincidenceSubscribedInnerParent subscribed
519 case occ of
471 case occ of
520− Nothing ->
472+ Nothing ->
521 when (innerHeight > outerHeight) $ liftIO $ do -- If the event fires, it will fire at a later height
473 when (innerHeight > outerHeight) $ liftIO $ do -- If the event fires, it will fire at a later height
522 writeIORef (coincidenceSubscribedHeight subscribed) $! innerHeight
474 writeIORef (coincidenceSubscribedHeight subscribed) $! innerHeight
523− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight outerHeight
475+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight outerHeight
524− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight innerHeight
476+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight innerHeight
525 Just o -> do -- Since it's already firing, no need to adjust height
477 Just o -> do -- Since it's already firing, no need to adjust height
526 liftIO $ writeIORef (coincidenceSubscribedOccurrence subscribed) occ
478 liftIO $ writeIORef (coincidenceSubscribedOccurrence subscribed) occ
527 scheduleClear $ coincidenceSubscribedOccurrence subscribed
479 scheduleClear $ coincidenceSubscribedOccurrence subscribed
528 propagate o $ coincidenceSubscribedSubscribers subscribed
480 propagate o $ coincidenceSubscribedSubscribers subscribed
529 , subscriberInvalidateHeight = \_ -> invalidateCoincidenceHeight subscribed
481 , subscriberInvalidateHeight = \_ -> invalidateCoincidenceHeight subscribed
530− , subscriberRecalculateHeight = \_ -> recalculateCoincidenceHeight subscribed
482+ , subscriberRecalculateHeight = \_ -> recalculateCoincidenceHeight subscribed
533newSubscriberCoincidenceInner :: forall x a. HasSpiderTimeline x => CoincidenceSubscribed x a -> IO (Subscriber x a)
485newSubscriberCoincidenceInner :: forall x a. HasSpiderTimeline x => CoincidenceSubscribed x a -> IO (Subscriber x a)
@@ -548,21 +500,21 @@ invalidateSubscriberHeight :: Height -> Subscriber x a -> IO ()
548invalidateSubscriberHeight = flip subscriberInvalidateHeight
500invalidateSubscriberHeight = flip subscriberInvalidateHeight
550recalculateSubscriberHeight :: Height -> Subscriber x a -> IO ()
502recalculateSubscriberHeight :: Height -> Subscriber x a -> IO ()
551−recalculateSubscriberHeight = flip subscriberRecalculateHeight
503+recalculateSubscriberHeight = flip subscriberRecalculateHeight
553-- | Propagate everything at the current height
505-- | Propagate everything at the current height
554propagate :: forall x a. HasSpiderTimeline x => a -> WeakBag (Subscriber x a) -> EventM x ()
506propagate :: 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) $
556 -- 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
508 -- 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
557 --TODO: Should we check if nodes already have their values before propagating? Maybe we're re-doing work
509 --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
560-- | Propagate everything at the current height
512-- | Propagate everything at the current height
561propagateFast :: forall x a. HasSpiderTimeline x => a -> FastWeakBag (Subscriber x a) -> EventM x ()
513propagateFast :: 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) $
563 -- 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
515 -- 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
564 --TODO: Should we check if nodes already have their values before propagating? Maybe we're re-doing work
516 --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
567--------------------------------------------------------------------------------
519--------------------------------------------------------------------------------
568-- EventSubscribed
520-- EventSubscribed
@@ -607,16 +559,6 @@ eventSubscribedNever = EventSubscribed
607 , eventSubscribedWhoCreated = return ["never"]
559 , eventSubscribedWhoCreated = return ["never"]
610−eventSubscribedNow :: EventSubscribed x
611−eventSubscribedNow = EventSubscribed
612− { eventSubscribedHeightRef = zeroRef
613− , eventSubscribedRetained = toAny ()
615− , eventSubscribedGetParents = return []
616− , eventSubscribedHasOwnHeightRef = False
617− , eventSubscribedWhoCreated = return ["now"]
621eventSubscribedFan :: FanSubscribed x k v -> EventSubscribed x
563eventSubscribedFan :: FanSubscribed x k v -> EventSubscribed x
622eventSubscribedFan !subscribed = EventSubscribed
564eventSubscribedFan !subscribed = EventSubscribed
@@ -994,10 +936,8 @@ instance Monad (BehaviorM x) where
994 BehaviorM x >> BehaviorM y = BehaviorM $ x >> y
936 BehaviorM x >> BehaviorM y = BehaviorM $ x >> y
995 {-# INLINE return #-}
937 {-# INLINE return #-}
996 return x = BehaviorM $ return x
938 return x = BehaviorM $ return x
997−#if !MIN_VERSION_base(4,13,0)
998 {-# INLINE fail #-}
939 {-# INLINE fail #-}
999 fail s = BehaviorM $ fail s
940 fail s = BehaviorM $ fail s
1002data BehaviorSubscribed x a
942data BehaviorSubscribed x a
1003 = forall p. BehaviorSubscribedHold (Hold x p)
943 = forall p. BehaviorSubscribedHold (Hold x p)
@@ -1057,7 +997,7 @@ data SomeMergeUpdate x = SomeMergeUpdate
1057newtype SomeMergeInit x = SomeMergeInit { unSomeMergeInit :: EventM x () }
997newtype SomeMergeInit x = SomeMergeInit { unSomeMergeInit :: EventM x () }
1059-- EventM can do everything BehaviorM can, plus create holds
999-- 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)
1062newtype MergeSubscribedParent x a = MergeSubscribedParent { unMergeSubscribedParent :: EventSubscription x }
1002newtype MergeSubscribedParent x a = MergeSubscribedParent { unMergeSubscribedParent :: EventSubscription x }
@@ -1082,7 +1022,7 @@ heightBagFromList :: [Height] -> HeightBag
1082heightBagFromList heights = heightBagVerify $ foldl' (flip heightBagAdd) heightBagEmpty heights
1022heightBagFromList heights = heightBagVerify $ foldl' (flip heightBagAdd) heightBagEmpty heights
1084heightBagAdd :: Height -> HeightBag -> HeightBag
1024heightBagAdd :: 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) $
1086 IntMap.insertWithKey (\_ _ old -> succ old) h 0 c
1026 IntMap.insertWithKey (\_ _ old -> succ old) h 0 c
1088heightBagRemove :: Height -> HeightBag -> HeightBag
1028heightBagRemove :: Height -> HeightBag -> HeightBag
@@ -1093,11 +1033,11 @@ heightBagRemove (Height h) b@(HeightBag s c) = heightBagVerify $ case IntMap.loo
1093 _ -> IntMap.insert h (pred old) c
1033 _ -> IntMap.insert h (pred old) c
1095heightBagRemoveMaybe :: Height -> HeightBag -> Maybe HeightBag
1035heightBagRemoveMaybe :: 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
1097 removed old = HeightBag (pred s) $ case old of
1037 removed old = HeightBag (pred s) $ case old of
1098 0 -> IntMap.delete h c
1038 0 -> IntMap.delete h c
1099 _ -> IntMap.insert h (pred old) c
1039 _ -> IntMap.insert h (pred old) c
1102heightBagMax :: HeightBag -> Height
1042heightBagMax :: HeightBag -> Height
1103heightBagMax (HeightBag _ c) = case IntMap.maxViewWithKey c of
1043heightBagMax (HeightBag _ c) = case IntMap.maxViewWithKey c of
@@ -1199,10 +1139,7 @@ instance HasSpiderTimeline x => Semialign (Event x) where
1199 align ea eb = mapMaybe dmapToThese $ mergeG coerce $ dynamicConst $
1139 align ea eb = mapMaybe dmapToThese $ mergeG coerce $ dynamicConst $
1200 DMap.fromDistinctAscList [LeftTag :=> ea, RightTag :=> eb]
1140 DMap.fromDistinctAscList [LeftTag :=> ea, RightTag :=> eb]
1202−#ifdef MIN_VERSION_semialign
1142+#if defined(MIN_VERSION_semialign)
1203−#if MIN_VERSION_semialign(1,1,0)
1204−instance HasSpiderTimeline x => Zip (Event x) where
1206 zip x y = mapMaybe justThese $ align x y
1143 zip x y = mapMaybe justThese $ align x y
@@ -1346,7 +1283,7 @@ mkWeakPtrWithDebug x debugNote = do
1346 x' <- evaluate x
1283 x' <- evaluate x
1347 mkWeakPtr x' $
1284 mkWeakPtr x' $
1348 if debugFinalize
1285 if debugFinalize
1349− then Just $ debugStrLn $ "finalizing: " ++ debugNote
1286+ then Just $ putStrLn $ "finalizing: " ++ debugNote
1350 else Nothing
1287 else Nothing
1352type WeakList a = [Weak a]
1289type WeakList a = [Weak a]
@@ -1361,20 +1298,21 @@ type CanTrace x m = (HasSpiderTimeline x, MonadIO m)
1361debugSubscriber :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> IO (Subscriber x a)
1298debugSubscriber :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> IO (Subscriber x a)
1362debugSubscriber description = return . debugSubscriber' description
1299debugSubscriber description = return . debugSubscriber' description
1364debugSubscriber' :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> Subscriber x a
1302debugSubscriber' :: forall x a. HasSpiderTimeline x => String -> Subscriber x a -> Subscriber x a
1365−debugSubscriber' description subscribed = Subscriber
1303+debugSubscriber' description subscribed = Subscriber
1367 subscriberPropagate = \m -> do
1305 subscriberPropagate = \m -> do
1368 tracePropagate (Proxy :: Proxy x) ("subscriberPropagate: " <> description)
1306 tracePropagate (Proxy :: Proxy x) ("subscriberPropagate: " <> description)
1369 subscriberPropagate subscribed m
1307 subscriberPropagate subscribed m
1370 , subscriberInvalidateHeight = \old -> do
1308 , subscriberInvalidateHeight = \old -> do
1371− traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
1309+ putStrLn $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
1372 subscriberInvalidateHeight subscribed old
1310 subscriberInvalidateHeight subscribed old
1373− traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", done"
1311+ putStrLn $ "invalidateSubscriberHeight: " <> description <> ", done"
1374 , subscriberRecalculateHeight = \new -> do
1312 , subscriberRecalculateHeight = \new -> do
1375− traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
1313+ putStrLn $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
1376 subscriberRecalculateHeight subscribed new
1314 subscriberRecalculateHeight subscribed new
1377− traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", done"
1315+ putStrLn $ "subscriberRecalculateHeight: " <> description <> ", done"
@@ -1388,15 +1326,11 @@ withIncreasedDepth _ a = do
1389{-# INLINE tracePropagate #-}
1327{-# INLINE tracePropagate #-}
1390tracePropagate :: (CanTrace x m) => proxy x -> String -> m ()
1328tracePropagate :: (CanTrace x m) => proxy x -> String -> m ()
1391−tracePropagate p = when debugPropagate . trace p
1329+tracePropagate p = trace p
1393{-# INLINE traceInvalidate #-}
1331{-# INLINE traceInvalidate #-}
1394traceInvalidate :: String -> IO ()
1332traceInvalidate :: String -> IO ()
1395−traceInvalidate = when debugInvalidate . liftIO . debugStrLn
1333+traceInvalidate = liftIO . putStrLn
1397−{-# INLINE traceInvalidateHeight #-}
1398−traceInvalidateHeight :: String -> IO ()
1399−traceInvalidateHeight = when debugInvalidateHeight . liftIO . debugStrLn
1401{-# INLINE trace #-}
1335{-# INLINE trace #-}
1402trace :: (CanTrace x m) => proxy x -> String -> m ()
1336trace :: (CanTrace x m) => proxy x -> String -> m ()
@@ -1407,7 +1341,7 @@ traceM :: forall x proxy m. (CanTrace x m) => proxy x -> m String -> m ()
1407traceM _ getMessage = do
1341traceM _ getMessage = do
1408 message <- getMessage
1342 message <- getMessage
1409 d <- liftIO $ readIORef $ _spiderTimeline_depth $ unSTE (spiderTimeline :: SpiderTimelineEnv x)
1343 d <- liftIO $ readIORef $ _spiderTimeline_depth $ unSTE (spiderTimeline :: SpiderTimelineEnv x)
1410− liftIO $ debugStrLn $ replicate d ' ' <> message
1344+ liftIO $ putStrLn $ replicate d ' ' <> message
@@ -1423,20 +1357,10 @@ tracePropagate _ _ = return ()
1423traceInvalidate :: String -> IO ()
1357traceInvalidate :: String -> IO ()
1424traceInvalidate _ = return ()
1358traceInvalidate _ = return ()
1426−{-# INLINE traceInvalidateHeight #-}
1427−traceInvalidateHeight :: String -> IO ()
1428−traceInvalidateHeight _ = return ()
1430{-# INLINE debugSubscriber #-}
1360{-# INLINE debugSubscriber #-}
1431debugSubscriber :: String -> Subscriber x a -> IO (Subscriber x a)
1361debugSubscriber :: String -> Subscriber x a -> IO (Subscriber x a)
1432debugSubscriber _ = return
1362debugSubscriber _ = return
1434−{-# INLINE debugSubscriber' #-}
1435−debugSubscriber' :: String -> Subscriber x a -> Subscriber x a
1436−debugSubscriber' _ = id
1440{-# INLINE trace #-}
1364{-# INLINE trace #-}
1441trace :: (CanTrace x m) => proxy x -> String -> m ()
1365trace :: (CanTrace x m) => proxy x -> String -> m ()
1442trace _ _ = return ()
1366trace _ _ = return ()
@@ -1467,20 +1391,17 @@ showStacks :: [[String]] -> String
1467showStacks = drawForest . listsToForest . fmap (filterStack "Reflex.Spider.Internal")
1391showStacks = drawForest . listsToForest . fmap (filterStack "Reflex.Spider.Internal")
1469filterStack :: String -> [String] -> [String]
1393filterStack :: String -> [String] -> [String]
1470−#ifdef DEBUG_HIDE_INTERNALS
1471filterStack prefix = filter (not . (prefix `isPrefixOf`))
1394filterStack prefix = filter (not . (prefix `isPrefixOf`))
1473−filterStack prefix = id
1476#ifdef DEBUG_CYCLES
1397#ifdef DEBUG_CYCLES
1478−data EventLoopException = EventLoopException [[String]]
1399+data EventLoopException = EventLoopException [[String]]
1479instance Exception EventLoopException
1400instance Exception EventLoopException
1481instance Show EventLoopException where
1402instance Show EventLoopException where
1482− show (EventLoopException stacks) = "causality loop detected:\n" <> if null stacks
1403+ show (EventLoopException stacks) = "causality loop detected:\n" <> if null stacks
1483− then "no location information, compile with profiling enabled for stack tree"
1404+ then "no location information, compile with profiling enabled for stack tree"
1484 else showStacks stacks
1405 else showStacks stacks
@@ -1498,7 +1419,7 @@ instance Show EventLoopException where
1498{-# INLINE propagateSubscriberHold #-}
1419{-# INLINE propagateSubscriberHold #-}
1499propagateSubscriberHold :: forall x p. (HasSpiderTimeline x, Patch p) => Hold x p -> p -> EventM x ()
1420propagateSubscriberHold :: forall x p. (HasSpiderTimeline x, Patch p) => Hold x p -> p -> EventM x ()
1500propagateSubscriberHold h a = do
1421propagateSubscriberHold h a = do
1501− {-# SCC "trace" #-} when debugPropagate $ traceM (Proxy :: Proxy x) $ liftIO $ do
1422+ traceM (Proxy :: Proxy x) $ liftIO $ do
1502 invalidators <- liftIO $ readIORef $ holdInvalidators h
1423 invalidators <- liftIO $ readIORef $ holdInvalidators h
1503 return $ "SubscriberHold" <> showNodeId h <> ": " ++ show (length invalidators)
1424 return $ "SubscriberHold" <> showNodeId h <> ": " ++ show (length invalidators)
@@ -1506,7 +1427,7 @@ propagateSubscriberHold h a = do
1506 case {-# SCC "apply" #-} apply a v of
1427 case {-# SCC "apply" #-} apply a v of
1507 Nothing -> return ()
1428 Nothing -> return ()
1508 Just v' -> do
1429 Just v' -> do
1509− {-# SCC "trace2" #-} withIncreasedDepth (Proxy :: Proxy x) $
1430+ withIncreasedDepth (Proxy :: Proxy x) $
1510 tracePropagate (Proxy :: Proxy x) ("propagateSubscriberHold: assigning Hold" <> showNodeId h)
1431 tracePropagate (Proxy :: Proxy x) ("propagateSubscriberHold: assigning Hold" <> showNodeId h)
1511 vRef <- {-# SCC "vRef" #-} liftIO $ evaluate $ holdValue h
1432 vRef <- {-# SCC "vRef" #-} liftIO $ evaluate $ holdValue h
1512 iRef <- {-# SCC "iRef" #-} liftIO $ evaluate $ holdInvalidators h
1433 iRef <- {-# SCC "iRef" #-} liftIO $ evaluate $ holdInvalidators h
@@ -1627,7 +1548,7 @@ data FanInt x a = FanInt
1627 { _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
1548 { _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
1628 , _fanInt_subscriptionRef :: {-# UNPACK #-} !(IORef (EventSubscription x)) -- This should have a valid subscription iff subscribers is non-empty
1549 , _fanInt_subscriptionRef :: {-# UNPACK #-} !(IORef (EventSubscription x)) -- This should have a valid subscription iff subscribers is non-empty
1629 , _fanInt_occRef :: {-# UNPACK #-} !(IORef (IntMap a))
1550 , _fanInt_occRef :: {-# UNPACK #-} !(IORef (IntMap a))
1630−#ifdef DEBUG_NODEIDS
1551+#ifdef DEBUG_NODEIDS
1631 , _fanInt_nodeId :: {-# UNPACK #-} !Int
1552 , _fanInt_nodeId :: {-# UNPACK #-} !Int
@@ -1637,15 +1558,15 @@ newFanInt = do
1637 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
1558 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
1638 subscriptionRef <- newIORef $ error "fanInt: no subscription"
1559 subscriptionRef <- newIORef $ error "fanInt: no subscription"
1639 occRef <- newIORef $ error "fanInt: no occurrence"
1560 occRef <- newIORef $ error "fanInt: no occurrence"
1640−#ifdef DEBUG_NODEIDS
1561+#ifdef DEBUG_NODEIDS
1641 nodeId <- newNodeId
1562 nodeId <- newNodeId
1643 return $ FanInt
1564 return $ FanInt
1644 { _fanInt_subscribers = subscribers
1565 { _fanInt_subscribers = subscribers
1645 , _fanInt_subscriptionRef = subscriptionRef
1566 , _fanInt_subscriptionRef = subscriptionRef
1646 , _fanInt_occRef = occRef
1567 , _fanInt_occRef = occRef
1647−#ifdef DEBUG_NODEIDS
1568+#ifdef DEBUG_NODEIDS
1648− , _fanInt_nodeId = nodeId
1569+ , _fanInt_nodeId = nodeId
@@ -1661,15 +1582,15 @@ fanInt p = unsafePerformIO $ do
1661 liftIO $ writeIORef (_fanInt_occRef self) m
1582 liftIO $ writeIORef (_fanInt_occRef self) m
1662 scheduleIntClear $ _fanInt_occRef self
1583 scheduleIntClear $ _fanInt_occRef self
1663 FastMutableIntMap.forIntersectionWithImmutable_ (_fanInt_subscribers self) m $ \b v -> --TODO: Do we need to know that no subscribers are being added as we traverse?
1584 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 ->
1665 subscriberPropagate s v
1586 subscriberPropagate s v
1666− , subscriberInvalidateHeight = \old ->
1587+ , subscriberInvalidateHeight = \old ->
1667− FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1588+ FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1668− FastWeakBag.traverse_ b $ \s ->
1589+ FastWeakBag.traverse b $ \s ->
1669 subscriberInvalidateHeight s old
1590 subscriberInvalidateHeight s old
1670 , subscriberRecalculateHeight = \new ->
1591 , subscriberRecalculateHeight = \new ->
1671− FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1592+ FastMutableIntMap.for_ (_fanInt_subscribers self) $ \b ->
1672− FastWeakBag.traverse_ b $ \s ->
1593+ FastWeakBag.traverse b $ \s ->
1673 subscriberRecalculateHeight s new
1594 subscriberRecalculateHeight s new
1675 liftIO $ do
1596 liftIO $ do
@@ -1685,14 +1606,14 @@ fanInt p = unsafePerformIO $ do
1685 Just b -> return b
1606 Just b -> return b
1686 ticket <- liftIO $ FastWeakBag.insert sub b
1607 ticket <- liftIO $ FastWeakBag.insert sub b
1687 currentOcc <- readIORef (_fanInt_occRef self)
1608 currentOcc <- readIORef (_fanInt_occRef self)
1689 subscribed <- fanIntSubscribed ticket self
1610 subscribed <- fanIntSubscribed ticket self
1690 return (EventSubscription (FastWeakBag.remove ticket) subscribed, IntMap.lookup k currentOcc)
1611 return (EventSubscription (FastWeakBag.remove ticket) subscribed, IntMap.lookup k currentOcc)
1692fanIntSubscribed :: FastWeakBagTicket k -> FanInt x a -> IO (EventSubscribed x)
1613fanIntSubscribed :: FastWeakBagTicket k -> FanInt x a -> IO (EventSubscribed x)
1693−fanIntSubscribed ticket self = do
1614+fanIntSubscribed ticket self = do
1694 subscribedParent <- _eventSubscription_subscribed <$> readIORef (_fanInt_subscriptionRef self)
1615 subscribedParent <- _eventSubscription_subscribed <$> readIORef (_fanInt_subscriptionRef self)
1695− return $ EventSubscribed
1616+ return $ EventSubscribed
1696 { eventSubscribedHeightRef = eventSubscribedHeightRef subscribedParent
1617 { eventSubscribedHeightRef = eventSubscribedHeightRef subscribedParent
1697 , eventSubscribedRetained = toAny (_fanInt_subscriptionRef self, ticket)
1618 , eventSubscribedRetained = toAny (_fanInt_subscriptionRef self, ticket)
1698#ifdef DEBUG_CYCLES
1619#ifdef DEBUG_CYCLES
@@ -1701,7 +1622,7 @@ fanIntSubscribed ticket self = do
1701 , eventSubscribedWhoCreated = whoCreatedIORef $ _fanInt_subscriptionRef self
1622 , eventSubscribedWhoCreated = whoCreatedIORef $ _fanInt_subscriptionRef self
1706{-# INLINABLE getFanSubscribed #-}
1627{-# INLINABLE getFanSubscribed #-}
1707getFanSubscribed :: (HasSpiderTimeline x, GCompare k) => k a -> Fan x k v -> Subscriber x (v a) -> EventM x (WeakBagTicket, FanSubscribed x k v, Maybe (v a))
1628getFanSubscribed :: (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
1914 liftIO $ modifyIORef' heightBagRef $ heightBagAdd newParentHeight
1835 liftIO $ modifyIORef' heightBagRef $ heightBagAdd newParentHeight
1915 return $ DMap.insertLookupWithKey' (\_ new _ -> new) k newParent ps
1836 return $ DMap.insertLookupWithKey' (\_ new _ -> new) k newParent ps
1916 forM_ mOldSubd $ \oldSubd -> do
1837 forM_ mOldSubd $ \oldSubd -> do
1917− oldHeight <- liftIO $ getEventSubscribedHeight $
1838+ oldHeight <- liftIO $ getEventSubscribedHeight $
1918 _eventSubscription_subscribed $ unMergeSubscribedParent oldSubd
1839 _eventSubscription_subscribed $ unMergeSubscribedParent oldSubd
1920 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
1841 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
@@ -1960,7 +1881,7 @@ mergeCheapWithMove nt = mergeGCheap' _mergeSubscribedParentWithMove_subscription
1960 let moveOrDelete :: forall a. k a -> PatchDMapWithMove.NodeInfo k q a -> MergeSubscribedParentWithMove x k a -> Constant (EventM x (Maybe (EventSubscription x))) a
1881 let moveOrDelete :: forall a. k a -> PatchDMapWithMove.NodeInfo k q a -> MergeSubscribedParentWithMove x k a -> Constant (EventM x (Maybe (EventSubscription x))) a
1961 moveOrDelete _ ni parent = Constant $ case getComposeMaybe $ PatchDMapWithMove._nodeInfo_to ni of
1882 moveOrDelete _ ni parent = Constant $ case getComposeMaybe $ PatchDMapWithMove._nodeInfo_to ni of
1962 Nothing -> do
1883 Nothing -> do
1963− oldHeight <- liftIO $ getEventSubscribedHeight $ _eventSubscription_subscribed $
1884+ oldHeight <- liftIO $ getEventSubscribedHeight $ _eventSubscription_subscribed $
1964 _mergeSubscribedParentWithMove_subscription parent
1885 _mergeSubscribedParentWithMove_subscription parent
1966 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
1887 liftIO $ modifyIORef heightBagRef $ heightBagRemove oldHeight
@@ -1968,7 +1889,7 @@ mergeCheapWithMove nt = mergeGCheap' _mergeSubscribedParentWithMove_subscription
1968 Just toKey -> do
1889 Just toKey -> do
1969 liftIO $ writeIORef (_mergeSubscribedParentWithMove_key parent) $! toKey
1890 liftIO $ writeIORef (_mergeSubscribedParentWithMove_key parent) $! toKey
1970 return Nothing
1891 return Nothing
1971− toDelete <- fmap catMaybes $ mapM (\(_ :=> v) -> getConstant v) $ DMap.toList $
1892+ toDelete <- fmap catMaybes $ mapM (\(_ :=> v) -> getConstant v) $ DMap.toList $
1972 DMap.intersectionWithKey moveOrDelete (unPatchDMapWithMove p) oldParents
1893 DMap.intersectionWithKey moveOrDelete (unPatchDMapWithMove p) oldParents
1974 return (toDelete, applyAlways p' oldParents)
1895 return (toDelete, applyAlways p' oldParents)
@@ -2021,16 +1942,16 @@ invalidateMergeHeight' :: IORef Height -> Subscriber x a -> IO ()
2021invalidateMergeHeight' heightRef sub = do
1942invalidateMergeHeight' heightRef sub = do
2022 oldHeight <- readIORef heightRef
1943 oldHeight <- readIORef heightRef
2023 -- If the height used to be valid, it must be invalid now; we should never have *more* heights than we have parents
1944 -- 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
2025 writeIORef heightRef $! invalidHeight
1946 writeIORef heightRef $! invalidHeight
2026 subscriberInvalidateHeight sub oldHeight
1947 subscriberInvalidateHeight sub oldHeight
2028revalidateMergeHeight :: Merge x k v s -> IO ()
1949revalidateMergeHeight :: Merge x k v s -> IO ()
2029revalidateMergeHeight m = do
1950revalidateMergeHeight m = do
2030 currentHeight <- readIORef $ _merge_heightRef m
1951 currentHeight <- readIORef $ _merge_heightRef m
2032 -- revalidateMergeHeight may be called multiple times; perhaps the's a way to finesse it to avoid this check
1953 -- 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
2034 heights <- readIORef $ _merge_heightBagRef m
1955 heights <- readIORef $ _merge_heightBagRef m
2035 parents <- readIORef $ _merge_parentsRef m
1956 parents <- readIORef $ _merge_parentsRef m
2036 -- When the number of heights in the bag reaches the number of parents, we should have a valid height
1957 -- 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
2038 LT -> return ()
1959 LT -> return ()
2039 EQ -> do
1960 EQ -> do
2040 let height = succHeight $ heightBagMax heights
1961 let height = succHeight $ heightBagMax heights
2041− traceInvalidateHeight $ "recalculateSubscriberHeight: height: " <> show height
1962+ traceInvalidate $ "recalculateSubscriberHeight: height: " <> show height
2042 writeIORef (_merge_heightRef m) $! height
1963 writeIORef (_merge_heightRef m) $! height
2043 subscriberRecalculateHeight (_merge_sub m) height
1964 subscriberRecalculateHeight (_merge_sub m) height
2044 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show (DMap.size parents) <> ") for Merge"
1965 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show (DMap.size parents) <> ") for Merge"
@@ -2046,22 +1967,22 @@ revalidateMergeHeight m = do
2046scheduleMergeSelf :: HasSpiderTimeline x => Merge x k v s -> Height -> EventM x ()
1967scheduleMergeSelf :: HasSpiderTimeline x => Merge x k v s -> Height -> EventM x ()
2047scheduleMergeSelf m height = scheduleMerge' height (_merge_heightRef m) $ do
1968scheduleMergeSelf m height = scheduleMerge' height (_merge_heightRef m) $ do
2048 vals <- liftIO $ readIORef $ _merge_accumRef m
1969 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,
2050 -- it'll handle subsequent subscribers, and if not, we won't get subsequent subscribers
1971 -- 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
2052 --TODO: Assert that m is not empty
1973 --TODO: Assert that m is not empty
2053 subscriberPropagate (_merge_sub m) vals
1974 subscriberPropagate (_merge_sub m) vals
2055checkCycle :: HasSpiderTimeline x => EventSubscribed x -> EventM x ()
1976checkCycle :: HasSpiderTimeline x => EventSubscribed x -> EventM x ()
2056checkCycle subscribed = liftIO $ do
1977checkCycle subscribed = liftIO $ do
2057 height <- readIORef (eventSubscribedHeightRef subscribed)
1978 height <- readIORef (eventSubscribedHeightRef subscribed)
2059 -- currentHeight <- getCurrentHeight
1980 -- currentHeight <- getCurrentHeight
2060 -- when (height <= currentHeight) $ if height /= invalidHeight
1981 -- when (height <= currentHeight) $ if height /= invalidHeight
2061 -- then do
1982 -- then do
2062 -- myStack <- liftIO $ whoCreatedIORef undefined --TODO
1983 -- myStack <- liftIO $ whoCreatedIORef undefined --TODO
2063 -- error $ "Height (" ++ show height ++ ") is not greater than current height (" ++ show currentHeight ++ ")\n" ++ unlines (reverse myStack)
1984 -- error $ "Height (" ++ show height ++ ") is not greater than current height (" ++ show currentHeight ++ ")\n" ++ unlines (reverse myStack)
2064− -- else liftIO $
1985+ -- else liftIO $
2065 when (height == invalidHeight) $
1986 when (height == invalidHeight) $
2066#ifdef DEBUG_CYCLES
1987#ifdef DEBUG_CYCLES
@@ -2114,17 +2035,17 @@ mergeGCheap' getParent getInitialSubscribers updateFunc destroy d = Event $ \sub
2114 parentsRef :: IORef (DMap k s) <- liftIO $ newIORef $ error "merge: parentsRef not yet initialized"
2035 parentsRef :: IORef (DMap k s) <- liftIO $ newIORef $ error "merge: parentsRef not yet initialized"
2115 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
2036 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
2117− let subscribed = EventSubscribed
2038+ let subscribed = EventSubscribed
2118− { eventSubscribedHeightRef = heightRef
2039+ { eventSubscribedHeightRef = heightRef
2119 , eventSubscribedRetained = toAny (parentsRef, changeSubdRef)
2040 , eventSubscribedRetained = toAny (parentsRef, changeSubdRef)
2120#ifdef DEBUG_CYCLES
2041#ifdef DEBUG_CYCLES
2121 , eventSubscribedGetParents = do
2042 , eventSubscribedGetParents = do
2122 let getParent' (_ :=> v) = _eventSubscription_subscribed (getParent v)
2043 let getParent' (_ :=> v) = _eventSubscription_subscribed (getParent v)
2123− fmap getParent' . DMap.toList <$> readIORef parentsRef
2044+ fmap getParent' . DMap.toList <$> readIORef parentsRef
2124 , eventSubscribedHasOwnHeightRef = False
2045 , eventSubscribedHasOwnHeightRef = False
2125 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2046 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2129 m = Merge
2050 m = Merge
2130 { _merge_parentsRef = parentsRef
2051 { _merge_parentsRef = parentsRef
@@ -2162,9 +2083,9 @@ mergeGCheap' getParent getInitialSubscribers updateFunc destroy d = Event $ \sub
2162 -- its subscription.
2083 -- its subscription.
2163 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
2084 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
2164 let unsubscribeAll = destroy =<< readIORef parentsRef
2085 let unsubscribeAll = destroy =<< readIORef parentsRef
2166 return (EventSubscription unsubscribeAll subscribed, occ)
2087 return (EventSubscription unsubscribeAll subscribed, occ)
2169mergeInt :: forall x a. (HasSpiderTimeline x) => DynamicS x (PatchIntMap (Event x a)) -> Event x (IntMap a)
2090mergeInt :: forall x a. (HasSpiderTimeline x) => DynamicS x (PatchIntMap (Event x a)) -> Event x (IntMap a)
2170mergeInt = cacheEvent . mergeIntCheap
2091mergeInt = cacheEvent . mergeIntCheap
@@ -2178,14 +2099,14 @@ mergeIntCheap d = Event $ \sub -> do
2178 heightBagRef <- liftIO $ newIORef heightBagEmpty
2099 heightBagRef <- liftIO $ newIORef heightBagEmpty
2179 parents <- liftIO $ FastMutableIntMap.newEmpty
2100 parents <- liftIO $ FastMutableIntMap.newEmpty
2180 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
2101 changeSubdRef <- liftIO $ newIORef $ error "getMergeSubscribed: changeSubdRef not yet initialized"
2181− let subscribed = EventSubscribed
2102+ let subscribed = EventSubscribed
2182− { eventSubscribedHeightRef = heightRef
2103+ { eventSubscribedHeightRef = heightRef
2183 , eventSubscribedRetained = toAny (parents, changeSubdRef)
2104 , eventSubscribedRetained = toAny (parents, changeSubdRef)
2184#ifdef DEBUG_CYCLES
2105#ifdef DEBUG_CYCLES
2185 , eventSubscribedGetParents = fmap (_eventSubscription_subscribed . snd) <$> FastMutableIntMap.toList parents
2106 , eventSubscribedGetParents = fmap (_eventSubscription_subscribed . snd) <$> FastMutableIntMap.toList parents
2186 , eventSubscribedHasOwnHeightRef = False
2107 , eventSubscribedHasOwnHeightRef = False
2187 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2108 , eventSubscribedWhoCreated = whoCreatedIORef heightRef
2190 let scheduleSelf = do
2111 let scheduleSelf = do
2191 height <- liftIO $ readIORef $ heightRef
2112 height <- liftIO $ readIORef $ heightRef
@@ -2202,7 +2123,7 @@ mergeIntCheap d = Event $ \sub -> do
2202 LT -> return ()
2123 LT -> return ()
2203 EQ -> do
2124 EQ -> do
2204 let height = succHeight $ heightBagMax heights
2125 let height = succHeight $ heightBagMax heights
2205− traceInvalidateHeight $ "recalculateSubscriberHeight: height: " <> show height
2126+ traceInvalidate $ "recalculateSubscriberHeight: height: " <> show height
2206 writeIORef heightRef $! height
2127 writeIORef heightRef $! height
2207 subscriberRecalculateHeight sub height
2128 subscriberRecalculateHeight sub height
2208 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show numParents <> ") for Merge"
2129 GT -> error $ "revalidateMergeHeight: more heights (" <> show (heightBagSize heights) <> ") than parents (" <> show numParents <> ") for Merge"
@@ -2274,7 +2195,7 @@ mergeIntCheap d = Event $ \sub -> do
2274 -- its subscription.
2195 -- its subscription.
2275 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
2196 liftIO $ writeIORef changeSubdRef (changeSubscriber, changeSubscription)
2276 let unsubscribeAll = traverse_ unsubscribe =<< FastMutableIntMap.getFrozenAndClear parents
2197 let unsubscribeAll = traverse_ unsubscribe =<< FastMutableIntMap.getFrozenAndClear parents
2279 return (EventSubscription unsubscribeAll subscribed, occ)
2200 return (EventSubscription unsubscribeAll subscribed, occ)
@@ -2385,7 +2306,7 @@ runFrame a = SpiderHost $ do
2385 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
2306 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
2387 stackTrace <- liftIO $ fmap renderStack $ ccsToStrings =<< (getCCSOf $! switchSubscribedParent subscribed)
2308 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
2389 EventRoot _ -> "EventRoot"
2310 EventRoot _ -> "EventRoot"
2390 EventNever -> "EventNever"
2311 EventNever -> "EventNever"
2391 _ -> "something else"
2312 _ -> "something else"
@@ -2400,7 +2321,7 @@ runFrame a = SpiderHost $ do
2400 myHeight <- readIORef $ switchSubscribedHeight subscribed
2321 myHeight <- readIORef $ switchSubscribedHeight subscribed
2401 when (parentHeight /= myHeight) $ do
2322 when (parentHeight /= myHeight) $ do
2402 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
2323 writeIORef (switchSubscribedHeight subscribed) $! invalidHeight
2403− WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight myHeight
2324+ WeakBag.traverse (switchSubscribedSubscribers subscribed) $ invalidateSubscriberHeight myHeight
2404 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
2325 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
2405 forM_ coincidenceInfos $ \(SomeResetCoincidence subscription mcs) -> do
2326 forM_ coincidenceInfos $ \(SomeResetCoincidence subscription mcs) -> do
2406 unsubscribe subscription
2327 unsubscribe subscription
@@ -2441,7 +2362,7 @@ invalidateCoincidenceHeight subscribed = do
2441 oldHeight <- readIORef $ coincidenceSubscribedHeight subscribed
2362 oldHeight <- readIORef $ coincidenceSubscribedHeight subscribed
2442 when (oldHeight /= invalidHeight) $ do
2363 when (oldHeight /= invalidHeight) $ do
2443 writeIORef (coincidenceSubscribedHeight subscribed) $! invalidHeight
2364 writeIORef (coincidenceSubscribedHeight subscribed) $! invalidHeight
2444− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
2365+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ invalidateSubscriberHeight oldHeight
2446updateSwitchHeight :: Height -> SwitchSubscribed x a -> IO ()
2367updateSwitchHeight :: Height -> SwitchSubscribed x a -> IO ()
2447updateSwitchHeight new subscribed = do
2368updateSwitchHeight new subscribed = do
@@ -2449,7 +2370,7 @@ updateSwitchHeight new subscribed = do
2449 when (oldHeight == invalidHeight) $ do --TODO: This 'when' should probably be an assertion
2370 when (oldHeight == invalidHeight) $ do --TODO: This 'when' should probably be an assertion
2450 when (new /= invalidHeight) $ do --TODO: This 'when' should probably be an assertion
2371 when (new /= invalidHeight) $ do --TODO: This 'when' should probably be an assertion
2451 writeIORef (switchSubscribedHeight subscribed) $! new
2372 writeIORef (switchSubscribedHeight subscribed) $! new
2452− WeakBag.traverse_ (switchSubscribedSubscribers subscribed) $ recalculateSubscriberHeight new
2373+ WeakBag.traverse (switchSubscribedSubscribers subscribed) $ recalculateSubscriberHeight new
2454recalculateCoincidenceHeight :: CoincidenceSubscribed x a -> IO ()
2375recalculateCoincidenceHeight :: CoincidenceSubscribed x a -> IO ()
2455recalculateCoincidenceHeight subscribed = do
2376recalculateCoincidenceHeight subscribed = do
@@ -2458,7 +2379,7 @@ recalculateCoincidenceHeight subscribed = do
2458 height <- calculateCoincidenceHeight subscribed
2379 height <- calculateCoincidenceHeight subscribed
2459 when (height /= invalidHeight) $ do
2380 when (height /= invalidHeight) $ do
2460 writeIORef (coincidenceSubscribedHeight subscribed) $! height
2381 writeIORef (coincidenceSubscribedHeight subscribed) $! height
2461− WeakBag.traverse_ (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight height
2382+ WeakBag.traverse (coincidenceSubscribedSubscribers subscribed) $ recalculateSubscriberHeight height
2463calculateSwitchHeight :: SwitchSubscribed x a -> IO Height
2384calculateSwitchHeight :: SwitchSubscribed x a -> IO Height
2464calculateSwitchHeight subscribed = getEventSubscribedHeight . _eventSubscription_subscribed =<< readIORef (switchSubscribedCurrentParent subscribed)
2385calculateSwitchHeight subscribed = getEventSubscribedHeight . _eventSubscription_subscribed =<< readIORef (switchSubscribedCurrentParent subscribed)
@@ -2520,8 +2441,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Event
2520 {-# INLINABLE headE #-}
2441 {-# INLINABLE headE #-}
2521 headE = R.slowHeadE
2442 headE = R.slowHeadE
2522-- headE (SpiderEvent e) = SpiderEvent <$> Reflex.Spider.Internal.headE e
2443-- headE (SpiderEvent e) = SpiderEvent <$> Reflex.Spider.Internal.headE e
2523− {-# INLINABLE now #-}
2524− now = nowSpiderEventM
2526instance Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPullM x) where
2445instance Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPullM x) where
2527 {-# INLINABLE sample #-}
2446 {-# INLINABLE sample #-}
@@ -2543,9 +2462,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
2543 {-# INLINABLE headE #-}
2462 {-# INLINABLE headE #-}
2544 headE = R.slowHeadE
2463 headE = R.slowHeadE
2545-- headE (SpiderEvent e) = SpiderPushM $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2464-- headE (SpiderEvent e) = SpiderPushM $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2546− {-# INLINABLE now #-}
2547− now = SpiderPushM nowSpiderEventM
2550instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
2466instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
2551 {-# INLINE return #-}
2467 {-# INLINE return #-}
@@ -2554,10 +2470,8 @@ instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x))
2554 x >>= f = SpiderDynamic $ dynamicDynIdentity $ newJoinDyn $ newMapDyn (unSpiderDynamic . f) $ unSpiderDynamic x
2470 x >>= f = SpiderDynamic $ dynamicDynIdentity $ newJoinDyn $ newMapDyn (unSpiderDynamic . f) $ unSpiderDynamic x
2555 {-# INLINE (>>) #-}
2471 {-# INLINE (>>) #-}
2556 (>>) = (*>)
2472 (>>) = (*>)
2557−#if !MIN_VERSION_base(4,13,0)
2558 {-# INLINE fail #-}
2473 {-# INLINE fail #-}
2559 fail _ = error "Dynamic does not support 'fail'"
2474 fail _ = error "Dynamic does not support 'fail'"
2562{-# INLINABLE newJoinDyn #-}
2476{-# INLINABLE newJoinDyn #-}
2563newJoinDyn :: HasSpiderTimeline x => DynamicS x (Identity (DynamicS x (Identity a))) -> Reflex.Spider.Internal.Dyn x (Identity a)
2477newJoinDyn :: 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
2609 buildDynamic getV0 e = runFrame . runSpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
2523 buildDynamic getV0 e = runFrame . runSpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
2610 {-# INLINABLE headE #-}
2524 {-# INLINABLE headE #-}
2611 headE e = runFrame . runSpiderHostFrame $ Reflex.Class.headE e
2525 headE e = runFrame . runSpiderHostFrame $ Reflex.Class.headE e
2612− {-# INLINABLE now #-}
2613− now = runFrame . runSpiderHostFrame $ Reflex.Class.now
2616instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHostFrame x) where
2527instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHostFrame x) where
2617 sample = SpiderHostFrame . readBehaviorUntracked . unSpiderBehavior --TODO: This can cause problems with laziness, so we should get rid of it if we can
2528 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
2628 {-# INLINABLE headE #-}
2539 {-# INLINABLE headE #-}
2629 headE = R.slowHeadE
2540 headE = R.slowHeadE
2630-- headE (SpiderEvent e) = SpiderHostFrame $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2541-- headE (SpiderEvent e) = SpiderHostFrame $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2631− {-# INLINABLE now #-}
2632− now = SpiderHostFrame Reflex.Class.now
2634instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHost x) where
2543instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHost x) where
2635 {-# INLINABLE sample #-}
2544 {-# INLINABLE sample #-}
@@ -2650,8 +2559,6 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Refle
2650 buildDynamic getV0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.buildDynamic getV0 e
2559 buildDynamic getV0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.buildDynamic getV0 e
2651 {-# INLINABLE headE #-}
2560 {-# INLINABLE headE #-}
2652 headE e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.headE e
2561 headE e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.headE e
2653− {-# INLINABLE now #-}
2654− now = Reflex.Spider.Internal.ReadPhase Reflex.Class.now
2656--------------------------------------------------------------------------------
2563--------------------------------------------------------------------------------
2657-- Deprecated items
2564-- Deprecated items
@@ -2775,7 +2682,7 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
2775 fanG e = R.EventSelectorG $ SpiderEvent . selectG (fanG (unSpiderEvent e))
2682 fanG e = R.EventSelectorG $ SpiderEvent . selectG (fanG (unSpiderEvent e))
2776 {-# INLINABLE mergeG #-}
2683 {-# INLINABLE mergeG #-}
2778− :: forall k2 (k :: k2 -> *) q (v :: k2 -> *). GCompare k
2685+ :: forall (k :: k2 -> *) q (v :: k2 -> *). GCompare k
2779 => (forall a. q a -> R.Event (SpiderTimeline x) (v a))
2686 => (forall a. q a -> R.Event (SpiderTimeline x) (v a))
2780 -> DMap k q
2687 -> DMap k q
2781 -> R.Event (SpiderTimeline x) (DMap k v)
2688 -> R.Event (SpiderTimeline x) (DMap k v)
@@ -2843,14 +2750,8 @@ instance Monad (SpiderHost x) where
2843 SpiderHost x >> SpiderHost y = SpiderHost $ x >> y
2750 SpiderHost x >> SpiderHost y = SpiderHost $ x >> y
2844 {-# INLINABLE return #-}
2751 {-# INLINABLE return #-}
2845 return x = SpiderHost $ return x
2752 return x = SpiderHost $ return x
2846−#if !MIN_VERSION_base(4,13,0)
2847− {-# INLINABLE fail #-}
2848− fail = MonadFail.fail
2851−instance MonadFail (SpiderHost x) where
2852 {-# INLINABLE fail #-}
2753 {-# INLINABLE fail #-}
2853− fail s = SpiderHost $ MonadFail.fail s
2754+ fail s = SpiderHost $ fail s
2855-- | Run an action affecting the global Spider timeline; this will be guarded by
2756-- | Run an action affecting the global Spider timeline; this will be guarded by
2856-- a mutex for that timeline
2757-- a mutex for that timeline
@@ -2872,10 +2773,8 @@ instance Monad (SpiderHostFrame x) where
2872 SpiderHostFrame x >> SpiderHostFrame y = SpiderHostFrame $ x >> y
2773 SpiderHostFrame x >> SpiderHostFrame y = SpiderHostFrame $ x >> y
2873 {-# INLINABLE return #-}
2774 {-# INLINABLE return #-}
2874 return x = SpiderHostFrame $ return x
2775 return x = SpiderHostFrame $ return x
2875−#if !MIN_VERSION_base(4,13,0)
2876 {-# INLINABLE fail #-}
2776 {-# INLINABLE fail #-}
2877 fail s = SpiderHostFrame $ fail s
2777 fail s = SpiderHostFrame $ fail s
2880instance NotReady (SpiderTimeline x) (SpiderHostFrame x) where
2779instance NotReady (SpiderTimeline x) (SpiderHostFrame x) where
2881 notReadyUntil _ = pure ()
2780 notReadyUntil _ = pure ()
@@ -2920,11 +2819,3 @@ instance MonadAtomicRef (SpiderHostFrame x) where
2920instance PrimMonad (SpiderHostFrame x) where
2819instance PrimMonad (SpiderHostFrame x) where
2921 type PrimState (SpiderHostFrame x) = PrimState IO
2820 type PrimState (SpiderHostFrame x) = PrimState IO
2922 primitive = SpiderHostFrame . EventM . primitive
2821 primitive = SpiderHostFrame . EventM . primitive
2924−instance NotReady (SpiderTimeline x) (SpiderHost x) where
2925− notReadyUntil _ = return ()
2926− notReady = return ()
2928−instance HasSpiderTimeline x => NotReady (SpiderTimeline x) (PerformEventT (SpiderTimeline x) (SpiderHost x)) where
2929− notReadyUntil _ = return ()
2930− notReady = return ()