@@ -53,8 +53,6 @@ import Data.List hiding (foldl')
53import Data.Maybe
53import Data.Maybe
54import Data.Monoid ((<>))
54import Data.Monoid ((<>))
55import Data.Proxy
55import Data.Proxy
56−import Data.Some (Some)
57−import qualified Data.Some as Some
58import Data.These
56import Data.These
59import Data.Traversable
57import Data.Traversable
60import Data.Word
58import Data.Word
@@ -77,6 +75,9 @@ import Data.Tree (Forest, Tree (..), drawForest)
77import Data.WeakBag (WeakBag, WeakBagTicket)
75import Data.WeakBag (WeakBag, WeakBagTicket)
78import qualified Data.WeakBag as WeakBag
76import qualified Data.WeakBag as WeakBag
79#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
77#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
78+import Data.Reflection
79+import Data.Some (Some)
80+import qualified Data.Some as Some
80import Data.Type.Coercion
81import Data.Type.Coercion
81import qualified Reflex.Class
82import qualified Reflex.Class
82import qualified Reflex.Class as R
83import qualified Reflex.Class as R
@@ -1870,13 +1871,29 @@ unsafeNewSpiderTimelineEnv = do
1874+#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
1873-- | Create a new SpiderTimelineEnv
1875-- | Create a new SpiderTimelineEnv
1874newSpiderTimeline :: IO (Some SpiderTimelineEnv)
1876newSpiderTimeline :: IO (Some SpiderTimelineEnv)
1875newSpiderTimeline = withSpiderTimeline (pure . Some.This)
1877newSpiderTimeline = withSpiderTimeline (pure . Some.This)
1879+data LocalSpiderTimeline x s
1881+instance Reifies s (SpiderTimelineEnv x) =>
1882+ HasSpiderTimeline (LocalSpiderTimeline x s) where
1883+ spiderTimeline = localSpiderTimeline (Proxy :: Proxy s) $ reflect (Proxy :: Proxy s)
1887+ -> SpiderTimelineEnv x
1888+ -> SpiderTimelineEnv (LocalSpiderTimeline x s)
1889+localSpiderTimeline _ = unsafeCoerce
1877-- | Pass a new timeline to the given function.
1891-- | Pass a new timeline to the given function.
1878−withSpiderTimeline :: (forall x. SpiderTimelineEnv x -> IO r) -> IO r
1892+withSpiderTimeline :: (forall x. HasSpiderTimeline x => SpiderTimelineEnv x -> IO r) -> IO r
1893+withSpiderTimeline k = do
1879−withSpiderTimeline k = unsafeNewSpiderTimelineEnv >>= k
1894+ env <- unsafeNewSpiderTimelineEnv
1895+ reify env $ \s -> k $ localSpiderTimeline s env
1881newtype SpiderPullM x a = SpiderPullM (BehaviorM x a) deriving (Functor, Applicative, Monad, MonadIO, MonadFix)
1898newtype SpiderPullM x a = SpiderPullM (BehaviorM x a) deriving (Functor, Applicative, Monad, MonadIO, MonadFix)
@@ -1968,10 +1985,12 @@ instance Monad (SpiderHost x) where
1968runSpiderHost :: SpiderHost Global a -> IO a
1985runSpiderHost :: SpiderHost Global a -> IO a
1969runSpiderHost (SpiderHost a) = runReaderT a globalSpiderTimelineEnv
1986runSpiderHost (SpiderHost a) = runReaderT a globalSpiderTimelineEnv
1988+#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
1971-- | Run an action affecting a given Spider timeline; this will be guarded by a
1989-- | Run an action affecting a given Spider timeline; this will be guarded by a
1972-- mutex for that timeline
1990-- mutex for that timeline
1973runSpiderHostForTimeline :: SpiderHost x a -> SpiderTimelineEnv x -> IO a
1991runSpiderHostForTimeline :: SpiderHost x a -> SpiderTimelineEnv x -> IO a
1974runSpiderHostForTimeline (SpiderHost a) = runReaderT a
1992runSpiderHostForTimeline (SpiderHost a) = runReaderT a
1976newtype SpiderHostFrame x a = SpiderHostFrame { runSpiderHostFrame :: EventM x a } deriving (Functor, Applicative, MonadFix, MonadIO, MonadException, MonadAsyncException)
1995newtype SpiderHostFrame x a = SpiderHostFrame { runSpiderHostFrame :: EventM x a } deriving (Functor, Applicative, MonadFix, MonadIO, MonadException, MonadAsyncException)