{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Test.Control.State.Transition.Trace (
SigState (..),
(.-),
(.->),
(.->>),
checkTrace,
Trace (..),
TraceOrder (NewestFirst, OldestFirst),
mkTrace,
traceEnv,
traceInitState,
traceSignals,
traceStates,
preStatesAndSignals,
SourceSignalTarget (..),
sourceSignalTargets,
traceLength,
traceInit,
lastState,
lastSignal,
firstAndLastState,
closure,
extractValues,
applySTSTest,
getEvents,
splitTrace,
)
where
import Control.DeepSeq (NFData)
import Control.Monad (void)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Reader (MonadReader, ReaderT, ask, runReaderT)
import Control.State.Transition.Extended hiding (Assertion, trans)
import Data.Data (Data, Typeable, cast, gmapQ)
import Data.Foldable (toList)
import Data.List.NonEmpty (NonEmpty)
import Data.Maybe (catMaybes)
import Data.Sequence.Strict (StrictSeq (Empty, (:<|), (:|>)))
import qualified Data.Sequence.Strict as SS
import qualified Data.Sequence.Strict as StrictSeq
import GHC.Generics (Generic)
import GHC.Stack (HasCallStack)
import Lens.Micro (Lens', lens, to, (^.), (^..))
import Lens.Micro.TH (makeLenses)
import NoThunks.Class (NoThunks (..))
import Test.Cardano.Ledger.Binary.TreeDiff (ToExpr, assertExprEqualWithMessage)
import Test.Tasty.HUnit (assertFailure, (@?=))
data SigState s = SigState !(State s) !(Signal s)
deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s x. Rep (SigState s) x -> SigState s
forall s x. SigState s -> Rep (SigState s) x
$cto :: forall s x. Rep (SigState s) x -> SigState s
$cfrom :: forall s x. SigState s -> Rep (SigState s) x
Generic)
transSt :: Lens' (SigState s) (State s)
transSt :: forall s. Lens' (SigState s) (State s)
transSt = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\(SigState State s
st Signal s
_) -> State s
st) (\(SigState State s
_ Signal s
x) State s
st -> forall s. State s -> Signal s -> SigState s
SigState State s
st Signal s
x)
transSig :: Lens' (SigState s) (Signal s)
transSig :: forall s. Lens' (SigState s) (Signal s)
transSig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\(SigState State s
_ Signal s
sig) -> Signal s
sig) (\(SigState State s
x Signal s
_) Signal s
sig -> forall s. State s -> Signal s -> SigState s
SigState State s
x Signal s
sig)
deriving instance
(Eq (State s), Eq (Signal s)) => (Eq (SigState s))
deriving instance
(Show (State s), Show (Signal s)) => (Show (SigState s))
instance
( NoThunks (State s)
, NoThunks (Signal s)
) =>
(NoThunks (SigState s))
data Trace s = Trace
{ forall s. Trace s -> Environment s
_traceEnv :: !(Environment s)
, forall s. Trace s -> State s
_traceInitState :: !(State s)
, forall s. Trace s -> StrictSeq (SigState s)
_traceTrans :: !(StrictSeq (SigState s))
}
deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s x. Rep (Trace s) x -> Trace s
forall s x. Trace s -> Rep (Trace s) x
$cto :: forall s x. Rep (Trace s) x -> Trace s
$cfrom :: forall s x. Trace s -> Rep (Trace s) x
Generic)
makeLenses ''Trace
deriving instance
( NFData (Environment s)
, NFData (State s)
, NFData (SigState s)
) =>
(NFData (Trace s))
deriving instance
(Eq (State s), Eq (Signal s), Eq (Environment s)) => (Eq (Trace s))
deriving instance
(Show (State s), Show (Signal s), Show (Environment s)) => (Show (Trace s))
instance
( NoThunks (Environment s)
, NoThunks (State s)
, NoThunks (Signal s)
) =>
(NoThunks (Trace s))
mkTrace :: Environment s -> State s -> [(State s, Signal s)] -> Trace s
mkTrace :: forall s.
Environment s -> State s -> [(State s, Signal s)] -> Trace s
mkTrace Environment s
env State s
initState [(State s, Signal s)]
sigs = forall s.
Environment s -> State s -> StrictSeq (SigState s) -> Trace s
Trace Environment s
env State s
initState StrictSeq (SigState s)
sigs'
where
sigs' :: StrictSeq (SigState s)
sigs' = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall s. State s -> Signal s -> SigState s
SigState forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. [a] -> StrictSeq a
StrictSeq.fromList [(State s, Signal s)]
sigs
lastState :: Trace s -> State s
lastState :: forall s. Trace s -> State s
lastState Trace {State s
_traceInitState :: State s
_traceInitState :: forall s. Trace s -> State s
_traceInitState, StrictSeq (SigState s)
_traceTrans :: StrictSeq (SigState s)
_traceTrans :: forall s. Trace s -> StrictSeq (SigState s)
_traceTrans} =
case StrictSeq (SigState s)
_traceTrans of
SigState State s
st Signal s
_ :<| StrictSeq (SigState s)
_ -> State s
st
StrictSeq (SigState s)
_ -> State s
_traceInitState
lastSignal :: HasCallStack => Trace s -> Signal s
lastSignal :: forall s. HasCallStack => Trace s -> Signal s
lastSignal Trace {StrictSeq (SigState s)
_traceTrans :: StrictSeq (SigState s)
_traceTrans :: forall s. Trace s -> StrictSeq (SigState s)
_traceTrans} =
case StrictSeq (SigState s)
_traceTrans of
StrictSeq (SigState s)
Empty -> forall a. HasCallStack => String -> a
error String
"lastSignal was called with a trace without signals"
SigState State s
_st Signal s
signal :<| StrictSeq (SigState s)
_ -> Signal s
signal
firstAndLastState :: Trace s -> (State s, State s)
firstAndLastState :: forall s. Trace s -> (State s, State s)
firstAndLastState Trace s
tr = (forall s. Trace s -> State s
_traceInitState Trace s
tr, forall s. Trace s -> State s
lastState Trace s
tr)
data TraceOrder = NewestFirst | OldestFirst deriving (TraceOrder -> TraceOrder -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TraceOrder -> TraceOrder -> Bool
$c/= :: TraceOrder -> TraceOrder -> Bool
== :: TraceOrder -> TraceOrder -> Bool
$c== :: TraceOrder -> TraceOrder -> Bool
Eq)
fromNewestFirst :: TraceOrder -> [a] -> [a]
fromNewestFirst :: forall a. TraceOrder -> [a] -> [a]
fromNewestFirst TraceOrder
NewestFirst = forall a. a -> a
id
fromNewestFirst TraceOrder
OldestFirst = forall a. [a] -> [a]
reverse
traceSignals :: TraceOrder -> Trace s -> [Signal s]
traceSignals :: forall s. TraceOrder -> Trace s -> [Signal s]
traceSignals TraceOrder
order Trace s
tr = forall a. TraceOrder -> [a] -> [a]
fromNewestFirst TraceOrder
order (Trace s
tr forall s a. s -> Getting (Endo [a]) s a -> [a]
^.. forall s. Lens' (Trace s) (StrictSeq (SigState s))
traceTrans forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Lens' (SigState s) (Signal s)
transSig)
traceStates :: TraceOrder -> Trace s -> [State s]
traceStates :: forall s. TraceOrder -> Trace s -> [State s]
traceStates TraceOrder
order Trace s
tr = forall a. TraceOrder -> [a] -> [a]
fromNewestFirst TraceOrder
order ([State s]
xs forall a. [a] -> [a] -> [a]
++ [State s
x])
where
x :: State s
x = Trace s
tr forall s a. s -> Getting a s a -> a
^. forall s. Lens' (Trace s) (State s)
traceInitState
xs :: [State s]
xs = Trace s
tr forall s a. s -> Getting (Endo [a]) s a -> [a]
^.. forall s. Lens' (Trace s) (StrictSeq (SigState s))
traceTrans forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Lens' (SigState s) (State s)
transSt
traceLength :: Trace s -> Int
traceLength :: forall s. Trace s -> Int
traceLength Trace s
tr = Trace s
tr forall s a. s -> Getting a s a -> a
^. forall s. Lens' (Trace s) (StrictSeq (SigState s))
traceTrans forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. (s -> a) -> SimpleGetter s a
to forall (t :: * -> *) a. Foldable t => t a -> Int
length
traceInit :: HasCallStack => Trace s -> Trace s
traceInit :: forall s. HasCallStack => Trace s -> Trace s
traceInit tr :: Trace s
tr@Trace {StrictSeq (SigState s)
_traceTrans :: StrictSeq (SigState s)
_traceTrans :: forall s. Trace s -> StrictSeq (SigState s)
_traceTrans} =
case StrictSeq (SigState s)
_traceTrans of
StrictSeq (SigState s)
Empty -> forall a. HasCallStack => String -> a
error String
"traceInit was called with a trace without signals"
SigState s
_ :<| StrictSeq (SigState s)
trans -> Trace s
tr {_traceTrans :: StrictSeq (SigState s)
_traceTrans = StrictSeq (SigState s)
trans}
preStatesAndSignals :: TraceOrder -> Trace s -> [(State s, Signal s)]
preStatesAndSignals :: forall s. TraceOrder -> Trace s -> [(State s, Signal s)]
preStatesAndSignals TraceOrder
OldestFirst Trace s
tr =
forall a b. [a] -> [b] -> [(a, b)]
zip (forall s. TraceOrder -> Trace s -> [State s]
traceStates TraceOrder
OldestFirst Trace s
tr) (forall s. TraceOrder -> Trace s -> [Signal s]
traceSignals TraceOrder
OldestFirst Trace s
tr)
preStatesAndSignals TraceOrder
NewestFirst Trace s
tr =
forall a. [a] -> [a]
reverse forall a b. (a -> b) -> a -> b
$ forall s. TraceOrder -> Trace s -> [(State s, Signal s)]
preStatesAndSignals TraceOrder
OldestFirst Trace s
tr
closure ::
forall s m.
(STS s, m ~ BaseM s) =>
Environment s ->
State s ->
[Signal s] ->
m (Trace s)
closure :: forall s (m :: * -> *).
(STS s, m ~ BaseM s) =>
Environment s -> State s -> [Signal s] -> m (Trace s)
closure Environment s
env State s
st0 [Signal s]
sigs = forall s.
Environment s -> State s -> [(State s, Signal s)] -> Trace s
mkTrace Environment s
env State s
st0 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> State s
-> [Signal s] -> [(State s, Signal s)] -> m [(State s, Signal s)]
loop State s
st0 (forall a. [a] -> [a]
reverse [Signal s]
sigs) []
where
loop :: State s
-> [Signal s] -> [(State s, Signal s)] -> m [(State s, Signal s)]
loop State s
_ [] [(State s, Signal s)]
acc = forall (f :: * -> *) a. Applicative f => a -> f a
pure [(State s, Signal s)]
acc
loop State s
sti (Signal s
sig : [Signal s]
sigs') [(State s, Signal s)]
acc =
forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s
-> m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSTest @s (forall sts. (Environment sts, State sts, Signal sts) -> TRC sts
TRC (Environment s
env, State s
sti, Signal s
sig)) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left NonEmpty (PredicateFailure s)
_ -> State s
-> [Signal s] -> [(State s, Signal s)] -> m [(State s, Signal s)]
loop State s
sti [Signal s]
sigs' [(State s, Signal s)]
acc
Right State s
sti' -> State s
-> [Signal s] -> [(State s, Signal s)] -> m [(State s, Signal s)]
loop State s
sti' [Signal s]
sigs' ((State s
sti', Signal s
sig) forall a. a -> [a] -> [a]
: [(State s, Signal s)]
acc)
(.-) ::
forall m st sig err.
( MonadIO m
, MonadReader (st -> sig -> Either err st) m
, Show err
, HasCallStack
) =>
m st ->
sig ->
m st
m st
mSt .- :: forall (m :: * -> *) st sig err.
(MonadIO m, MonadReader (st -> sig -> Either err st) m, Show err,
HasCallStack) =>
m st -> sig -> m st
.- sig
sig = do
st
st <- m st
mSt
st -> sig -> Either err st
validation <- forall r (m :: * -> *). MonadReader r m => m r
ask
case st -> sig -> Either err st
validation st
st sig
sig of
Left err
pfs -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasCallStack => String -> IO a
assertFailure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ err
pfs
Right st
st' -> forall (f :: * -> *) a. Applicative f => a -> f a
pure st
st'
(.->>) ::
forall m st.
(MonadIO m, Eq st, ToExpr st, HasCallStack) =>
m st ->
st ->
m st
m st
mSt .->> :: forall (m :: * -> *) st.
(MonadIO m, Eq st, ToExpr st, HasCallStack) =>
m st -> st -> m st
.->> st
stExpected = do
st
stActual <- m st
mSt
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a.
(ToExpr a, Eq a, HasCallStack) =>
String -> a -> a -> Assertion
assertExprEqualWithMessage String
"Check trace with (.->>) fails" st
stExpected st
stActual
forall (m :: * -> *) a. Monad m => a -> m a
return st
stActual
(.->) ::
forall m st.
(MonadIO m, Eq st, Show st, HasCallStack) =>
m st ->
st ->
m st
m st
mSt .-> :: forall (m :: * -> *) st.
(MonadIO m, Eq st, Show st, HasCallStack) =>
m st -> st -> m st
.-> st
stExpected = do
st
stActual <- m st
mSt
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ st
stActual forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= st
stExpected
forall (m :: * -> *) a. Monad m => a -> m a
return st
stActual
checkTrace ::
forall s m.
(STS s, BaseM s ~ m) =>
(forall a. m a -> a) ->
Environment s ->
ReaderT
( State s ->
Signal s ->
Either (NonEmpty (PredicateFailure s)) (State s)
)
IO
(State s) ->
IO ()
checkTrace :: forall s (m :: * -> *).
(STS s, BaseM s ~ m) =>
(forall a. m a -> a)
-> Environment s
-> ReaderT
(State s
-> Signal s -> Either (NonEmpty (PredicateFailure s)) (State s))
IO
(State s)
-> Assertion
checkTrace forall a. m a -> a
interp Environment s
env ReaderT
(State s
-> Signal s -> Either (NonEmpty (PredicateFailure s)) (State s))
IO
(State s)
act =
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT
(State s
-> Signal s -> Either (NonEmpty (PredicateFailure s)) (State s))
IO
(State s)
act (\State s
st Signal s
sig -> forall a. m a -> a
interp forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s
-> m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSTest @s (forall sts. (Environment sts, State sts, Signal sts) -> TRC sts
TRC (Environment s
env, State s
st, Signal s
sig)))
extractValues :: forall d a. (Data d, Typeable a) => d -> [a]
d
d =
forall a. [Maybe a] -> [a]
catMaybes (forall a u. Data a => (forall d. Data d => d -> u) -> a -> [u]
gmapQ forall d1. Data d1 => d1 -> Maybe a
extractValue d
d)
forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (forall a u. Data a => (forall d. Data d => d -> u) -> a -> [u]
gmapQ forall d a. (Data d, Typeable a) => d -> [a]
extractValues d
d)
where
extractValue :: forall d1. Data d1 => d1 -> Maybe a
extractValue :: forall d1. Data d1 => d1 -> Maybe a
extractValue d1
d1 = forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast d1
d1
data SourceSignalTarget a = SourceSignalTarget
{ forall a. SourceSignalTarget a -> State a
source :: State a
, forall a. SourceSignalTarget a -> State a
target :: State a
, forall a. SourceSignalTarget a -> Signal a
signal :: Signal a
}
deriving instance (Eq (State a), Eq (Signal a)) => Eq (SourceSignalTarget a)
deriving instance (Show (State a), Show (Signal a)) => Show (SourceSignalTarget a)
sourceSignalTargets :: forall a. Trace a -> [SourceSignalTarget a]
sourceSignalTargets :: forall a. Trace a -> [SourceSignalTarget a]
sourceSignalTargets Trace a
trace = forall a b c d. (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3 forall a. State a -> State a -> Signal a -> SourceSignalTarget a
SourceSignalTarget [State a]
states [State a]
statesTail [Signal a]
signals
where
signals :: [Signal a]
signals = forall s. TraceOrder -> Trace s -> [Signal s]
traceSignals TraceOrder
OldestFirst Trace a
trace
states :: [State a]
states = forall s. TraceOrder -> Trace s -> [State s]
traceStates TraceOrder
OldestFirst Trace a
trace
statesTail :: [State a]
statesTail =
case [State a]
states of
[] -> forall a. HasCallStack => String -> a
error String
"Control.State.Transition.Trace.sourceSignalTargets: Unexpected empty list"
(State a
_ : [State a]
xs) -> [State a]
xs
applySTSTest ::
forall s m rtype.
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s ->
m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSTest :: forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s
-> m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSTest = forall s (m :: * -> *) (rtype :: RuleType) (ep :: EventPolicy).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
ApplySTSOpts ep
-> RuleContext rtype s
-> m (Either
(NonEmpty (PredicateFailure s)) (EventReturnType ep s (State s)))
applySTSOptsEither ApplySTSOpts 'EventPolicyDiscard
defaultOpts
where
defaultOpts :: ApplySTSOpts 'EventPolicyDiscard
defaultOpts =
ApplySTSOpts
{ asoAssertions :: AssertionPolicy
asoAssertions = AssertionPolicy
AssertionsAll
, asoValidation :: ValidationPolicy
asoValidation = ValidationPolicy
ValidateAll
, asoEvents :: SingEP 'EventPolicyDiscard
asoEvents = SingEP 'EventPolicyDiscard
EPDiscard
}
getEvents :: forall sts. STS sts => Trace sts -> BaseM sts [[Event sts]]
getEvents :: forall sts. STS sts => Trace sts -> BaseM sts [[Event sts]]
getEvents (Trace Environment sts
env State sts
s0 StrictSeq (SigState sts)
pairs) = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Environment sts, State sts, Signal sts) -> BaseM sts [Event sts]
action (forall a b. (a -> b) -> [a] -> [b]
map (State sts, Signal sts) -> (Environment sts, State sts, Signal sts)
make [(State sts, Signal sts)]
pairs2)
where
pairs2 :: [(State sts, Signal sts)]
pairs2 = forall s. State s -> [SigState s] -> [(State s, Signal s)]
unstagger State sts
s0 (forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (SigState sts)
pairs)
make :: (State sts, Signal sts) -> (Environment sts, State sts, Signal sts)
make (State sts
state, Signal sts
sig) = (Environment sts
env, State sts
state, Signal sts
sig)
defaultOpts :: ApplySTSOpts 'EventPolicyReturn
defaultOpts =
ApplySTSOpts
{ asoAssertions :: AssertionPolicy
asoAssertions = AssertionPolicy
AssertionsOff
, asoValidation :: ValidationPolicy
asoValidation = ValidationPolicy
ValidateNone
, asoEvents :: SingEP 'EventPolicyReturn
asoEvents = SingEP 'EventPolicyReturn
EPReturn
}
action :: (Environment sts, State sts, Signal sts) -> BaseM sts [Event sts]
action :: (Environment sts, State sts, Signal sts) -> BaseM sts [Event sts]
action (Environment sts, State sts, Signal sts)
x = do
Either (NonEmpty (PredicateFailure sts)) (State sts, [Event sts])
item <- forall s (m :: * -> *) (rtype :: RuleType) (ep :: EventPolicy).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
ApplySTSOpts ep
-> RuleContext rtype s
-> m (Either
(NonEmpty (PredicateFailure s)) (EventReturnType ep s (State s)))
applySTSOptsEither @sts @(BaseM sts) @'Transition ApplySTSOpts 'EventPolicyReturn
defaultOpts (forall sts. (Environment sts, State sts, Signal sts) -> TRC sts
TRC (Environment sts, State sts, Signal sts)
x)
case Either (NonEmpty (PredicateFailure sts)) (State sts, [Event sts])
item of
Left NonEmpty (PredicateFailure sts)
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure []
Right (State sts
_, [Event sts]
events) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. [a] -> [a]
reverse [Event sts]
events)
unstagger :: State s -> [SigState s] -> [(State s, Signal s)]
unstagger :: forall s. State s -> [SigState s] -> [(State s, Signal s)]
unstagger State s
_ [] = []
unstagger State s
s1 [(SigState State s
_s2 Signal s
d1)] = [(State s
s1, Signal s
d1)]
unstagger State s
s1 ((SigState State s
_s4 Signal s
d3) : (more :: [SigState s]
more@((SigState State s
s3 Signal s
_d2) : [SigState s]
_))) = (State s
s3, Signal s
d3) forall a. a -> [a] -> [a]
: forall s. State s -> [SigState s] -> [(State s, Signal s)]
unstagger State s
s1 [SigState s]
more
splitAtChange ::
(State s -> State s -> Bool) ->
StrictSeq (SigState s) ->
State s ->
StrictSeq (SigState s) ->
[(StrictSeq (SigState s), State s)] ->
[(StrictSeq (SigState s), State s)]
splitAtChange :: forall s.
(State s -> State s -> Bool)
-> StrictSeq (SigState s)
-> State s
-> StrictSeq (SigState s)
-> [(StrictSeq (SigState s), State s)]
-> [(StrictSeq (SigState s), State s)]
splitAtChange State s -> State s -> Bool
_p StrictSeq (SigState s)
SS.Empty State s
a0 StrictSeq (SigState s)
ans1 [(StrictSeq (SigState s), State s)]
ans2 = (StrictSeq (SigState s)
ans1, State s
a0) forall a. a -> [a] -> [a]
: [(StrictSeq (SigState s), State s)]
ans2
splitAtChange State s -> State s -> Bool
p (xs :: StrictSeq (SigState s)
xs@(StrictSeq (SigState s)
_ :|> SigState s
x1) :|> SigState s
x0) State s
a0 StrictSeq (SigState s)
ans1 [(StrictSeq (SigState s), State s)]
ans2 =
if State s -> State s -> Bool
p State s
s1 State s
s0
then forall s.
(State s -> State s -> Bool)
-> StrictSeq (SigState s)
-> State s
-> StrictSeq (SigState s)
-> [(StrictSeq (SigState s), State s)]
-> [(StrictSeq (SigState s), State s)]
splitAtChange State s -> State s -> Bool
p StrictSeq (SigState s)
xs State s
a0 (SigState s
x0 forall a. a -> StrictSeq a -> StrictSeq a
:<| StrictSeq (SigState s)
ans1) [(StrictSeq (SigState s), State s)]
ans2
else forall s.
(State s -> State s -> Bool)
-> StrictSeq (SigState s)
-> State s
-> StrictSeq (SigState s)
-> [(StrictSeq (SigState s), State s)]
-> [(StrictSeq (SigState s), State s)]
splitAtChange State s -> State s -> Bool
p StrictSeq (SigState s)
xs State s
s0 forall a. StrictSeq a
SS.Empty ((SigState s
x1 forall a. a -> StrictSeq a -> StrictSeq a
:<| (SigState s
x0 forall a. a -> StrictSeq a -> StrictSeq a
:<| StrictSeq (SigState s)
ans1), State s
a0) forall a. a -> [a] -> [a]
: [(StrictSeq (SigState s), State s)]
ans2)
where
(SigState State s
s1 Signal s
_) = SigState s
x1
(SigState State s
s0 Signal s
_) = SigState s
x0
splitAtChange State s -> State s -> Bool
_p (StrictSeq (SigState s)
SS.Empty :|> SigState s
x1) State s
a0 StrictSeq (SigState s)
ans1 [(StrictSeq (SigState s), State s)]
ans2 = (((SigState s
x1 forall a. a -> StrictSeq a -> StrictSeq a
:<| StrictSeq (SigState s)
ans1), State s
a0) forall a. a -> [a] -> [a]
: [(StrictSeq (SigState s), State s)]
ans2)
splitTrace :: (State s -> State s -> Bool) -> Trace s -> [Trace s]
splitTrace :: forall s. (State s -> State s -> Bool) -> Trace s -> [Trace s]
splitTrace State s -> State s -> Bool
p (Trace Environment s
env State s
s0 StrictSeq (SigState s)
sigstates) = forall a b. (a -> b) -> [a] -> [b]
map (StrictSeq (SigState s), State s) -> Trace s
f [(StrictSeq (SigState s), State s)]
xs
where
f :: (StrictSeq (SigState s), State s) -> Trace s
f (StrictSeq (SigState s)
sigstates2, State s
s) = forall s.
Environment s -> State s -> StrictSeq (SigState s) -> Trace s
Trace Environment s
env State s
s StrictSeq (SigState s)
sigstates2
xs :: [(StrictSeq (SigState s), State s)]
xs = forall s.
(State s -> State s -> Bool)
-> StrictSeq (SigState s)
-> State s
-> StrictSeq (SigState s)
-> [(StrictSeq (SigState s), State s)]
-> [(StrictSeq (SigState s), State s)]
splitAtChange State s -> State s -> Bool
p StrictSeq (SigState s)
sigstates State s
s0 forall a. StrictSeq a
Empty []