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 May 7, 2024
1 parent 904551e commit 6bc33c5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion rhine/src/Data/Automaton.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ImportQualifiedPost #-}
Expand Down Expand Up @@ -258,7 +259,7 @@ stepAutomaton (Automaton automatonT) a =
{-# INLINE stepAutomaton #-}

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

-- FIXME rename to mapAutomaton? if yes change in document
Expand Down
6 changes: 3 additions & 3 deletions rhine/src/Data/Stream/Optimized.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE RankNTypes #-}
Expand Down Expand Up @@ -160,8 +161,8 @@ handleOptimized f stream = Stateful $ f $ toStreamT stream
See 'Data.Stream.reactimate'.
-}
reactimate :: (Monad m) => OptimizedStreamT m () -> m void
reactimate (Stateful stream) = StreamT.reactimate stream
reactimate (Stateless f) = go
reactimate (Stateful !stream) = StreamT.reactimate stream
reactimate (Stateless !f) = go
where
go = f *> go
{-# INLINE reactimate #-}
Expand All @@ -173,7 +174,6 @@ since the optimized version doesn't create a state type.
-}
constM :: m a -> OptimizedStreamT m a
constM = Stateless
{-# INLINE constM #-}

-- | Perform one step of a stream, resulting in an updated stream and an output value.
stepOptimizedStream :: (Functor m) => OptimizedStreamT m a -> m (Result (OptimizedStreamT m a) a)
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,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE GADTs #-}

{- |
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 6bc33c5

Please sign in to comment.