Skip to content

Commit

Permalink
Inline initClock everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Bärenz authored and turion committed Nov 29, 2024
1 parent 9ef48f9 commit 11fabe5
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rhine-gloss/src/FRP/Rhine/Gloss/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ instance (MonadIO m) => Clock (GlossConcT m) GlossEventClockIO where
liftIO $ do
time <- readIORef timeRef
return (time, event)
{-# INLINE initClock #-}

instance GetClockProxy GlossEventClockIO

Expand All @@ -153,6 +154,7 @@ instance (MonadIO m) => Clock (GlossConcT m) GlossSimClockIO where
getTime = GlossConcT $ do
GlossEnv {timeVar} <- ask
lift $ asyncMVar timeVar
{-# INLINE initClock #-}

instance GetClockProxy GlossSimClockIO

Expand Down
1 change: 1 addition & 0 deletions rhine-gloss/src/FRP/Rhine/Gloss/Pure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ instance Clock GlossM GlossClock where
type Time GlossClock = Float
type Tag GlossClock = Maybe Event
initClock _ = return (constM (GlossM $ yield >> lift ask) >>> (sumS *** Category.id), 0)
{-# INLINE initClock #-}

instance GetClockProxy GlossClock

Expand Down
1 change: 1 addition & 0 deletions rhine-terminal/src/FRP/Rhine/Terminal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ instance (MonadInput m, MonadIO m) => Clock m TerminalEventClock where
return (time, event)
, initialTime
)
{-# INLINE initClock #-}

instance GetClockProxy TerminalEventClock

Expand Down
4 changes: 4 additions & 0 deletions rhine/src/FRP/Rhine/Clock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ instance
( runningClock >>> first (arr f)
, f initTime
)
{-# INLINE initClock #-}

{- | Instead of a mere function as morphism of time domains,
we can transform one time domain into the other with an effectful morphism.
Expand All @@ -172,6 +173,7 @@ instance
( runningClock >>> first (arrM rescaleM)
, rescaledInitTime
)
{-# INLINE initClock #-}

-- | A 'RescaledClock' is trivially a 'RescaledClockM'.
rescaledClockToM :: (Monad m) => RescaledClock cl time -> RescaledClockM m cl time
Expand Down Expand Up @@ -205,6 +207,7 @@ instance
( runningClock >>> rescaling
, rescaledInitTime
)
{-# INLINE initClock #-}

-- | A 'RescaledClockM' is trivially a 'RescaledClockS'.
rescaledClockMToS ::
Expand Down Expand Up @@ -242,6 +245,7 @@ instance
( hoistS monadMorphism runningClock
, initialTime
)
{-# INLINE initClock #-}

-- | Lift a clock type into a monad transformer.
type LiftClock m t cl = HoistClock m (t m) cl
Expand Down
3 changes: 3 additions & 0 deletions rhine/src/FRP/Rhine/Clock/Except.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ instance (Exception e, Clock IO cl, MonadIO eio, MonadError e eio) => Clock eio
where
ioerror :: (MonadError e eio, MonadIO eio) => IO (Either e a) -> eio a
ioerror = liftEither <=< liftIO
{-# INLINE initClock #-}

instance GetClockProxy (ExceptClock cl e)

Expand Down Expand Up @@ -87,6 +88,7 @@ instance (Time cl1 ~ Time cl2, Clock (ExceptT e m) cl1, Clock m cl2, Monad m) =>
safe $ runningClock' >>> arr (second Left)
return (catchingClock, initTime)
Left e -> (fmap (first (>>> arr (second Left))) . initClock) $ handler e
{-# INLINE initClock #-}

instance (GetClockProxy (CatchClock cl1 e cl2))

Expand Down Expand Up @@ -142,6 +144,7 @@ instance (TimeDomain time, MonadError e m) => Clock m (Single m time tag e) wher
errorT :: (MonadError e m) => m (Either e a) -> m a
errorT = (>>= liftEither)
return (runningClock, initTime)
{-# INLINE initClock #-}

-- * 'DelayException'

Expand Down
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/FixedStep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ instance (MonadSchedule m, Monad m) => Clock (ScheduleT Integer m) (FixedStep n)
>>> arrM (\time -> wait step $> (time, ()))
, 0
)
{-# INLINE initClock #-}

instance GetClockProxy (FixedStep n)

Expand Down
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Periodic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ instance
( cycleS (theList cl) >>> withSideEffect wait >>> accumulateWith (+) 0 &&& arr (const ())
, 0
)
{-# INLINE initClock #-}

instance GetClockProxy (Periodic v)

Expand Down
2 changes: 2 additions & 0 deletions rhine/src/FRP/Rhine/Clock/Realtime/Audio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ instance
( runningClock initialTime Nothing
, initialTime
)
{-# INLINE initClock #-}

instance GetClockProxy (AudioClock rate bufferSize)

Expand Down Expand Up @@ -155,6 +156,7 @@ instance (Monad m, PureAudioClockRate rate) => Clock m (PureAudioClock rate) whe
( arr (const (1 / thePureRateNum audioClock)) >>> sumS &&& arr (const ())
, 0
)
{-# INLINE initClock #-}

instance GetClockProxy (PureAudioClock rate)

Expand Down
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Realtime/Busy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ instance (MonadIO m) => Clock m Busy where
&&& arr (const ())
, initialTime
)
{-# INLINE initClock #-}

instance GetClockProxy Busy
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Realtime/Event.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ instance (MonadIO m) => Clock (EventChanT event m) (EventClock event) where
return (time, event)
, initialTime
)
{-# INLINE initClock #-}

instance GetClockProxy (EventClock event)

Expand Down
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Realtime/Millisecond.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ instance Clock IO (Millisecond n) where
type Time (Millisecond n) = UTCTime
type Tag (Millisecond n) = Maybe Double
initClock (Millisecond cl) = initClock cl <&> first (>>> arr (second snd))
{-# INLINE initClock #-}

instance GetClockProxy (Millisecond n)

Expand Down
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Realtime/Never.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ instance (MonadIO m) => Clock m Never where
( constM (liftIO . forever . threadDelay $ 10 ^ 9)
, initialTime
)
{-# INLINE initClock #-}

instance GetClockProxy Never
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Realtime/Stdin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ instance (MonadIO m) => Clock m StdinClock where
return (time, line)
, initialTime
)
{-# INLINE initClock #-}

instance GetClockProxy StdinClock

Expand Down
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Select.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ instance (Monad m, Clock m cl) => Clock m (SelectClock cl a) where
(time, tag) <- runningClock -< ()
returnA -< (time,) <$> select tag
return (runningSelectClock, initialTime)
{-# INLINE initClock #-}

instance GetClockProxy (SelectClock cl a)

Expand Down
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Trivial.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ instance (Monad m) => Clock m Trivial where
type Time Trivial = ()
type Tag Trivial = ()
initClock _ = return (arr $ const ((), ()), ())
{-# INLINE initClock #-}

instance GetClockProxy Trivial
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Unschedule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ instance (TimeDomain (Time cl), Clock (ScheduleT (Diff (Time cl)) m) cl, Monad m
where
run :: ScheduleT (Diff (Time cl)) m a -> m a
run = runScheduleT scheduleWait
{-# INLINE initClock #-}
2 changes: 2 additions & 0 deletions rhine/src/FRP/Rhine/Schedule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ instance
type Tag (SequentialClock cl1 cl2) = Either (Tag cl1) (Tag cl2)
initClock SequentialClock {..} =
initSchedule sequentialCl1 sequentialCl2
{-# INLINE initClock #-}

-- ** Parallelly combined clocks

Expand All @@ -136,6 +137,7 @@ instance
type Tag (ParallelClock cl1 cl2) = Either (Tag cl1) (Tag cl2)
initClock ParallelClock {..} =
initSchedule parallelCl1 parallelCl2
{-# INLINE initClock #-}

-- * Navigating the clock tree

Expand Down
1 change: 1 addition & 0 deletions rhine/test/Clock/Except.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ instance (Monad m) => Clock (ExceptT () m) FailingClock where
type Time FailingClock = UTCTime
type Tag FailingClock = ()
initClock FailingClock = throwE ()
{-# INLINE initClock #-}

instance GetClockProxy FailingClock

Expand Down

0 comments on commit 11fabe5

Please sign in to comment.