Safe Haskell | Safe |
---|---|
Language | GHC2021 |
LambdaUC.Syntax.Async.Eval.Internal
Synopsis
- fork_ :: forall st st' ach ach' bef bef' aft aft' a a'. ForkPremiseD bef bef' aft aft' a a' -> KnownLenD ach -> AsyncT ach bef aft a -> AsyncT ach' bef' aft' a' -> AsyncT (Concat ach ach') (ForkIndexOr bef bef') (ForkIndexOr aft aft') (ChooseRet aft aft' a a')
- swap_ :: KnownIndex bef => ListSplitD l p (f : l') -> ListSplitD l' p' (s : rest) -> AsyncT l bef aft a -> AsyncT (Concat p (s : Concat p' (f : rest))) bef aft a
- link_ :: KnownIndex bef => MayOnlyReturnAfterRecvD aft a -> ListSplitD l p ((x :> y) : l') -> ListSplitD l' p' ((y :> x) : rest) -> AsyncT l bef aft a -> AsyncT (Concat p (Concat p' rest)) bef aft a
- spawnOnDemand_ :: forall l r ports. ConstrAllD Ord l -> ConstrAllD Ord r -> KnownHPPortsD ports -> KnownLenD l -> KnownLenD r -> (HListPair l r -> AsyncT ports NextRecv NextRecv Void) -> AsyncT (MapConcat2 l r ports) NextRecv NextRecv Void
- permPorts :: KnownIndex bef => (forall p. InList l p -> InList l' p) -> (forall p. InList l' p -> InList l p) -> AsyncT l bef aft a -> AsyncT l' bef aft a
- data InitStatus
- data InitStatusS (s :: InitStatus) where
- data InitStatusIndexRetD (s :: InitStatus) (i :: Index) (res :: Type) where
- data SomeInitStatusIndexRetD s where
- SomeInitStatusIndexRetD :: InitStatusIndexRetD s i res -> SomeInitStatusIndexRetD s
- class InitStatusIndexRet s i res where
- getInitStatusIndexRetD :: InitStatusIndexRetD s i res
- type family InitStatusOr (s :: InitStatus) (s' :: InitStatus) where ...
- data InitStatusCompD (st :: InitStatus) (st' :: InitStatus) where
- class InitStatusComp st st' where
- getInitStatusCompD :: InitStatusCompD st st'
- type family ToInitStatus (i :: Index) (a :: Type) where ...
- type family InitStatusIndex (st :: InitStatus) where ...
- initStatusIndexS :: InitStatusS st -> SIndex (InitStatusIndex st)
- type family InitStatusRes (st :: InitStatus) where ...
- data ForkPremiseD bef bef' aft aft' a a' = ForkPremiseD {
- forkPremiseIndexCompBef :: ForkIndexCompD bef bef'
- forkPremiseIndexCompAft :: ForkIndexCompD aft aft'
- forkPremiseRet :: MayOnlyReturnAfterRecvD aft a
- forkPremiseRet' :: MayOnlyReturnAfterRecvD aft' a'
- getForkPremiseD :: (ForkIndexComp bef bef', ForkIndexComp aft aft', MayOnlyReturnAfterRecv aft a, MayOnlyReturnAfterRecv aft' a') => ForkPremiseD bef bef' aft aft' a a'
- class MayOnlyReturnAfterRecv i a where
- getMayOnlyReturnAfterRecvPrf :: MayOnlyReturnAfterRecvD i a
- class ForkIndexComp befFst befSnd where
- getForkIndexComp :: ForkIndexCompD befFst befSnd
- getForkIndexSwap :: ForkIndexCompD i i' -> ForkIndexCompD i' i
- getForkIndexRecv :: SIndex i -> ForkIndexCompD NextRecv i
- data ForkIndexCompD (befFst :: Index) (befSnd :: Index) where
- type family ForkIndexOr bef bef' where ...
- class KnownInitStatus (st :: InitStatus) where
- type family ChooseRet i i' a a' where ...
Execution Implementation
These are utility functions that are used by runExec
to evaluate an exection.
The fork_
, swap_
and link_
correspond one-to-one to the constructors
of Exec
. And escapeSyncT
evaluates a concurrent algorithm that has all
of its ports bound as a local algorithm.
Arguments
:: forall st st' ach ach' bef bef' aft aft' a a'. ForkPremiseD bef bef' aft aft' a a' | Proof that this combination of indices and return values is valid |
-> KnownLenD ach | Depdendent length of free ports list in left branch |
-> AsyncT ach bef aft a | Left branch of the fork_ |
-> AsyncT ach' bef' aft' a' | Right branch of the fork_ |
-> AsyncT (Concat ach ach') (ForkIndexOr bef bef') (ForkIndexOr aft aft') (ChooseRet aft aft' a a') |
Run two processes in parallel exposing the free ports of both of them.
The typeclass constaint Forkable
here ensures that:
- No more than one of forked processes expects to finish in
NextSend
. - Only the process that finishes in
NextSend
is allowed to produce a (non-Void
) result.
The resulting action that implements the fork_ starts in NextSend
if one
of the forked actions started in NextSend
. Similarly, it finishes in
NextSend
if one of the forked two finishes in NextSend
. (Implemented
with ForkIndexOr
.)
The return value of the fork_ is the same as return value of process that
finishes in NextSend
. If both finish in NextRecv
, then fork_'s return
value is Void
.
Arguments
:: KnownIndex bef | |
=> ListSplitD l p (f : l') | Proof of |
-> ListSplitD l' p' (s : rest) | Proof of |
-> AsyncT l bef aft a | |
-> AsyncT (Concat p (s : Concat p' (f : rest))) bef aft a |
Swap two free ports.
We go from an action where free ports are
p ++ [f] ++ p' ++ [s] ++ rest
to
p ++ [s] ++ p' ++ [f] ++ rest
.
In other words, the elemens f
and s
are swapped.
The ListSplitD
arguments can often be derived automatically if p
p'
and rest
are fully known.
Arguments
:: KnownIndex bef | |
=> MayOnlyReturnAfterRecvD aft a | |
-> ListSplitD l p ((x :> y) : l') | Proof of |
-> ListSplitD l' p' ((y :> x) : rest) | Proof of |
-> AsyncT l bef aft a | Exectuion where we want to link_ the ports |
-> AsyncT (Concat p (Concat p' rest)) bef aft a |
Link two adjacent free ports with each other. This binds them and removes from the free list.
spawnOnDemand_ :: forall l r ports. ConstrAllD Ord l -> ConstrAllD Ord r -> KnownHPPortsD ports -> KnownLenD l -> KnownLenD r -> (HListPair l r -> AsyncT ports NextRecv NextRecv Void) -> AsyncT (MapConcat2 l r ports) NextRecv NextRecv Void #
Unsafe
permPorts :: KnownIndex bef => (forall p. InList l p -> InList l' p) -> (forall p. InList l' p -> InList l p) -> AsyncT l bef aft a -> AsyncT l' bef aft a #
Helper functions and types
data InitStatus #
Constructors
InitAbsent | |
InitPresent Type |
data InitStatusS (s :: InitStatus) where #
Constructors
InitAbsentS :: InitStatusS InitAbsent | |
InitPresentS :: InitStatusS (InitPresent a) |
data InitStatusIndexRetD (s :: InitStatus) (i :: Index) (res :: Type) where #
Constructors
InitStatusIndexRetAbsent :: InitStatusIndexRetD InitAbsent NextRecv Void | |
InitStatusIndexRetPresent :: InitStatusIndexRetD (InitPresent res) NextSend res |
data SomeInitStatusIndexRetD s where #
Constructors
SomeInitStatusIndexRetD :: InitStatusIndexRetD s i res -> SomeInitStatusIndexRetD s |
class InitStatusIndexRet s i res where #
Methods
getInitStatusIndexRetD :: InitStatusIndexRetD s i res #
Instances
(s ~ 'InitAbsent, res ~ Void) => InitStatusIndexRet s 'NextRecv res # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods getInitStatusIndexRetD :: InitStatusIndexRetD s 'NextRecv res # | |
s ~ 'InitPresent res => InitStatusIndexRet s 'NextSend res # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods getInitStatusIndexRetD :: InitStatusIndexRetD s 'NextSend res # |
type family InitStatusOr (s :: InitStatus) (s' :: InitStatus) where ... #
Equations
InitStatusOr InitAbsent InitAbsent = InitAbsent | |
InitStatusOr (InitPresent a) InitAbsent = InitPresent a | |
InitStatusOr InitAbsent (InitPresent a) = InitPresent a |
data InitStatusCompD (st :: InitStatus) (st' :: InitStatus) where #
Constructors
InitStatusNone :: InitStatusCompD InitAbsent InitAbsent | |
InitStatusFst :: InitStatusCompD (InitPresent a) InitAbsent | |
InitStatusSnd :: InitStatusCompD InitAbsent (InitPresent a) |
class InitStatusComp st st' where #
Methods
getInitStatusCompD :: InitStatusCompD st st' #
Instances
KnownInitStatus st' => InitStatusComp 'InitAbsent st' # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods getInitStatusCompD :: InitStatusCompD 'InitAbsent st' # | |
st' ~ 'InitAbsent => InitStatusComp ('InitPresent res) st' # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods getInitStatusCompD :: InitStatusCompD ('InitPresent res) st' # |
type family ToInitStatus (i :: Index) (a :: Type) where ... #
Equations
ToInitStatus NextSend a = InitPresent a | |
ToInitStatus NextRecv _ = InitAbsent |
type family InitStatusIndex (st :: InitStatus) where ... #
Equations
InitStatusIndex InitAbsent = NextRecv | |
InitStatusIndex (InitPresent _) = NextSend |
initStatusIndexS :: InitStatusS st -> SIndex (InitStatusIndex st) #
type family InitStatusRes (st :: InitStatus) where ... #
Equations
InitStatusRes InitAbsent = Void | |
InitStatusRes (InitPresent res) = res |
data ForkPremiseD bef bef' aft aft' a a' #
Constructors
ForkPremiseD | |
Fields
|
getForkPremiseD :: (ForkIndexComp bef bef', ForkIndexComp aft aft', MayOnlyReturnAfterRecv aft a, MayOnlyReturnAfterRecv aft' a') => ForkPremiseD bef bef' aft aft' a a' #
class MayOnlyReturnAfterRecv i a where #
Methods
getMayOnlyReturnAfterRecvPrf :: MayOnlyReturnAfterRecvD i a #
Instances
MayOnlyReturnAfterRecv 'NextRecv Void # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods getMayOnlyReturnAfterRecvPrf :: MayOnlyReturnAfterRecvD 'NextRecv Void # | |
MayOnlyReturnAfterRecv 'NextSend a # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods getMayOnlyReturnAfterRecvPrf :: MayOnlyReturnAfterRecvD 'NextSend a # |
class ForkIndexComp befFst befSnd where #
Methods
getForkIndexComp :: ForkIndexCompD befFst befSnd #
Instances
KnownIndex i => ForkIndexComp 'NextRecv i # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods | |
i ~ 'NextRecv => ForkIndexComp 'NextSend i # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods |
getForkIndexSwap :: ForkIndexCompD i i' -> ForkIndexCompD i' i #
getForkIndexRecv :: SIndex i -> ForkIndexCompD NextRecv i #
data ForkIndexCompD (befFst :: Index) (befSnd :: Index) where #
type family ForkIndexOr bef bef' where ... #
Equations
ForkIndexOr NextSend NextRecv = NextSend | |
ForkIndexOr NextRecv i = i |
class KnownInitStatus (st :: InitStatus) where #
Methods
getKnownInitStatus :: InitStatusS st #
Instances
KnownInitStatus 'InitAbsent # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods | |
KnownInitStatus ('InitPresent a) # | |
Defined in LambdaUC.Syntax.Async.Eval.Internal Methods getKnownInitStatus :: InitStatusS ('InitPresent a) # |