@@ -53,8 +53,6 @@ import Data.List hiding (foldl')
5353import Data.Maybe
5454import Data.Monoid ((<>))
5555import Data.Proxy
56−import Data.Some (Some)
57−import qualified Data.Some as Some
5856import Data.These
5957import Data.Traversable
6058import Data.Word
@@ -77,6 +75,9 @@ import Data.Tree (Forest, Tree (..), drawForest)
7775import Data.WeakBag (WeakBag, WeakBagTicket)
7876import qualified Data.WeakBag as WeakBag
7977#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
78+import Data.Reflection
79+import Data.Some (Some)
80+import qualified Data.Some as Some
8081import Data.Type.Coercion
8182import qualified Reflex.Class
8283import qualified Reflex.Class as R
@@ -1870,13 +1871,29 @@ unsafeNewSpiderTimelineEnv = do
18701871#endif
18711872 }
18721873
1874+#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
18731875-- | Create a new SpiderTimelineEnv
18741876newSpiderTimeline :: IO (Some SpiderTimelineEnv)
18751877newSpiderTimeline = withSpiderTimeline (pure . Some.This)
18761878
1879+data LocalSpiderTimeline x s
1880+
1881+instance Reifies s (SpiderTimelineEnv x) =>
1882+ HasSpiderTimeline (LocalSpiderTimeline x s) where
1883+ spiderTimeline = localSpiderTimeline (Proxy :: Proxy s) $ reflect (Proxy :: Proxy s)
1884+
1885+localSpiderTimeline
1886+ :: Proxy s
1887+ -> SpiderTimelineEnv x
1888+ -> SpiderTimelineEnv (LocalSpiderTimeline x s)
1889+localSpiderTimeline _ = unsafeCoerce
1890+
18771891-- | Pass a new timeline to the given function.
1878−withSpiderTimeline :: (forall x. SpiderTimelineEnv x -> IO r) -> IO r
1879−withSpiderTimeline k = unsafeNewSpiderTimelineEnv >>= k
1892+withSpiderTimeline :: (forall x. HasSpiderTimeline x => SpiderTimelineEnv x -> IO r) -> IO r
1893+withSpiderTimeline k = do
1894+ env <- unsafeNewSpiderTimelineEnv
1895+ reify env $ \s -> k $ localSpiderTimeline s env
1896+#endif
18801897
18811898newtype SpiderPullM x a = SpiderPullM (BehaviorM x a) deriving (Functor, Applicative, Monad, MonadIO, MonadFix)
18821899
@@ -1968,10 +1985,12 @@ instance Monad (SpiderHost x) where
19681985runSpiderHost :: SpiderHost Global a -> IO a
19691986runSpiderHost (SpiderHost a) = runReaderT a globalSpiderTimelineEnv
19701987
1988+#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
19711989-- | Run an action affecting a given Spider timeline; this will be guarded by a
19721990-- mutex for that timeline
19731991runSpiderHostForTimeline :: SpiderHost x a -> SpiderTimelineEnv x -> IO a
19741992runSpiderHostForTimeline (SpiderHost a) = runReaderT a
1993+#endif
19751994
19761995newtype SpiderHostFrame x a = SpiderHostFrame { runSpiderHostFrame :: EventM x a } deriving (Functor, Applicative, MonadFix, MonadIO, MonadException, MonadAsyncException)
19771996