Skip to content

Commit

Permalink
WIP Clock erasure should happen at compile time, but can't achieve it…
Browse files Browse the repository at this point in the history
… through strictness

* Maybe through simplifying initClock (#304)
* Looking at the Core it turns out that erased clock isn't completely simplified,
  and it's somehow obvious because it can't be inlined since it's recursive
* I was hoping that if the automaton is evaluated strictly enough, it would be reduced to WHNF before reactimation starts
  but it's unclear whether this would even be visible in Core
  • Loading branch information
turion committed Apr 19, 2024
1 parent 1927977 commit 09b273e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion rhine/src/Data/Automaton/MSF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}

Check warning on line 7 in rhine/src/Data/Automaton/MSF.hs

View workflow job for this annotation

GitHub Actions / Run hlint

Warning in module Data.Automaton.MSF: Unused LANGUAGE pragma ▫︎ Found: "{-# LANGUAGE StandaloneDeriving #-}"
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE BangPatterns #-}

module Data.Automaton.MSF where

Expand Down Expand Up @@ -244,7 +245,7 @@ stepMSF (MSF automatonT) a =
{-# INLINE stepMSF #-}

reactimate :: (Monad m) => MSF m () () -> m void
reactimate (MSF automaton) = AutomatonOptimized.reactimate $ hoist (`runReaderT` ()) automaton
reactimate (MSF !automaton) = AutomatonOptimized.reactimate $ hoist (`runReaderT` ()) automaton
{-# INLINE reactimate #-}

-- FIXME rename to mapMSF? if yes change in document
Expand Down
5 changes: 3 additions & 2 deletions rhine/src/Data/Automaton/Optimized.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE BangPatterns #-}

module Data.Automaton.Optimized where

Expand Down Expand Up @@ -112,8 +113,8 @@ handleS :: (Functor m) => (AutomatonT m a -> AutomatonT n b) -> OptimizedAutomat
handleS f automaton = Stateful $ f $ toAutomatonT automaton

reactimate :: (Monad m) => OptimizedAutomatonT m () -> m void
reactimate (Stateful automaton) = AutomatonT.reactimate automaton
reactimate (Stateless f) = go
reactimate (Stateful !automaton) = AutomatonT.reactimate automaton
reactimate (Stateless !f) = go
where
go = f *> go
{-# INLINE reactimate #-}
Expand Down
3 changes: 2 additions & 1 deletion rhine/src/FRP/Rhine/Reactimation.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE BangPatterns #-}

{- |
Run closed 'Rhine's (which are signal functions together with matching clocks)
Expand Down Expand Up @@ -55,7 +56,7 @@ flow ::
Rhine m cl () () ->
m void
flow rhine = do
msf <- eraseClock rhine
!msf <- eraseClock rhine
reactimate $ msf >>> arr (const ())
{-# INLINE flow #-}

Expand Down

0 comments on commit 09b273e

Please sign in to comment.