hoopl-3.10.2.2: A library to support dataflow analysis and optimization

Safe Haskell | Safe
Language | Haskell2010

Compiler.Hoopl

Contents

- Body
- Graph
  - Constructing graphs
  - Splicing graphs
  - Maps
  - Folds
  - Extracting Labels
  - Depth-first traversals
- Shapes
- Blocks
  - Predicates on Blocks
  - Constructing blocks
  - Deconstructing blocks
  - Modifying blocks
  - Converting to and from lists
  - Maps and folds
  - Biasing
- Utilities for clients
- Respecting Fuel

Synopsis

- type Body n = LabelMap (Block n C C)
- type Body' block (n :: * -> * -> *) = LabelMap (block n C C)
- emptyBody :: Body' block n
- bodyList :: Body' block n -> [(Label, block n C C)]
- addBlock :: NonLocal thing => thing C C -> LabelMap (thing C C) -> LabelMap (thing C C)
- bodyUnion :: forall a. LabelMap a -> LabelMap a -> LabelMap a
- type Graph = Graph' Block
- data Graph' block (n :: * -> * -> *) e x where
  - GNil :: Graph' block n O O
  - GUnit :: block n O O -> Graph' block n O O
  - GMany :: MaybeO e (block n O C) -> Body' block n -> MaybeO x (block n C O) -> Graph' block n e x
- class NonLocal thing where
- bodyGraph :: Body n -> Graph n C C
- blockGraph :: NonLocal n => Block n e x -> Graph n e x
- gUnitOO :: block n O O -> Graph' block n O O
- gUnitOC :: block n O C -> Graph' block n O C
- gUnitCO :: block n C O -> Graph' block n C O
- gUnitCC :: NonLocal (block n) => block n C C -> Graph' block n C C
- catGraphNodeOC :: NonLocal n => Graph n e O -> n O C -> Graph n e C
- catGraphNodeOO :: Graph n e O -> n O O -> Graph n e O
- catNodeCOGraph :: NonLocal n => n C O -> Graph n O x -> Graph n C x
- catNodeOOGraph :: n O O -> Graph n O x -> Graph n O x
- splice :: forall block n e a x. NonLocal (block n) => (forall e x. block n e O -> block n O x -> block n e x) -> Graph' block n e a -> Graph' block n a x -> Graph' block n e x
- gSplice :: NonLocal n => Graph n e a -> Graph n a x -> Graph n e x
- mapGraph :: (forall e x. n e x -> n' e x) -> Graph n e x -> Graph n' e x
- mapGraphBlocks :: forall block n block' n' e x. (forall e x. block n e x -> block' n' e x) -> Graph' block n e x -> Graph' block' n' e x
- foldGraphNodes :: forall n a. (forall e x. n e x -> a -> a) -> forall e x. Graph n e x -> a -> a
- labelsDefined :: forall block n e x. NonLocal (block n) => Graph' block n e x -> LabelSet
- labelsUsed :: forall block n e x. NonLocal (block n) => Graph' block n e x -> LabelSet
- externalEntryLabels :: forall n. NonLocal n => LabelMap (Block n C C) -> LabelSet
- postorder_dfs :: NonLocal (block n) => Graph' block n O x -> [block n C C]
- postorder_dfs_from :: (NonLocal block, LabelsPtr b) => LabelMap (block C C) -> b -> [block C C]
- postorder_dfs_from_except :: forall block e. (NonLocal block, LabelsPtr e) => LabelMap (block C C) -> e -> LabelSet -> [block C C]
- preorder_dfs :: NonLocal (block n) => Graph' block n O x -> [block n C C]
- preorder_dfs_from_except :: forall block e. (NonLocal block, LabelsPtr e) => LabelMap (block C C) -> e -> LabelSet -> [block C C]
- class LabelsPtr l where
- data O
- data C
- data MaybeO ex t where
  - JustO :: t -> MaybeO O t
  - NothingO :: MaybeO C t
- data MaybeC ex t where
  - JustC :: t -> MaybeC C t
  - NothingC :: MaybeC O t
- type family IndexedCO ex a b :: *
- data Shape ex where
  - Closed :: Shape C
  - Open :: Shape O
- data Block n e x where
  - BlockCO :: n C O -> Block n O O -> Block n C O
  - BlockCC :: n C O -> Block n O O -> n O C -> Block n C C
  - BlockOC :: Block n O O -> n O C -> Block n O C
  - BNil :: Block n O O
  - BMiddle :: n O O -> Block n O O
  - BCat :: Block n O O -> Block n O O -> Block n O O
  - BSnoc :: Block n O O -> n O O -> Block n O O
  - BCons :: n O O -> Block n O O -> Block n O O
- isEmptyBlock :: Block n e x -> Bool
- emptyBlock :: Block n O O
- blockCons :: n O O -> Block n O x -> Block n O x
- blockSnoc :: Block n e O -> n O O -> Block n e O
- blockJoinHead :: n C O -> Block n O x -> Block n C x
- blockJoinTail :: Block n e O -> n O C -> Block n e C
- blockJoin :: n C O -> Block n O O -> n O C -> Block n C C
- blockJoinAny :: (MaybeC e (n C O), Block n O O, MaybeC x (n O C)) -> Block n e x
- blockAppend :: Block n e O -> Block n O x -> Block n e x
- firstNode :: Block n C x -> n C O
- lastNode :: Block n x C -> n O C
- endNodes :: Block n C C -> (n C O, n O C)
- blockSplitHead :: Block n C x -> (n C O, Block n O x)
- blockSplitTail :: Block n e C -> (Block n e O, n O C)
- blockSplit :: Block n C C -> (n C O, Block n O O, n O C)
- blockSplitAny :: Block n e x -> (MaybeC e (n C O), Block n O O, MaybeC x (n O C))
- replaceFirstNode :: Block n C x -> n C O -> Block n C x
- replaceLastNode :: Block n x C -> n O C -> Block n x C
- blockToList :: Block n O O -> [n O O]
- blockFromList :: [n O O] -> Block n O O
- mapBlock :: (forall e x. n e x -> n' e x) -> Block n e x -> Block n' e x
- mapBlock' :: (forall e x. n e x -> n' e x) -> Block n e x -> Block n' e x
- mapBlock3' :: forall n n' e x. (n C O -> n' C O, n O O -> n' O O, n O C -> n' O C) -> Block n e x -> Block n' e x
- foldBlockNodesF :: forall n a. (forall e x. n e x -> a -> a) -> forall e x. Block n e x -> IndexedCO e a a -> IndexedCO x a a
- foldBlockNodesF3 :: forall n a b c. (n C O -> a -> b, n O O -> b -> b, n O C -> b -> c) -> forall e x. Block n e x -> IndexedCO e a b -> IndexedCO x c b
- foldBlockNodesB :: forall n a. (forall e x. n e x -> a -> a) -> forall e x. Block n e x -> IndexedCO x a a -> IndexedCO e a a
- foldBlockNodesB3 :: forall n a b c. (n C O -> b -> c, n O O -> b -> b, n O C -> a -> b) -> forall e x. Block n e x -> IndexedCO x a b -> IndexedCO e c b
- frontBiasBlock :: Block n e x -> Block n e x
- backBiasBlock :: Block n e x -> Block n e x
- data AGraph n e x
- graphOfAGraph :: AGraph n e x -> forall m. UniqueMonad m => m (Graph n e x)
- aGraphOfGraph :: Graph n e x -> AGraph n e x
- (<*>) :: (GraphRep g, NonLocal n) => g n e O -> g n O x -> g n e x
- (|*><*|) :: (GraphRep g, NonLocal n) => g n e C -> g n C x -> g n e x
- catGraphs :: (GraphRep g, NonLocal n) => [g n O O] -> g n O O
- addEntrySeq :: NonLocal n => AGraph n O C -> AGraph n C x -> AGraph n O x
- addExitSeq :: NonLocal n => AGraph n e C -> AGraph n C O -> AGraph n e O
- addBlocks :: HooplNode n => AGraph n e x -> AGraph n C C -> AGraph n e x
- unionBlocks :: NonLocal n => AGraph n C C -> AGraph n C C -> AGraph n C C
- emptyGraph :: GraphRep g => g n O O
- emptyClosedGraph :: GraphRep g => g n C C
- withFresh :: Uniques u => (u -> AGraph n e x) -> AGraph n e x
- mkFirst :: GraphRep g => n C O -> g n C O
- mkMiddle :: GraphRep g => n O O -> g n O O
- mkMiddles :: (GraphRep g, NonLocal n) => [n O O] -> g n O O
- mkLast :: GraphRep g => n O C -> g n O C
- mkBranch :: (GraphRep g, HooplNode n) => Label -> g n O C
- mkLabel :: (GraphRep g, HooplNode n) => Label -> g n C O
- mkWhileDo :: HooplNode n => (Label -> Label -> AGraph n O C) -> AGraph n O O -> AGraph n O O
- class IfThenElseable x where
- mkEntry :: GraphRep g => Block n O C -> g n O C
- mkExit :: GraphRep g => Block n C O -> g n C O
- class NonLocal n => HooplNode n where
- firstXfer :: NonLocal n => (n C O -> f -> f) -> n C O -> FactBase f -> f
- distributeXfer :: NonLocal n => DataflowLattice f -> (n O C -> f -> f) -> n O C -> f -> FactBase f
- distributeFact :: NonLocal n => n O C -> f -> FactBase f
- distributeFactBwd :: NonLocal n => n C O -> f -> FactBase f
- successorFacts :: NonLocal n => n O C -> FactBase f -> [f]
- joinFacts :: DataflowLattice f -> Label -> [f] -> f
- joinOutFacts :: NonLocal node => DataflowLattice f -> node O C -> FactBase f -> f
- joinMaps :: Ord k => JoinFun v -> JoinFun (Map k v)
- analyzeAndRewriteFwdBody :: forall m n f entries. (CheckpointMonad m, NonLocal n, LabelsPtr entries) => FwdPass m n f -> entries -> Body n -> FactBase f -> m (Body n, FactBase f)
- analyzeAndRewriteBwdBody :: forall m n f entries. (CheckpointMonad m, NonLocal n, LabelsPtr entries) => BwdPass m n f -> entries -> Body n -> FactBase f -> m (Body n, FactBase f)
- analyzeAndRewriteFwdOx :: forall m n f x. (CheckpointMonad m, NonLocal n) => FwdPass m n f -> Graph n O x -> f -> m (Graph n O x, FactBase f, MaybeO x f)
- analyzeAndRewriteBwdOx :: forall m n f x. (CheckpointMonad m, NonLocal n) => BwdPass m n f -> Graph n O x -> Fact x f -> m (Graph n O x, FactBase f, f)
- class IsSet set where
  - type ElemOf set
- setInsertList :: IsSet set => [ElemOf set] -> set -> set
- setDeleteList :: IsSet set => [ElemOf set] -> set -> set
- setUnions :: IsSet set => [set] -> set
- class IsMap map where
  - type KeyOf map
- mapInsertList :: IsMap map => [(KeyOf map, a)] -> map a -> map a
- mapDeleteList :: IsMap map => [KeyOf map] -> map a -> map a
- mapUnions :: IsMap map => [map a] -> map a
- class Monad m => CheckpointMonad m where
  - type Checkpoint m
- data DataflowLattice a = DataflowLattice {
  - fact_name :: String
  - fact_bot :: a
  - fact_join :: JoinFun a
  }
- type JoinFun a = Label -> OldFact a -> NewFact a -> (ChangeFlag, a)
- newtype OldFact a = OldFact a
- newtype NewFact a = NewFact a
- type family Fact x f :: *
- mkFactBase :: forall f. DataflowLattice f -> [(Label, f)] -> FactBase f
- data ChangeFlag
  - = NoChange
  - | SomeChange
- changeIf :: Bool -> ChangeFlag
- data FwdPass m n f = FwdPass {
  - fp_lattice :: DataflowLattice f
  - fp_transfer :: FwdTransfer n f
  - fp_rewrite :: FwdRewrite m n f
  }
- newtype FwdTransfer n f = FwdTransfer3 {
  - getFTransfer3 :: (n C O -> f -> f, n O O -> f -> f, n O C -> f -> FactBase f)
  }
- mkFTransfer :: (forall e x. n e x -> f -> Fact x f) -> FwdTransfer n f
- mkFTransfer3 :: (n C O -> f -> f) -> (n O O -> f -> f) -> (n O C -> f -> FactBase f) -> FwdTransfer n f
- newtype FwdRewrite m n f = FwdRewrite3 {
  - getFRewrite3 :: (n C O -> f -> m (Maybe (Graph n C O, FwdRewrite m n f)), n O O -> f -> m (Maybe (Graph n O O, FwdRewrite m n f)), n O C -> f -> m (Maybe (Graph n O C, FwdRewrite m n f)))
  }
- mkFRewrite :: FuelMonad m => (forall e x. n e x -> f -> m (Maybe (Graph n e x))) -> FwdRewrite m n f
- mkFRewrite3 :: forall m n f. FuelMonad m => (n C O -> f -> m (Maybe (Graph n C O))) -> (n O O -> f -> m (Maybe (Graph n O O))) -> (n O C -> f -> m (Maybe (Graph n O C))) -> FwdRewrite m n f
- noFwdRewrite :: Monad m => FwdRewrite m n f
- wrapFR :: (forall e x. (n e x -> f -> m (Maybe (Graph n e x, FwdRewrite m n f))) -> n' e x -> f' -> m' (Maybe (Graph n' e x, FwdRewrite m' n' f'))) -> FwdRewrite m n f -> FwdRewrite m' n' f'
- wrapFR2 :: (forall e x. (n1 e x -> f1 -> m1 (Maybe (Graph n1 e x, FwdRewrite m1 n1 f1))) -> (n2 e x -> f2 -> m2 (Maybe (Graph n2 e x, FwdRewrite m2 n2 f2))) -> n3 e x -> f3 -> m3 (Maybe (Graph n3 e x, FwdRewrite m3 n3 f3))) -> FwdRewrite m1 n1 f1 -> FwdRewrite m2 n2 f2 -> FwdRewrite m3 n3 f3
- data BwdPass m n f = BwdPass {
  - bp_lattice :: DataflowLattice f
  - bp_transfer :: BwdTransfer n f
  - bp_rewrite :: BwdRewrite m n f
  }
- newtype BwdTransfer n f = BwdTransfer3 {
  - getBTransfer3 :: (n C O -> f -> f, n O O -> f -> f, n O C -> FactBase f -> f)
  }
- mkBTransfer :: (forall e x. n e x -> Fact x f -> f) -> BwdTransfer n f
- mkBTransfer3 :: (n C O -> f -> f) -> (n O O -> f -> f) -> (n O C -> FactBase f -> f) -> BwdTransfer n f
- wrapBR :: (forall e x. Shape x -> (n e x -> Fact x f -> m (Maybe (Graph n e x, BwdRewrite m n f))) -> n' e x -> Fact x f' -> m' (Maybe (Graph n' e x, BwdRewrite m' n' f'))) -> BwdRewrite m n f -> BwdRewrite m' n' f'
- wrapBR2 :: (forall e x. Shape x -> (n1 e x -> Fact x f1 -> m1 (Maybe (Graph n1 e x, BwdRewrite m1 n1 f1))) -> (n2 e x -> Fact x f2 -> m2 (Maybe (Graph n2 e x, BwdRewrite m2 n2 f2))) -> n3 e x -> Fact x f3 -> m3 (Maybe (Graph n3 e x, BwdRewrite m3 n3 f3))) -> BwdRewrite m1 n1 f1 -> BwdRewrite m2 n2 f2 -> BwdRewrite m3 n3 f3
- newtype BwdRewrite m n f = BwdRewrite3 {
  - getBRewrite3 :: (n C O -> f -> m (Maybe (Graph n C O, BwdRewrite m n f)), n O O -> f -> m (Maybe (Graph n O O, BwdRewrite m n f)), n O C -> FactBase f -> m (Maybe (Graph n O C, BwdRewrite m n f)))
  }
- mkBRewrite :: FuelMonad m => (forall e x. n e x -> Fact x f -> m (Maybe (Graph n e x))) -> BwdRewrite m n f
- mkBRewrite3 :: forall m n f. FuelMonad m => (n C O -> f -> m (Maybe (Graph n C O))) -> (n O O -> f -> m (Maybe (Graph n O O))) -> (n O C -> FactBase f -> m (Maybe (Graph n O C))) -> BwdRewrite m n f
- noBwdRewrite :: Monad m => BwdRewrite m n f
- analyzeAndRewriteFwd :: forall m n f e x entries. (CheckpointMonad m, NonLocal n, LabelsPtr entries) => FwdPass m n f -> MaybeC e entries -> Graph n e x -> Fact e f -> m (Graph n e x, FactBase f, MaybeO x f)
- analyzeAndRewriteBwd :: (CheckpointMonad m, NonLocal n, LabelsPtr entries) => BwdPass m n f -> MaybeC e entries -> Graph n e x -> Fact x f -> m (Graph n e x, FactBase f, MaybeO e f)
- data Label
- freshLabel :: UniqueMonad m => m Label
- data LabelSet
- data LabelMap v
- type FactBase f = LabelMap f
- noFacts :: FactBase f
- lookupFact :: Label -> FactBase f -> Maybe f
- uniqueToLbl :: Unique -> Label
- lblToUnique :: Label -> Unique
- data Pointed t b a where
  - Bot :: Pointed t C a
  - PElem :: a -> Pointed t b a
  - Top :: Pointed C b a
- addPoints :: String -> JoinFun a -> DataflowLattice (Pointed t C a)
- addPoints' :: forall a t. String -> (Label -> OldFact a -> NewFact a -> (ChangeFlag, Pointed t C a)) -> DataflowLattice (Pointed t C a)
- addTop :: DataflowLattice a -> DataflowLattice (WithTop a)
- addTop' :: forall a. String -> a -> (Label -> OldFact a -> NewFact a -> (ChangeFlag, WithTop a)) -> DataflowLattice (WithTop a)
- liftJoinTop :: JoinFun a -> JoinFun (WithTop a)
- extendJoinDomain :: forall a. (Label -> OldFact a -> NewFact a -> (ChangeFlag, WithTop a)) -> JoinFun (WithTop a)
- type WithTop a = Pointed C O a
- type WithBot a = Pointed O C a
- type WithTopAndBot a = Pointed C C a
- thenFwdRw :: forall m n f. Monad m => FwdRewrite m n f -> FwdRewrite m n f -> FwdRewrite m n f
- deepFwdRw3 :: FuelMonad m => (n C O -> f -> m (Maybe (Graph n C O))) -> (n O O -> f -> m (Maybe (Graph n O O))) -> (n O C -> f -> m (Maybe (Graph n O C))) -> FwdRewrite m n f
- deepFwdRw :: FuelMonad m => (forall e x. n e x -> f -> m (Maybe (Graph n e x))) -> FwdRewrite m n f
- iterFwdRw :: forall m n f. Monad m => FwdRewrite m n f -> FwdRewrite m n f
- thenBwdRw :: forall m n f. Monad m => BwdRewrite m n f -> BwdRewrite m n f -> BwdRewrite m n f
- deepBwdRw3 :: FuelMonad m => (n C O -> f -> m (Maybe (Graph n C O))) -> (n O O -> f -> m (Maybe (Graph n O O))) -> (n O C -> FactBase f -> m (Maybe (Graph n O C))) -> BwdRewrite m n f
- deepBwdRw :: FuelMonad m => (forall e x. n e x -> Fact x f -> m (Maybe (Graph n e x))) -> BwdRewrite m n f
- iterBwdRw :: forall m n f. Monad m => BwdRewrite m n f -> BwdRewrite m n f
- pairFwd :: forall m n f f'. Monad m => FwdPass m n f -> FwdPass m n f' -> FwdPass m n (f, f')
- pairBwd :: forall m n f f'. Monad m => BwdPass m n f -> BwdPass m n f' -> BwdPass m n (f, f')
- pairLattice :: forall f f'. DataflowLattice f -> DataflowLattice f' -> DataflowLattice (f, f')
- type Fuel = Int
- infiniteFuel :: Fuel
- fuelRemaining :: FuelMonad m => m Fuel
- withFuel :: FuelMonad m => Maybe a -> m (Maybe a)
- class Monad m => FuelMonad m where
- class FuelMonadT fm where
- data CheckingFuelMonad m a
- data InfiniteFuelMonad m a
- type SimpleFuelMonad = CheckingFuelMonad SimpleUniqueMonad
- type Unique = Int
- intToUnique :: Int -> Unique
- data UniqueSet
- data UniqueMap v
- class Monad m => UniqueMonad m where
- data SimpleUniqueMonad a
- runSimpleUniqueMonad :: SimpleUniqueMonad a -> a
- data UniqueMonadT m a
- runUniqueMonadT :: Monad m => UniqueMonadT m a -> m a
- uniqueToInt :: Unique -> Int
- type TraceFn = forall a. String -> a -> a
- debugFwdJoins :: forall m n f. Show f => TraceFn -> ChangePred -> FwdPass m n f -> FwdPass m n f
- debugBwdJoins :: forall m n f. Show f => TraceFn -> ChangePred -> BwdPass m n f -> BwdPass m n f
- debugFwdTransfers :: forall m n f. Show f => TraceFn -> ShowN n -> FPred n f -> FwdPass m n f -> FwdPass m n f
- debugBwdTransfers :: forall m n f. Show f => TraceFn -> ShowN n -> BPred n f -> BwdPass m n f -> BwdPass m n f
- showGraph :: forall n e x. Showing n -> Graph n e x -> String
- showFactBase :: Show f => FactBase f -> String
- type Showing n = forall e x. n e x -> String

# Body

type Body n = LabelMap (Block n C C) #

A (possibly empty) collection of closed/closed blocks

type Body' block (n :: * -> * -> *) = LabelMap (block n C C) #

`Body` abstracted over `block`

emptyBody :: Body' block n #

bodyList :: Body' block n -> [(Label, block n C C)] #

addBlock :: NonLocal thing => thing C C -> LabelMap (thing C C) -> LabelMap (thing C C) #

bodyUnion :: forall a. LabelMap a -> LabelMap a -> LabelMap a #

# Graph

type Graph = Graph' Block #

A control-flow graph, which may take any of four shapes (O/O, OC, CO, C/C). A graph open at the entry has a single, distinguished, anonymous entry point; if a graph is closed at the entry, its entry point(s) are supplied by a context.

data Graph' block (n :: * -> * -> *) e x where #

`Graph'` is abstracted over the block type, so that we can build graphs of annotated blocks for example (Compiler.Hoopl.Dataflow needs this).

Constructors

GNil :: Graph' block n O O |
GUnit :: block n O O -> Graph' block n O O |
GMany :: MaybeO e (block n O C) -> Body' block n -> MaybeO x (block n C O) -> Graph' block n e x |

class NonLocal thing where #

Gives access to the anchor points for nonlocal edges as well as the edges themselves

Minimal complete definition

entryLabel, successors

Methods

entryLabel #

Arguments

:: thing C x |
-> Label | The label of a first node or block

successors #

Arguments

:: thing e C |
-> [Label] | Gives control-flow successors

Instances

NonLocal n => NonLocal (Block n) # |
Methods entryLabel :: Block n C x -> Label # successors :: Block n e C -> [Label] #

## Constructing graphs

bodyGraph :: Body n -> Graph n C C #

blockGraph :: NonLocal n => Block n e x -> Graph n e x #

gUnitOO :: block n O O -> Graph' block n O O #

gUnitOC :: block n O C -> Graph' block n O C #

gUnitCO :: block n C O -> Graph' block n C O #

gUnitCC :: NonLocal (block n) => block n C C -> Graph' block n C C #

catGraphNodeOC :: NonLocal n => Graph n e O -> n O C -> Graph n e C #

catGraphNodeOO :: Graph n e O -> n O O -> Graph n e O #

catNodeCOGraph :: NonLocal n => n C O -> Graph n O x -> Graph n C x #

catNodeOOGraph :: n O O -> Graph n O x -> Graph n O x #

## Splicing graphs

splice :: forall block n e a x. NonLocal (block n) => (forall e x. block n e O -> block n O x -> block n e x) -> Graph' block n e a -> Graph' block n a x -> Graph' block n e x #

gSplice :: NonLocal n => Graph n e a -> Graph n a x -> Graph n e x #

## Maps

mapGraph :: (forall e x. n e x -> n' e x) -> Graph n e x -> Graph n' e x #

Maps over all nodes in a graph.

mapGraphBlocks :: forall block n block' n' e x. (forall e x. block n e x -> block' n' e x) -> Graph' block n e x -> Graph' block' n' e x #

Function `mapGraphBlocks` enables a change of representation of blocks, nodes, or both. It lifts a polymorphic block transform into a polymorphic graph transform. When the block representation stabilizes, a similar function should be provided for blocks.

## Folds

foldGraphNodes :: forall n a. (forall e x. n e x -> a -> a) -> forall e x. Graph n e x -> a -> a #

Fold a function over every node in a graph. The fold function must be polymorphic in the shape of the nodes.

## Extracting Labels

labelsDefined :: forall block n e x. NonLocal (block n) => Graph' block n e x -> LabelSet #

labelsUsed :: forall block n e x. NonLocal (block n) => Graph' block n e x -> LabelSet #

externalEntryLabels :: forall n. NonLocal n => LabelMap (Block n C C) -> LabelSet #

## Depth-first traversals

postorder_dfs :: NonLocal (block n) => Graph' block n O x -> [block n C C] #

Traversal: `postorder_dfs` returns a list of blocks reachable from the entry of enterable graph. The entry and exit are *not* included. The list has the following property:

Say a "back reference" exists if one of a block's control-flow successors precedes it in the output list

Then there are as few back references as possible

The output is suitable for use in a forward dataflow problem. For a backward problem, simply reverse the list. (`postorder_dfs` is sufficiently tricky to implement that one doesn't want to try and maintain both forward and backward versions.)

postorder_dfs_from :: (NonLocal block, LabelsPtr b) => LabelMap (block C C) -> b -> [block C C] #

postorder_dfs_from_except :: forall block e. (NonLocal block, LabelsPtr e) => LabelMap (block C C) -> e -> LabelSet -> [block C C] #

preorder_dfs :: NonLocal (block n) => Graph' block n O x -> [block n C C] #

preorder_dfs_from_except :: forall block e. (NonLocal block, LabelsPtr e) => LabelMap (block C C) -> e -> LabelSet -> [block C C] #

class LabelsPtr l where #

Minimal complete definition

targetLabels

Methods

targetLabels :: l -> [Label] #

Instances

LabelsPtr LabelSet # |
Methods targetLabels :: LabelSet -> [Label] #
LabelsPtr Label # |
Methods targetLabels :: Label -> [Label] #
LabelsPtr l => LabelsPtr [l] # |
Methods targetLabels :: [l] -> [Label] #
NonLocal n => LabelsPtr (n e C) # |
Methods targetLabels :: n e C -> [Label] #

# Shapes

data O #

Used at the type level to indicate an "open" structure with a unique, unnamed control-flow edge flowing in or out. Fallthrough and concatenation are permitted at an open point.

Instances

IfThenElseable O # |
Methods mkIfThenElse :: HooplNode n => (Label -> Label -> AGraph n O C) -> AGraph n O O -> AGraph n O O -> AGraph n O O #
type Fact O f # |
type Fact O f = f
type IndexedCO O _a b # |
type IndexedCO O _a b = b

data C #

Used at the type level to indicate a "closed" structure which supports control transfer only through the use of named labels---no "fallthrough" is permitted. The number of control-flow edges is unconstrained.

Instances

IfThenElseable C # |
Methods mkIfThenElse :: HooplNode n => (Label -> Label -> AGraph n O C) -> AGraph n O C -> AGraph n O C -> AGraph n O C #
NonLocal n => LabelsPtr (n e C) # |
Methods targetLabels :: n e C -> [Label] #
type Fact C f # |
type Fact C f = FactBase f
type IndexedCO C a _b # |
type IndexedCO C a _b = a

data MaybeO ex t where #

Maybe type indexed by open/closed

Constructors

JustO :: t -> MaybeO O t |
NothingO :: MaybeO C t |

Instances

Functor (MaybeO ex) # |
Methods fmap :: (a -> b) -> MaybeO ex a -> MaybeO ex b Source # (<$) :: a -> MaybeO ex b -> MaybeO ex a Source #

data MaybeC ex t where #

Maybe type indexed by closed/open

Constructors

JustC :: t -> MaybeC C t |
NothingC :: MaybeC O t |

Instances

Functor (MaybeC ex) # |
Methods fmap :: (a -> b) -> MaybeC ex a -> MaybeC ex b Source # (<$) :: a -> MaybeC ex b -> MaybeC ex a Source #

type family IndexedCO ex a b :: * #

Either type indexed by closed/open using type families

Instances

type IndexedCO C a _b # |
type IndexedCO C a _b = a
type IndexedCO O _a b # |
type IndexedCO O _a b = b

data Shape ex where #

Dynamic shape value

Constructors

Closed :: Shape C |
Open :: Shape O |

# Blocks

data Block n e x where #

A sequence of nodes. May be any of four shapes (OO, OC, CO, CC). Open at the entry means single entry, mutatis mutandis for exit. A closedclosed block is a basic/ block and can't be extended further. Clients should avoid manipulating blocks and should stick to either nodes or graphs.

Constructors

BlockCO :: n C O -> Block n O O -> Block n C O |
BlockCC :: n C O -> Block n O O -> n O C -> Block n C C |
BlockOC :: Block n O O -> n O C -> Block n O C |
BNil :: Block n O O |
BMiddle :: n O O -> Block n O O |
BCat :: Block n O O -> Block n O O -> Block n O O |
BSnoc :: Block n O O -> n O O -> Block n O O |
BCons :: n O O -> Block n O O -> Block n O O |

Instances

NonLocal n => NonLocal (Block n) # |
Methods entryLabel :: Block n C x -> Label # successors :: Block n e C -> [Label] #

## Predicates on Blocks

isEmptyBlock :: Block n e x -> Bool #

## Constructing blocks

emptyBlock :: Block n O O #

blockCons :: n O O -> Block n O x -> Block n O x #

blockSnoc :: Block n e O -> n O O -> Block n e O #

blockJoinHead :: n C O -> Block n O x -> Block n C x #

blockJoinTail :: Block n e O -> n O C -> Block n e C #

blockJoin :: n C O -> Block n O O -> n O C -> Block n C C #

blockJoinAny :: (MaybeC e (n C O), Block n O O, MaybeC x (n O C)) -> Block n e x #

Convert a list of nodes to a block. The entry and exit node must or must not be present depending on the shape of the block.

blockAppend :: Block n e O -> Block n O x -> Block n e x #

## Deconstructing blocks

firstNode :: Block n C x -> n C O #

lastNode :: Block n x C -> n O C #

endNodes :: Block n C C -> (n C O, n O C) #

blockSplitHead :: Block n C x -> (n C O, Block n O x) #

blockSplitTail :: Block n e C -> (Block n e O, n O C) #

blockSplit :: Block n C C -> (n C O, Block n O O, n O C) #

Split a closed block into its entry node, open middle block, and exit node.

blockSplitAny :: Block n e x -> (MaybeC e (n C O), Block n O O, MaybeC x (n O C)) #

## Modifying blocks

replaceFirstNode :: Block n C x -> n C O -> Block n C x #

replaceLastNode :: Block n x C -> n O C -> Block n x C #

## Converting to and from lists

blockToList :: Block n O O -> [n O O] #

blockFromList :: [n O O] -> Block n O O #

## Maps and folds

mapBlock :: (forall e x. n e x -> n' e x) -> Block n e x -> Block n' e x #

map a function over the nodes of a `Block`

mapBlock' :: (forall e x. n e x -> n' e x) -> Block n e x -> Block n' e x #

A strict `mapBlock`

mapBlock3' :: forall n n' e x. (n C O -> n' C O, n O O -> n' O O, n O C -> n' O C) -> Block n e x -> Block n' e x #

map over a block, with different functions to apply to first nodes, middle nodes and last nodes respectively. The map is strict.

foldBlockNodesF :: forall n a. (forall e x. n e x -> a -> a) -> forall e x. Block n e x -> IndexedCO e a a -> IndexedCO x a a #

foldBlockNodesF3 :: forall n a b c. (n C O -> a -> b, n O O -> b -> b, n O C -> b -> c) -> forall e x. Block n e x -> IndexedCO e a b -> IndexedCO x c b #

Fold a function over every node in a block, forward or backward. The fold function must be polymorphic in the shape of the nodes.

foldBlockNodesB :: forall n a. (forall e x. n e x -> a -> a) -> forall e x. Block n e x -> IndexedCO x a a -> IndexedCO e a a #

foldBlockNodesB3 :: forall n a b c. (n C O -> b -> c, n O O -> b -> b, n O C -> a -> b) -> forall e x. Block n e x -> IndexedCO x a b -> IndexedCO e c b #

## Biasing

frontBiasBlock :: Block n e x -> Block n e x #

A block is "front biased" if the left child of every concatenation operation is a node, not a general block; a front-biased block is analogous to an ordinary list. If a block is front-biased, then its nodes can be traversed from front to back without general recusion; tail recursion suffices. Not all shapes can be front-biased; a closed/open block is inherently back-biased.

backBiasBlock :: Block n e x -> Block n e x #

A block is "back biased" if the right child of every concatenation operation is a node, not a general block; a back-biased block is analogous to a snoc-list. If a block is back-biased, then its nodes can be traversed from back to back without general recusion; tail recursion suffices. Not all shapes can be back-biased; an open/closed block is inherently front-biased.

data AGraph n e x #

The type of abstract graphs. Offers extra "smart constructors" that may consume fresh labels during construction.

graphOfAGraph :: AGraph n e x -> forall m. UniqueMonad m => m (Graph n e x) #

Take an abstract `AGraph` and make a concrete (if monadic) `Graph`.

aGraphOfGraph :: Graph n e x -> AGraph n e x #

Take a graph and make it abstract.

(<*>) :: (GraphRep g, NonLocal n) => g n e O -> g n O x -> g n e x infixl 3 #

Concatenate two graphs; control flows from left to right.

(|*><*|) :: (GraphRep g, NonLocal n) => g n e C -> g n C x -> g n e x infixl 2 #

Splice together two graphs at a closed point; nothing is known about control flow.

catGraphs :: (GraphRep g, NonLocal n) => [g n O O] -> g n O O #

Conveniently concatenate a sequence of open/open graphs using `<*>`.

addEntrySeq :: NonLocal n => AGraph n O C -> AGraph n C x -> AGraph n O x #

Deprecated: use |*><*| instead

addExitSeq :: NonLocal n => AGraph n e C -> AGraph n C O -> AGraph n e O #

Deprecated: use |*><*| instead

addBlocks :: HooplNode n => AGraph n e x -> AGraph n C C -> AGraph n e x #

Extend an existing `AGraph` with extra basic blocks "out of line". No control flow is implied. Simon PJ should give example use case.

unionBlocks :: NonLocal n => AGraph n C C -> AGraph n C C -> AGraph n C C #

Deprecated: use |*><*| instead

emptyGraph :: GraphRep g => g n O O #

An empty graph that is open at entry and exit. It is the left and right identity of `<*>`.

emptyClosedGraph :: GraphRep g => g n C C #

An empty graph that is closed at entry and exit. It is the left and right identity of `|*><*|`.

withFresh :: Uniques u => (u -> AGraph n e x) -> AGraph n e x #

mkFirst :: GraphRep g => n C O -> g n C O #

Create a graph from a first node

mkMiddle :: GraphRep g => n O O -> g n O O #

Create a graph from a middle node

mkMiddles :: (GraphRep g, NonLocal n) => [n O O] -> g n O O #

Conveniently concatenate a sequence of middle nodes to form an open/open graph.

mkLast :: GraphRep g => n O C -> g n O C #

Create a graph from a last node

mkBranch :: (GraphRep g, HooplNode n) => Label -> g n O C #

Create a graph that branches to a label

mkLabel :: (GraphRep g, HooplNode n) => Label -> g n C O #

Create a graph that defines a label

mkWhileDo #

Arguments

:: HooplNode n |
=> (Label -> Label -> AGraph n O C) | loop condition
-> AGraph n O O | body of the loop
-> AGraph n O O | the final while loop

class IfThenElseable x where #

Minimal complete definition

mkIfThenElse

Methods

mkIfThenElse #

Arguments

:: HooplNode n |
=> (Label -> Label -> AGraph n O C) | branch condition
-> AGraph n O x | code in the "then" branch
-> AGraph n O x | code in the "else" branch
-> AGraph n O x | resulting if-then-else construct

Translate a high-level if-then-else construct into an `AGraph`. The condition takes as arguments labels on the true-false branch and returns a single-entry, two-exit graph which exits to the two labels.

Instances

IfThenElseable C # |
Methods mkIfThenElse :: HooplNode n => (Label -> Label -> AGraph n O C) -> AGraph n O C -> AGraph n O C -> AGraph n O C #
IfThenElseable O # |
Methods mkIfThenElse :: HooplNode n => (Label -> Label -> AGraph n O C) -> AGraph n O O -> AGraph n O O -> AGraph n O O #

mkEntry :: GraphRep g => Block n O C -> g n O C #

Create a graph containing only an entry sequence

mkExit :: GraphRep g => Block n C O -> g n C O #

Create a graph containing only an exit sequence

class NonLocal n => HooplNode n where #

For some graph-construction operations and some optimizations, Hoopl must be able to create control-flow edges using a given node type `n`.

Minimal complete definition

mkBranchNode, mkLabelNode

Methods

mkBranchNode :: Label -> n O C #

Create a branch node, the source of a control-flow edge.

mkLabelNode :: Label -> n C O #

Create a label node, the target (destination) of a control-flow edge.

# Utilities for clients

firstXfer :: NonLocal n => (n C O -> f -> f) -> n C O -> FactBase f -> f #

A utility function so that a transfer function for a first node can be given just a fact; we handle the lookup. This function is planned to be made obsolete by changes in the dataflow interface.

distributeXfer :: NonLocal n => DataflowLattice f -> (n O C -> f -> f) -> n O C -> f -> FactBase f #

This utility function handles a common case in which a transfer function produces a single fact out of a last node, which is then distributed over the outgoing edges.

distributeFact :: NonLocal n => n O C -> f -> FactBase f #

This utility function handles a common case in which a transfer function for a last node takes the incoming fact unchanged and simply distributes that fact over the outgoing edges.

distributeFactBwd :: NonLocal n => n C O -> f -> FactBase f #

This utility function handles a common case in which a backward transfer function takes the incoming fact unchanged and tags it with the node's label.

successorFacts :: NonLocal n => n O C -> FactBase f -> [f] #

List of (unlabelled) facts from the successors of a last node

joinFacts :: DataflowLattice f -> Label -> [f] -> f #

Join a list of facts.

joinOutFacts :: NonLocal node => DataflowLattice f -> node O C -> FactBase f -> f #

Deprecated: should be replaced by 'joinFacts lat l (successorFacts n f)'; as is, it uses the wrong Label

joinMaps :: Ord k => JoinFun v -> JoinFun (Map k v) #

It's common to represent dataflow facts as a map from variables to some fact about the locations. For these maps, the join operation on the map can be expressed in terms of the join on each element of the codomain:

analyzeAndRewriteFwdBody :: forall m n f entries. (CheckpointMonad m, NonLocal n, LabelsPtr entries) => FwdPass m n f -> entries -> Body n -> FactBase f -> m (Body n, FactBase f) #

Forward dataflow analysis and rewriting for the special case of a Body. A set of entry points must be supplied; blocks not reachable from the set are thrown away.

analyzeAndRewriteBwdBody :: forall m n f entries. (CheckpointMonad m, NonLocal n, LabelsPtr entries) => BwdPass m n f -> entries -> Body n -> FactBase f -> m (Body n, FactBase f) #

Backward dataflow analysis and rewriting for the special case of a Body. A set of entry points must be supplied; blocks not reachable from the set are thrown away.

analyzeAndRewriteFwdOx :: forall m n f x. (CheckpointMonad m, NonLocal n) => FwdPass m n f -> Graph n O x -> f -> m (Graph n O x, FactBase f, MaybeO x f) #

Forward dataflow analysis and rewriting for the special case of a graph open at the entry. This special case relieves the client from having to specify a type signature for `NothingO`, which beginners might find confusing and experts might find annoying.

analyzeAndRewriteBwdOx :: forall m n f x. (CheckpointMonad m, NonLocal n) => BwdPass m n f -> Graph n O x -> Fact x f -> m (Graph n O x, FactBase f, f) #

Backward dataflow analysis and rewriting for the special case of a graph open at the entry. This special case relieves the client from having to specify a type signature for `NothingO`, which beginners might find confusing and experts might find annoying.

class IsSet set where #

Minimal complete definition

setNull, setSize, setMember, setEmpty, setSingleton, setInsert, setDelete, setUnion, setDifference, setIntersection, setIsSubsetOf, setFold, setElems, setFromList

Associated Types

type ElemOf set #

Methods

setNull :: set -> Bool #

setSize :: set -> Int #

setMember :: ElemOf set -> set -> Bool #

setEmpty :: set #

setSingleton :: ElemOf set -> set #

setInsert :: ElemOf set -> set -> set #

setDelete :: ElemOf set -> set -> set #

setUnion :: set -> set -> set #

setDifference :: set -> set -> set #

setIntersection :: set -> set -> set #

setIsSubsetOf :: set -> set -> Bool #

setFold :: (ElemOf set -> b -> b) -> b -> set -> b #

setElems :: set -> [ElemOf set] #

setFromList :: [ElemOf set] -> set #

Instances

IsSet UniqueSet # |

Associated Types

type ElemOf UniqueSet :: * #

Methods

setNull :: UniqueSet -> Bool #

setSize :: UniqueSet -> Int #

setMember :: ElemOf UniqueSet -> UniqueSet -> Bool #

setEmpty :: UniqueSet #

setSingleton :: ElemOf UniqueSet -> UniqueSet #

setInsert :: ElemOf UniqueSet -> UniqueSet -> UniqueSet #

setDelete :: ElemOf UniqueSet -> UniqueSet -> UniqueSet #

setUnion :: UniqueSet -> UniqueSet -> UniqueSet #

setDifference :: UniqueSet -> UniqueSet -> UniqueSet #

setIntersection :: UniqueSet -> UniqueSet -> UniqueSet #

setIsSubsetOf :: UniqueSet -> UniqueSet -> Bool #

setFold :: (ElemOf UniqueSet -> b -> b) -> b -> UniqueSet -> b #

setElems :: UniqueSet -> [ElemOf UniqueSet] #

setFromList :: [ElemOf UniqueSet] -> UniqueSet #

IsSet LabelSet # |

Associated Types

type ElemOf LabelSet :: * #

Methods

setNull :: LabelSet -> Bool #

setSize :: LabelSet -> Int #

setMember :: ElemOf LabelSet -> LabelSet -> Bool #

setEmpty :: LabelSet #

setSingleton :: ElemOf LabelSet -> LabelSet #

setInsert :: ElemOf LabelSet -> LabelSet -> LabelSet #

setDelete :: ElemOf LabelSet -> LabelSet -> LabelSet #

setUnion :: LabelSet -> LabelSet -> LabelSet #

setDifference :: LabelSet -> LabelSet -> LabelSet #

setIntersection :: LabelSet -> LabelSet -> LabelSet #

setIsSubsetOf :: LabelSet -> LabelSet -> Bool #

setFold :: (ElemOf LabelSet -> b -> b) -> b -> LabelSet -> b #

setElems :: LabelSet -> [ElemOf LabelSet] #

setFromList :: [ElemOf LabelSet] -> LabelSet #

setInsertList :: IsSet set => [ElemOf set] -> set -> set #

setDeleteList :: IsSet set => [ElemOf set] -> set -> set #

setUnions :: IsSet set => [set] -> set #

class IsMap map where #

Minimal complete definition

mapNull, mapSize, mapMember, mapLookup, mapFindWithDefault, mapEmpty, mapSingleton, mapInsert, mapInsertWith, mapDelete, mapUnion, mapUnionWithKey, mapDifference, mapIntersection, mapIsSubmapOf, mapMap, mapMapWithKey, mapFold, mapFoldWithKey, mapFilter, mapElems, mapKeys, mapToList, mapFromList, mapFromListWith

Associated Types

type KeyOf map #

Methods

mapNull :: map a -> Bool #

mapSize :: map a -> Int #

mapMember :: KeyOf map -> map a -> Bool #

mapLookup :: KeyOf map -> map a -> Maybe a #

mapFindWithDefault :: a -> KeyOf map -> map a -> a #

mapEmpty :: map a #

mapSingleton :: KeyOf map -> a -> map a #

mapInsert :: KeyOf map -> a -> map a -> map a #

mapInsertWith :: (a -> a -> a) -> KeyOf map -> a -> map a -> map a #

mapDelete :: KeyOf map -> map a -> map a #

mapUnion :: map a -> map a -> map a #

mapUnionWithKey :: (KeyOf map -> a -> a -> a) -> map a -> map a -> map a #

mapDifference :: map a -> map a -> map a #

mapIntersection :: map a -> map a -> map a #

mapIsSubmapOf :: Eq a => map a -> map a -> Bool #

mapMap :: (a -> b) -> map a -> map b #

mapMapWithKey :: (KeyOf map -> a -> b) -> map a -> map b #

mapFold :: (a -> b -> b) -> b -> map a -> b #

mapFoldWithKey :: (KeyOf map -> a -> b -> b) -> b -> map a -> b #

mapFilter :: (a -> Bool) -> map a -> map a #

mapElems :: map a -> [a] #

mapKeys :: map a -> [KeyOf map] #

mapToList :: map a -> [(KeyOf map, a)] #

mapFromList :: [(KeyOf map, a)] -> map a #

mapFromListWith :: (a -> a -> a) -> [(KeyOf map, a)] -> map a #

Instances

IsMap UniqueMap # |

Associated Types

type KeyOf (UniqueMap :: * -> *) :: * #

Methods

mapNull :: UniqueMap a -> Bool #

mapSize :: UniqueMap a -> Int #

mapMember :: KeyOf UniqueMap -> UniqueMap a -> Bool #

mapLookup :: KeyOf UniqueMap -> UniqueMap a -> Maybe a #

mapFindWithDefault :: a -> KeyOf UniqueMap -> UniqueMap a -> a #

mapEmpty :: UniqueMap a #

mapSingleton :: KeyOf UniqueMap -> a -> UniqueMap a #

mapInsert :: KeyOf UniqueMap -> a -> UniqueMap a -> UniqueMap a #

mapInsertWith :: (a -> a -> a) -> KeyOf UniqueMap -> a -> UniqueMap a -> UniqueMap a #

mapDelete :: KeyOf UniqueMap -> UniqueMap a -> UniqueMap a #

mapUnion :: UniqueMap a -> UniqueMap a -> UniqueMap a #

mapUnionWithKey :: (KeyOf UniqueMap -> a -> a -> a) -> UniqueMap a -> UniqueMap a -> UniqueMap a #

mapDifference :: UniqueMap a -> UniqueMap a -> UniqueMap a #

mapIntersection :: UniqueMap a -> UniqueMap a -> UniqueMap a #

mapIsSubmapOf :: Eq a => UniqueMap a -> UniqueMap a -> Bool #

mapMap :: (a -> b) -> UniqueMap a -> UniqueMap b #

mapMapWithKey :: (KeyOf UniqueMap -> a -> b) -> UniqueMap a -> UniqueMap b #

mapFold :: (a -> b -> b) -> b -> UniqueMap a -> b #

mapFoldWithKey :: (KeyOf UniqueMap -> a -> b -> b) -> b -> UniqueMap a -> b #

mapFilter :: (a -> Bool) -> UniqueMap a -> UniqueMap a #

mapElems :: UniqueMap a -> [a] #

mapKeys :: UniqueMap a -> [KeyOf UniqueMap] #

mapToList :: UniqueMap a -> [(KeyOf UniqueMap, a)] #

mapFromList :: [(KeyOf UniqueMap, a)] -> UniqueMap a #

mapFromListWith :: (a -> a -> a) -> [(KeyOf UniqueMap, a)] -> UniqueMap a #

IsMap LabelMap # |

Associated Types

type KeyOf (LabelMap :: * -> *) :: * #

Methods

mapNull :: LabelMap a -> Bool #

mapSize :: LabelMap a -> Int #

mapMember :: KeyOf LabelMap -> LabelMap a -> Bool #

mapLookup :: KeyOf LabelMap -> LabelMap a -> Maybe a #

mapFindWithDefault :: a -> KeyOf LabelMap -> LabelMap a -> a #

mapEmpty :: LabelMap a #

mapSingleton :: KeyOf LabelMap -> a -> LabelMap a #

mapInsert :: KeyOf LabelMap -> a -> LabelMap a -> LabelMap a #

mapInsertWith :: (a -> a -> a) -> KeyOf LabelMap -> a -> LabelMap a -> LabelMap a #

mapDelete :: KeyOf LabelMap -> LabelMap a -> LabelMap a #

mapUnion :: LabelMap a -> LabelMap a -> LabelMap a #

mapUnionWithKey :: (KeyOf LabelMap -> a -> a -> a) -> LabelMap a -> LabelMap a -> LabelMap a #

mapDifference :: LabelMap a -> LabelMap a -> LabelMap a #

mapIntersection :: LabelMap a -> LabelMap a -> LabelMap a #

mapIsSubmapOf :: Eq a => LabelMap a -> LabelMap a -> Bool #

mapMap :: (a -> b) -> LabelMap a -> LabelMap b #

mapMapWithKey :: (KeyOf LabelMap -> a -> b) -> LabelMap a -> LabelMap b #

mapFold :: (a -> b -> b) -> b -> LabelMap a -> b #

mapFoldWithKey :: (KeyOf LabelMap -> a -> b -> b) -> b -> LabelMap a -> b #

mapFilter :: (a -> Bool) -> LabelMap a -> LabelMap a #

mapElems :: LabelMap a -> [a] #

mapKeys :: LabelMap a -> [KeyOf LabelMap] #

mapToList :: LabelMap a -> [(KeyOf LabelMap, a)] #

mapFromList :: [(KeyOf LabelMap, a)] -> LabelMap a #

mapFromListWith :: (a -> a -> a) -> [(KeyOf LabelMap, a)] -> LabelMap a #

mapInsertList :: IsMap map => [(KeyOf map, a)] -> map a -> map a #

mapDeleteList :: IsMap map => [KeyOf map] -> map a -> map a #

mapUnions :: IsMap map => [map a] -> map a #

class Monad m => CheckpointMonad m where #

Obeys the following law: for all `m` `do { s <- checkpoint; m; restart s } == return ()`

Minimal complete definition

checkpoint, restart

Associated Types

type Checkpoint m #

Methods

checkpoint :: m (Checkpoint m) #

restart :: Checkpoint m -> m () #

Instances

CheckpointMonad SimpleUniqueMonad # |
Associated Types type Checkpoint (SimpleUniqueMonad :: * -> *) :: * # Methods checkpoint :: SimpleUniqueMonad (Checkpoint SimpleUniqueMonad) # restart :: Checkpoint SimpleUniqueMonad -> SimpleUniqueMonad () #
CheckpointMonad m => CheckpointMonad (InfiniteFuelMonad m) # |
Associated Types type Checkpoint (InfiniteFuelMonad m :: * -> *) :: * # Methods checkpoint :: InfiniteFuelMonad m (Checkpoint (InfiniteFuelMonad m)) # restart :: Checkpoint (InfiniteFuelMonad m) -> InfiniteFuelMonad m () #
CheckpointMonad m => CheckpointMonad (CheckingFuelMonad m) # |
Associated Types type Checkpoint (CheckingFuelMonad m :: * -> *) :: * # Methods checkpoint :: CheckingFuelMonad m (Checkpoint (CheckingFuelMonad m)) # restart :: Checkpoint (CheckingFuelMonad m) -> CheckingFuelMonad m () #

data DataflowLattice a #

A transfer function might want to use the logging flag to control debugging, as in for example, it updates just one element in a big finite map. We don't want Hoopl to show the whole fact, and only the transfer function knows exactly what changed.

Constructors

DataflowLattice |

Fields

- fact_name :: String
- fact_bot :: a
- fact_join :: JoinFun a

type JoinFun a = Label -> OldFact a -> NewFact a -> (ChangeFlag, a) #

newtype OldFact a #

Constructors

OldFact a |

newtype NewFact a #

Constructors

NewFact a |

type family Fact x f :: * #

Instances

type Fact C f # |
type Fact C f = FactBase f
type Fact O f # |
type Fact O f = f

mkFactBase :: forall f. DataflowLattice f -> [(Label, f)] -> FactBase f #

`mkFactBase` creates a `FactBase` from a list of (`Label`, fact) pairs. If the same label appears more than once, the relevant facts are joined.

data ChangeFlag #

Constructors

NoChange |
SomeChange |

Instances

Eq ChangeFlag # |
Methods (==) :: ChangeFlag -> ChangeFlag -> Bool # (/=) :: ChangeFlag -> ChangeFlag -> Bool #
Ord ChangeFlag # |
Methods compare :: ChangeFlag -> ChangeFlag -> Ordering # (<) :: ChangeFlag -> ChangeFlag -> Bool # (<=) :: ChangeFlag -> ChangeFlag -> Bool # (>) :: ChangeFlag -> ChangeFlag -> Bool # (>=) :: ChangeFlag -> ChangeFlag -> Bool # max :: ChangeFlag -> ChangeFlag -> ChangeFlag # min :: ChangeFlag -> ChangeFlag -> ChangeFlag #

changeIf :: Bool -> ChangeFlag #

data FwdPass m n f #

Constructors

FwdPass |

Fields

- fp_lattice :: DataflowLattice f
- fp_transfer :: FwdTransfer n f
- fp_rewrite :: FwdRewrite m n f

newtype FwdTransfer n f #

Constructors

FwdTransfer3 |

Fields

- getFTransfer3 :: (n C O -> f -> f, n O O -> f -> f, n O C -> f -> FactBase f)

mkFTransfer :: (forall e x. n e x -> f -> Fact x f) -> FwdTransfer n f #

mkFTransfer3 :: (n C O -> f -> f) -> (n O O -> f -> f) -> (n O C -> f -> FactBase f) -> FwdTransfer n f #

newtype FwdRewrite m n f #

Constructors

FwdRewrite3 |

Fields

- getFRewrite3 :: (n C O -> f -> m (Maybe (Graph n C O, FwdRewrite m n f)), n O O -> f -> m (Maybe (Graph n O O, FwdRewrite m n f)), n O C -> f -> m (Maybe (Graph n O C, FwdRewrite m n f)))

mkFRewrite :: FuelMonad m => (forall e x. n e x -> f -> m (Maybe (Graph n e x))) -> FwdRewrite m n f #

Functions passed to `mkFRewrite` should not be aware of the fuel supply. The result returned by `mkFRewrite` respects fuel.

mkFRewrite3 :: forall m n f. FuelMonad m => (n C O -> f -> m (Maybe (Graph n C O))) -> (n O O -> f -> m (Maybe (Graph n O O))) -> (n O C -> f -> m (Maybe (Graph n O C))) -> FwdRewrite m n f #

Functions passed to `mkFRewrite3` should not be aware of the fuel supply. The result returned by `mkFRewrite3` respects fuel.

noFwdRewrite :: Monad m => FwdRewrite m n f #

wrapFR #

Arguments

:: (forall e x. (n e x -> f -> m (Maybe (Graph n e x, FwdRewrite m n f))) -> n' e x -> f' -> m' (Maybe (Graph n' e x, FwdRewrite m' n' f'))) | This argument may assume that any function passed to it respects fuel, and it must return a result that respects fuel.
-> FwdRewrite m n f |
-> FwdRewrite m' n' f' |

wrapFR2 #

Arguments

:: (forall e x. (n1 e x -> f1 -> m1 (Maybe (Graph n1 e x, FwdRewrite m1 n1 f1))) -> (n2 e x -> f2 -> m2 (Maybe (Graph n2 e x, FwdRewrite m2 n2 f2))) -> n3 e x -> f3 -> m3 (Maybe (Graph n3 e x, FwdRewrite m3 n3 f3))) | This argument may assume that any function passed to it respects fuel, and it must return a result that respects fuel.
-> FwdRewrite m1 n1 f1 |
-> FwdRewrite m2 n2 f2 |
-> FwdRewrite m3 n3 f3 |

data BwdPass m n f #

Constructors

BwdPass |

Fields

- bp_lattice :: DataflowLattice f
- bp_transfer :: BwdTransfer n f
- bp_rewrite :: BwdRewrite m n f

newtype BwdTransfer n f #

Constructors

BwdTransfer3 |

Fields

- getBTransfer3 :: (n C O -> f -> f, n O O -> f -> f, n O C -> FactBase f -> f)

mkBTransfer :: (forall e x. n e x -> Fact x f -> f) -> BwdTransfer n f #

mkBTransfer3 :: (n C O -> f -> f) -> (n O O -> f -> f) -> (n O C -> FactBase f -> f) -> BwdTransfer n f #

wrapBR #

Arguments

:: (forall e x. Shape x -> (n e x -> Fact x f -> m (Maybe (Graph n e x, BwdRewrite m n f))) -> n' e x -> Fact x f' -> m' (Maybe (Graph n' e x, BwdRewrite m' n' f'))) | This argument may assume that any function passed to it respects fuel, and it must return a result that respects fuel.
-> BwdRewrite m n f |
-> BwdRewrite m' n' f' |

wrapBR2 #

Arguments

:: (forall e x. Shape x -> (n1 e x -> Fact x f1 -> m1 (Maybe (Graph n1 e x, BwdRewrite m1 n1 f1))) -> (n2 e x -> Fact x f2 -> m2 (Maybe (Graph n2 e x, BwdRewrite m2 n2 f2))) -> n3 e x -> Fact x f3 -> m3 (Maybe (Graph n3 e x, BwdRewrite m3 n3 f3))) | This argument may assume that any function passed to it respects fuel, and it must return a result that respects fuel.
-> BwdRewrite m1 n1 f1 |
-> BwdRewrite m2 n2 f2 |
-> BwdRewrite m3 n3 f3 |

newtype BwdRewrite m n f #

Constructors

BwdRewrite3 |

Fields

- getBRewrite3 :: (n C O -> f -> m (Maybe (Graph n C O, BwdRewrite m n f)), n O O -> f -> m (Maybe (Graph n O O, BwdRewrite m n f)), n O C -> FactBase f -> m (Maybe (Graph n O C, BwdRewrite m n f)))

mkBRewrite :: FuelMonad m => (forall e x. n e x -> Fact x f -> m (Maybe (Graph n e x))) -> BwdRewrite m n f #

Functions passed to `mkBRewrite` should not be aware of the fuel supply. The result returned by `mkBRewrite` respects fuel.

mkBRewrite3 :: forall m n f. FuelMonad m => (n C O -> f -> m (Maybe (Graph n C O))) -> (n O O -> f -> m (Maybe (Graph n O O))) -> (n O C -> FactBase f -> m (Maybe (Graph n O C))) -> BwdRewrite m n f #

Functions passed to `mkBRewrite3` should not be aware of the fuel supply. The result returned by `mkBRewrite3` respects fuel.

noBwdRewrite :: Monad m => BwdRewrite m n f #

analyzeAndRewriteFwd :: forall m n f e x entries. (CheckpointMonad m, NonLocal n, LabelsPtr entries) => FwdPass m n f -> MaybeC e entries -> Graph n e x -> Fact e f -> m (Graph n e x, FactBase f, MaybeO x f) #

if the graph being analyzed is open at the entry, there must be no other entry point, or all goes horribly wrong...

analyzeAndRewriteBwd :: (CheckpointMonad m, NonLocal n, LabelsPtr entries) => BwdPass m n f -> MaybeC e entries -> Graph n e x -> Fact x f -> m (Graph n e x, FactBase f, MaybeO e f) #

if the graph being analyzed is open at the exit, I don't quite understand the implications of possible other exits

# Respecting Fuel

A value of type `FwdRewrite` or `BwdRewrite` respects fuel if any function contained within the value satisfies the following properties:

- When fuel is exhausted, it always returns `Nothing`.
- When it returns `Just g rw`, it consumes exactly one unit of fuel, and new rewrite `rw` also respects fuel.

Provided that functions passed to `mkFRewrite`, `mkFRewrite3`, `mkBRewrite`, and `mkBRewrite3` are not aware of the fuel supply, the results respect fuel.

It is an unchecked run-time error for the argument passed to `wrapFR`, `wrapFR2`, `wrapBR`, or `warpBR2` to return a function that does not respect fuel.

data Label #

Instances

Eq Label # |
Methods (==) :: Label -> Label -> Bool # (/=) :: Label -> Label -> Bool #
Ord Label # |
Methods compare :: Label -> Label -> Ordering # (<) :: Label -> Label -> Bool # (<=) :: Label -> Label -> Bool # (>) :: Label -> Label -> Bool # (>=) :: Label -> Label -> Bool # max :: Label -> Label -> Label # min :: Label -> Label -> Label #
Show Label # |
Methods showsPrec :: Int -> Label -> ShowS Source # show :: Label -> String Source # showList :: [Label] -> ShowS Source #
LabelsPtr Label # |
Methods targetLabels :: Label -> [Label] #

freshLabel :: UniqueMonad m => m Label #

data LabelSet #

Instances

Eq LabelSet # |
Methods (==) :: LabelSet -> LabelSet -> Bool # (/=) :: LabelSet -> LabelSet -> Bool #
Ord LabelSet # |
Methods compare :: LabelSet -> LabelSet -> Ordering # (<) :: LabelSet -> LabelSet -> Bool # (<=) :: LabelSet -> LabelSet -> Bool # (>) :: LabelSet -> LabelSet -> Bool # (>=) :: LabelSet -> LabelSet -> Bool # max :: LabelSet -> LabelSet -> LabelSet # min :: LabelSet -> LabelSet -> LabelSet #
Show LabelSet # |
Methods showsPrec :: Int -> LabelSet -> ShowS Source # show :: LabelSet -> String Source # showList :: [LabelSet] -> ShowS Source #
IsSet LabelSet # |

Associated Types

type ElemOf LabelSet :: * #

Methods

setNull :: LabelSet -> Bool #

setSize :: LabelSet -> Int #

setMember :: ElemOf LabelSet -> LabelSet -> Bool #

setEmpty :: LabelSet #

setSingleton :: ElemOf LabelSet -> LabelSet #

setInsert :: ElemOf LabelSet -> LabelSet -> LabelSet #

setDelete :: ElemOf LabelSet -> LabelSet -> LabelSet #

setUnion :: LabelSet -> LabelSet -> LabelSet #

setDifference :: LabelSet -> LabelSet -> LabelSet #

setIntersection :: LabelSet -> LabelSet -> LabelSet #

setIsSubsetOf :: LabelSet -> LabelSet -> Bool #

setFold :: (ElemOf LabelSet -> b -> b) -> b -> LabelSet -> b #

setElems :: LabelSet -> [ElemOf LabelSet] #

setFromList :: [ElemOf LabelSet] -> LabelSet #

LabelsPtr LabelSet # |
Methods targetLabels :: LabelSet -> [Label] #
type ElemOf LabelSet # |
type ElemOf LabelSet = Label

data LabelMap v #

Instances

Functor LabelMap # |
Methods fmap :: (a -> b) -> LabelMap a -> LabelMap b Source # (<$) :: a -> LabelMap b -> LabelMap a Source #
Foldable LabelMap # |

Methods

fold :: Monoid m => LabelMap m -> m Source #

foldMap :: Monoid m => (a -> m) -> LabelMap a -> m Source #

foldr :: (a -> b -> b) -> b -> LabelMap a -> b Source #

foldr' :: (a -> b -> b) -> b -> LabelMap a -> b Source #

foldl :: (b -> a -> b) -> b -> LabelMap a -> b Source #

foldl' :: (b -> a -> b) -> b -> LabelMap a -> b Source #

foldr1 :: (a -> a -> a) -> LabelMap a -> a Source #

foldl1 :: (a -> a -> a) -> LabelMap a -> a Source #

toList :: LabelMap a -> [a] Source #

null :: LabelMap a -> Bool Source #

length :: LabelMap a -> Int Source #

elem :: Eq a => a -> LabelMap a -> Bool Source #

maximum :: Ord a => LabelMap a -> a Source #

minimum :: Ord a => LabelMap a -> a Source #

sum :: Num a => LabelMap a -> a Source #

product :: Num a => LabelMap a -> a Source #

Traversable LabelMap # |
Methods traverse :: Applicative f => (a -> f b) -> LabelMap a -> f (LabelMap b) Source # sequenceA :: Applicative f => LabelMap (f a) -> f (LabelMap a) Source # mapM :: Monad m => (a -> m b) -> LabelMap a -> m (LabelMap b) Source # sequence :: Monad m => LabelMap (m a) -> m (LabelMap a) Source #
IsMap LabelMap # |

Associated Types

type KeyOf (LabelMap :: * -> *) :: * #

Methods

mapNull :: LabelMap a -> Bool #

mapSize :: LabelMap a -> Int #

mapMember :: KeyOf LabelMap -> LabelMap a -> Bool #

mapLookup :: KeyOf LabelMap -> LabelMap a -> Maybe a #

mapFindWithDefault :: a -> KeyOf LabelMap -> LabelMap a -> a #

mapEmpty :: LabelMap a #

mapSingleton :: KeyOf LabelMap -> a -> LabelMap a #

mapInsert :: KeyOf LabelMap -> a -> LabelMap a -> LabelMap a #

mapInsertWith :: (a -> a -> a) -> KeyOf LabelMap -> a -> LabelMap a -> LabelMap a #

mapDelete :: KeyOf LabelMap -> LabelMap a -> LabelMap a #

mapUnion :: LabelMap a -> LabelMap a -> LabelMap a #

mapUnionWithKey :: (KeyOf LabelMap -> a -> a -> a) -> LabelMap a -> LabelMap a -> LabelMap a #

mapDifference :: LabelMap a -> LabelMap a -> LabelMap a #

mapIntersection :: LabelMap a -> LabelMap a -> LabelMap a #

mapIsSubmapOf :: Eq a => LabelMap a -> LabelMap a -> Bool #

mapMap :: (a -> b) -> LabelMap a -> LabelMap b #

mapMapWithKey :: (KeyOf LabelMap -> a -> b) -> LabelMap a -> LabelMap b #

mapFold :: (a -> b -> b) -> b -> LabelMap a -> b #

mapFoldWithKey :: (KeyOf LabelMap -> a -> b -> b) -> b -> LabelMap a -> b #

mapFilter :: (a -> Bool) -> LabelMap a -> LabelMap a #

mapElems :: LabelMap a -> [a] #

mapKeys :: LabelMap a -> [KeyOf LabelMap] #

mapToList :: LabelMap a -> [(KeyOf LabelMap, a)] #

mapFromList :: [(KeyOf LabelMap, a)] -> LabelMap a #

mapFromListWith :: (a -> a -> a) -> [(KeyOf LabelMap, a)] -> LabelMap a #

Eq v => Eq (LabelMap v) # |
Methods (==) :: LabelMap v -> LabelMap v -> Bool # (/=) :: LabelMap v -> LabelMap v -> Bool #
Ord v => Ord (LabelMap v) # |
Methods compare :: LabelMap v -> LabelMap v -> Ordering # (<) :: LabelMap v -> LabelMap v -> Bool # (<=) :: LabelMap v -> LabelMap v -> Bool # (>) :: LabelMap v -> LabelMap v -> Bool # (>=) :: LabelMap v -> LabelMap v -> Bool # max :: LabelMap v -> LabelMap v -> LabelMap v # min :: LabelMap v -> LabelMap v -> LabelMap v #
Show v => Show (LabelMap v) # |
Methods showsPrec :: Int -> LabelMap v -> ShowS Source # show :: LabelMap v -> String Source # showList :: [LabelMap v] -> ShowS Source #
type KeyOf LabelMap # |
type KeyOf LabelMap = Label

type FactBase f = LabelMap f #

noFacts :: FactBase f #

lookupFact :: Label -> FactBase f -> Maybe f #

uniqueToLbl :: Unique -> Label #

lblToUnique :: Label -> Unique #

data Pointed t b a where #

Adds top, bottom, or both to help form a lattice

The type parameters `t` and `b` are used to say whether top and bottom elements have been added. The analogy with `Block` is nearly exact:

- A `Block` is closed at the entry if and only if it has a first node; a `Pointed` is closed at the top if and only if it has a top element.
- A `Block` is closed at the exit if and only if it has a last node; a `Pointed` is closed at the bottom if and only if it has a bottom element.

We thus have four possible types, of which three are interesting:

`Pointed C C a`
  Type `a` extended with both top and bottom elements.
`Pointed C O a`
  Type `a` extended with a top element only. (Presumably `a` comes equipped with a bottom element of its own.)
`Pointed O C a`
  Type `a` extended with a bottom element only.
`Pointed O O a`
  Isomorphic to `a`, and therefore not interesting.

The advantage of all this GADT-ishness is that the constructors `Bot`, `Top`, and `PElem` can all be used polymorphically.

A 'Pointed t b' type is an instance of `Functor` and `Show`.

Constructors

Bot :: Pointed t C a |
PElem :: a -> Pointed t b a |
Top :: Pointed C b a |

Instances

Functor (Pointed t b) # |
Methods fmap :: (a -> b) -> Pointed t b a -> Pointed t b b Source # (<$) :: a -> Pointed t b b -> Pointed t b a Source #
Eq a => Eq (Pointed t b a) # |
Methods (==) :: Pointed t b a -> Pointed t b a -> Bool # (/=) :: Pointed t b a -> Pointed t b a -> Bool #
Ord a => Ord (Pointed t b a) # |
Methods compare :: Pointed t b a -> Pointed t b a -> Ordering # (<) :: Pointed t b a -> Pointed t b a -> Bool # (<=) :: Pointed t b a -> Pointed t b a -> Bool # (>) :: Pointed t b a -> Pointed t b a -> Bool # (>=) :: Pointed t b a -> Pointed t b a -> Bool # max :: Pointed t b a -> Pointed t b a -> Pointed t b a # min :: Pointed t b a -> Pointed t b a -> Pointed t b a #
Show a => Show (Pointed t b a) # |
Methods showsPrec :: Int -> Pointed t b a -> ShowS Source # show :: Pointed t b a -> String Source # showList :: [Pointed t b a] -> ShowS Source #

addPoints :: String -> JoinFun a -> DataflowLattice (Pointed t C a) #

Given a join function and a name, creates a semi lattice by adding a bottom element, and possibly a top element also. A specialized version of `addPoints'`.

addPoints' :: forall a t. String -> (Label -> OldFact a -> NewFact a -> (ChangeFlag, Pointed t C a)) -> DataflowLattice (Pointed t C a) #

A more general case for creating a new lattice

addTop :: DataflowLattice a -> DataflowLattice (WithTop a) #

Given a join function and a name, creates a semi lattice by adding a top element but no bottom element. Caller must supply the bottom element.

addTop' :: forall a. String -> a -> (Label -> OldFact a -> NewFact a -> (ChangeFlag, WithTop a)) -> DataflowLattice (WithTop a) #

A more general case for creating a new lattice

liftJoinTop :: JoinFun a -> JoinFun (WithTop a) #

extendJoinDomain :: forall a. (Label -> OldFact a -> NewFact a -> (ChangeFlag, WithTop a)) -> JoinFun (WithTop a) #

type WithTop a = Pointed C O a #

Type `a` with a top element adjoined

type WithBot a = Pointed O C a #

Type `a` with a bottom element adjoined

type WithTopAndBot a = Pointed C C a #

Type `a` with top and bottom elements adjoined

thenFwdRw :: forall m n f. Monad m => FwdRewrite m n f -> FwdRewrite m n f -> FwdRewrite m n f #

deepFwdRw3 :: FuelMonad m => (n C O -> f -> m (Maybe (Graph n C O))) -> (n O O -> f -> m (Maybe (Graph n O O))) -> (n O C -> f -> m (Maybe (Graph n O C))) -> FwdRewrite m n f #

deepFwdRw :: FuelMonad m => (forall e x. n e x -> f -> m (Maybe (Graph n e x))) -> FwdRewrite m n f #

iterFwdRw :: forall m n f. Monad m => FwdRewrite m n f -> FwdRewrite m n f #

thenBwdRw :: forall m n f. Monad m => BwdRewrite m n f -> BwdRewrite m n f -> BwdRewrite m n f #

deepBwdRw3 :: FuelMonad m => (n C O -> f -> m (Maybe (Graph n C O))) -> (n O O -> f -> m (Maybe (Graph n O O))) -> (n O C -> FactBase f -> m (Maybe (Graph n O C))) -> BwdRewrite m n f #

deepBwdRw :: FuelMonad m => (forall e x. n e x -> Fact x f -> m (Maybe (Graph n e x))) -> BwdRewrite m n f #

iterBwdRw :: forall m n f. Monad m => BwdRewrite m n f -> BwdRewrite m n f #

pairFwd :: forall m n f f'. Monad m => FwdPass m n f -> FwdPass m n f' -> FwdPass m n (f, f') #

pairBwd :: forall m n f f'. Monad m => BwdPass m n f -> BwdPass m n f' -> BwdPass m n (f, f') #

pairLattice :: forall f f'. DataflowLattice f -> DataflowLattice f' -> DataflowLattice (f, f') #

type Fuel = Int #

infiniteFuel :: Fuel #

fuelRemaining :: FuelMonad m => m Fuel #

Find out how much fuel remains after a computation. Can be subtracted from initial fuel to get total consumption.

withFuel :: FuelMonad m => Maybe a -> m (Maybe a) #

class Monad m => FuelMonad m where #

Minimal complete definition

getFuel, setFuel

Methods

getFuel :: m Fuel #

setFuel :: Fuel -> m () #

Instances

Monad m => FuelMonad (InfiniteFuelMonad m) # |
Methods getFuel :: InfiniteFuelMonad m Fuel # setFuel :: Fuel -> InfiniteFuelMonad m () #
Monad m => FuelMonad (CheckingFuelMonad m) # |
Methods getFuel :: CheckingFuelMonad m Fuel # setFuel :: Fuel -> CheckingFuelMonad m () #

class FuelMonadT fm where #

Minimal complete definition

runWithFuel, liftFuel

Methods

runWithFuel :: (Monad m, FuelMonad (fm m)) => Fuel -> fm m a -> m a #

liftFuel :: (Monad m, FuelMonad (fm m)) => m a -> fm m a #

Instances

FuelMonadT InfiniteFuelMonad # |
Methods runWithFuel :: (Monad m, FuelMonad (InfiniteFuelMonad m)) => Fuel -> InfiniteFuelMonad m a -> m a # liftFuel :: (Monad m, FuelMonad (InfiniteFuelMonad m)) => m a -> InfiniteFuelMonad m a #
FuelMonadT CheckingFuelMonad # |
Methods runWithFuel :: (Monad m, FuelMonad (CheckingFuelMonad m)) => Fuel -> CheckingFuelMonad m a -> m a # liftFuel :: (Monad m, FuelMonad (CheckingFuelMonad m)) => m a -> CheckingFuelMonad m a #

data CheckingFuelMonad m a #

Instances

FuelMonadT CheckingFuelMonad # |
Methods runWithFuel :: (Monad m, FuelMonad (CheckingFuelMonad m)) => Fuel -> CheckingFuelMonad m a -> m a # liftFuel :: (Monad m, FuelMonad (CheckingFuelMonad m)) => m a -> CheckingFuelMonad m a #
Monad m => Monad (CheckingFuelMonad m) # |
Methods (>>=) :: CheckingFuelMonad m a -> (a -> CheckingFuelMonad m b) -> CheckingFuelMonad m b Source # (>>) :: CheckingFuelMonad m a -> CheckingFuelMonad m b -> CheckingFuelMonad m b Source # return :: a -> CheckingFuelMonad m a Source # fail :: String -> CheckingFuelMonad m a Source #
Monad m => Functor (CheckingFuelMonad m) # |
Methods fmap :: (a -> b) -> CheckingFuelMonad m a -> CheckingFuelMonad m b Source # (<$) :: a -> CheckingFuelMonad m b -> CheckingFuelMonad m a Source #
Monad m => Applicative (CheckingFuelMonad m) # |

Methods

pure :: a -> CheckingFuelMonad m a Source #

(<*>) :: CheckingFuelMonad m (a -> b) -> CheckingFuelMonad m a -> CheckingFuelMonad m b Source #

liftA2 :: (a -> b -> c) -> CheckingFuelMonad m a -> CheckingFuelMonad m b -> CheckingFuelMonad m c Source #

(*>) :: CheckingFuelMonad m a -> CheckingFuelMonad m b -> CheckingFuelMonad m b Source #

(<*) :: CheckingFuelMonad m a -> CheckingFuelMonad m b -> CheckingFuelMonad m a Source #

CheckpointMonad m => CheckpointMonad (CheckingFuelMonad m) # |
Associated Types type Checkpoint (CheckingFuelMonad m :: * -> *) :: * # Methods checkpoint :: CheckingFuelMonad m (Checkpoint (CheckingFuelMonad m)) # restart :: Checkpoint (CheckingFuelMonad m) -> CheckingFuelMonad m () #
UniqueMonad m => UniqueMonad (CheckingFuelMonad m) # |
Methods freshUnique :: CheckingFuelMonad m Unique #
Monad m => FuelMonad (CheckingFuelMonad m) # |
Methods getFuel :: CheckingFuelMonad m Fuel # setFuel :: Fuel -> CheckingFuelMonad m () #
type Checkpoint (CheckingFuelMonad m) # |
type Checkpoint (CheckingFuelMonad m) = (Fuel, Checkpoint m)

data InfiniteFuelMonad m a #

Instances

FuelMonadT InfiniteFuelMonad # |
Methods runWithFuel :: (Monad m, FuelMonad (InfiniteFuelMonad m)) => Fuel -> InfiniteFuelMonad m a -> m a # liftFuel :: (Monad m, FuelMonad (InfiniteFuelMonad m)) => m a -> InfiniteFuelMonad m a #
Monad m => Monad (InfiniteFuelMonad m) # |
Methods (>>=) :: InfiniteFuelMonad m a -> (a -> InfiniteFuelMonad m b) -> InfiniteFuelMonad m b Source # (>>) :: InfiniteFuelMonad m a -> InfiniteFuelMonad m b -> InfiniteFuelMonad m b Source # return :: a -> InfiniteFuelMonad m a Source # fail :: String -> InfiniteFuelMonad m a Source #
Monad m => Functor (InfiniteFuelMonad m) # |
Methods fmap :: (a -> b) -> InfiniteFuelMonad m a -> InfiniteFuelMonad m b Source # (<$) :: a -> InfiniteFuelMonad m b -> InfiniteFuelMonad m a Source #
Monad m => Applicative (InfiniteFuelMonad m) # |

Methods

pure :: a -> InfiniteFuelMonad m a Source #

(<*>) :: InfiniteFuelMonad m (a -> b) -> InfiniteFuelMonad m a -> InfiniteFuelMonad m b Source #

liftA2 :: (a -> b -> c) -> InfiniteFuelMonad m a -> InfiniteFuelMonad m b -> InfiniteFuelMonad m c Source #

(*>) :: InfiniteFuelMonad m a -> InfiniteFuelMonad m b -> InfiniteFuelMonad m b Source #

(<*) :: InfiniteFuelMonad m a -> InfiniteFuelMonad m b -> InfiniteFuelMonad m a Source #

CheckpointMonad m => CheckpointMonad (InfiniteFuelMonad m) # |
Associated Types type Checkpoint (InfiniteFuelMonad m :: * -> *) :: * # Methods checkpoint :: InfiniteFuelMonad m (Checkpoint (InfiniteFuelMonad m)) # restart :: Checkpoint (InfiniteFuelMonad m) -> InfiniteFuelMonad m () #
UniqueMonad m => UniqueMonad (InfiniteFuelMonad m) # |
Methods freshUnique :: InfiniteFuelMonad m Unique #
Monad m => FuelMonad (InfiniteFuelMonad m) # |
Methods getFuel :: InfiniteFuelMonad m Fuel # setFuel :: Fuel -> InfiniteFuelMonad m () #
type Checkpoint (InfiniteFuelMonad m) # |
type Checkpoint (InfiniteFuelMonad m) = Checkpoint m

type SimpleFuelMonad = CheckingFuelMonad SimpleUniqueMonad #

type Unique = Int #

intToUnique :: Int -> Unique #

data UniqueSet #

Instances

Eq UniqueSet # |
Methods (==) :: UniqueSet -> UniqueSet -> Bool # (/=) :: UniqueSet -> UniqueSet -> Bool #
Ord UniqueSet # |
Methods compare :: UniqueSet -> UniqueSet -> Ordering # (<) :: UniqueSet -> UniqueSet -> Bool # (<=) :: UniqueSet -> UniqueSet -> Bool # (>) :: UniqueSet -> UniqueSet -> Bool # (>=) :: UniqueSet -> UniqueSet -> Bool # max :: UniqueSet -> UniqueSet -> UniqueSet # min :: UniqueSet -> UniqueSet -> UniqueSet #
Show UniqueSet # |
Methods showsPrec :: Int -> UniqueSet -> ShowS Source # show :: UniqueSet -> String Source # showList :: [UniqueSet] -> ShowS Source #
IsSet UniqueSet # |

Associated Types

type ElemOf UniqueSet :: * #

Methods

setNull :: UniqueSet -> Bool #

setSize :: UniqueSet -> Int #

setMember :: ElemOf UniqueSet -> UniqueSet -> Bool #

setEmpty :: UniqueSet #

setSingleton :: ElemOf UniqueSet -> UniqueSet #

setInsert :: ElemOf UniqueSet -> UniqueSet -> UniqueSet #

setDelete :: ElemOf UniqueSet -> UniqueSet -> UniqueSet #

setUnion :: UniqueSet -> UniqueSet -> UniqueSet #

setDifference :: UniqueSet -> UniqueSet -> UniqueSet #

setIntersection :: UniqueSet -> UniqueSet -> UniqueSet #

setIsSubsetOf :: UniqueSet -> UniqueSet -> Bool #

setFold :: (ElemOf UniqueSet -> b -> b) -> b -> UniqueSet -> b #

setElems :: UniqueSet -> [ElemOf UniqueSet] #

setFromList :: [ElemOf UniqueSet] -> UniqueSet #

type ElemOf UniqueSet # |
type ElemOf UniqueSet = Unique

data UniqueMap v #

Instances

Functor UniqueMap # |
Methods fmap :: (a -> b) -> UniqueMap a -> UniqueMap b Source # (<$) :: a -> UniqueMap b -> UniqueMap a Source #
Foldable UniqueMap # |

Methods

fold :: Monoid m => UniqueMap m -> m Source #

foldMap :: Monoid m => (a -> m) -> UniqueMap a -> m Source #

foldr :: (a -> b -> b) -> b -> UniqueMap a -> b Source #

foldr' :: (a -> b -> b) -> b -> UniqueMap a -> b Source #

foldl :: (b -> a -> b) -> b -> UniqueMap a -> b Source #

foldl' :: (b -> a -> b) -> b -> UniqueMap a -> b Source #

foldr1 :: (a -> a -> a) -> UniqueMap a -> a Source #

foldl1 :: (a -> a -> a) -> UniqueMap a -> a Source #

toList :: UniqueMap a -> [a] Source #

null :: UniqueMap a -> Bool Source #

length :: UniqueMap a -> Int Source #

elem :: Eq a => a -> UniqueMap a -> Bool Source #

maximum :: Ord a => UniqueMap a -> a Source #

minimum :: Ord a => UniqueMap a -> a Source #

sum :: Num a => UniqueMap a -> a Source #

product :: Num a => UniqueMap a -> a Source #

Traversable UniqueMap # |
Methods traverse :: Applicative f => (a -> f b) -> UniqueMap a -> f (UniqueMap b) Source # sequenceA :: Applicative f => UniqueMap (f a) -> f (UniqueMap a) Source # mapM :: Monad m => (a -> m b) -> UniqueMap a -> m (UniqueMap b) Source # sequence :: Monad m => UniqueMap (m a) -> m (UniqueMap a) Source #
IsMap UniqueMap # |

Associated Types

type KeyOf (UniqueMap :: * -> *) :: * #

Methods

mapNull :: UniqueMap a -> Bool #

mapSize :: UniqueMap a -> Int #

mapMember :: KeyOf UniqueMap -> UniqueMap a -> Bool #

mapLookup :: KeyOf UniqueMap -> UniqueMap a -> Maybe a #

mapFindWithDefault :: a -> KeyOf UniqueMap -> UniqueMap a -> a #

mapEmpty :: UniqueMap a #

mapSingleton :: KeyOf UniqueMap -> a -> UniqueMap a #

mapInsert :: KeyOf UniqueMap -> a -> UniqueMap a -> UniqueMap a #

mapInsertWith :: (a -> a -> a) -> KeyOf UniqueMap -> a -> UniqueMap a -> UniqueMap a #

mapDelete :: KeyOf UniqueMap -> UniqueMap a -> UniqueMap a #

mapUnion :: UniqueMap a -> UniqueMap a -> UniqueMap a #

mapUnionWithKey :: (KeyOf UniqueMap -> a -> a -> a) -> UniqueMap a -> UniqueMap a -> UniqueMap a #

mapDifference :: UniqueMap a -> UniqueMap a -> UniqueMap a #

mapIntersection :: UniqueMap a -> UniqueMap a -> UniqueMap a #

mapIsSubmapOf :: Eq a => UniqueMap a -> UniqueMap a -> Bool #

mapMap :: (a -> b) -> UniqueMap a -> UniqueMap b #

mapMapWithKey :: (KeyOf UniqueMap -> a -> b) -> UniqueMap a -> UniqueMap b #

mapFold :: (a -> b -> b) -> b -> UniqueMap a -> b #

mapFoldWithKey :: (KeyOf UniqueMap -> a -> b -> b) -> b -> UniqueMap a -> b #

mapFilter :: (a -> Bool) -> UniqueMap a -> UniqueMap a #

mapElems :: UniqueMap a -> [a] #

mapKeys :: UniqueMap a -> [KeyOf UniqueMap] #

mapToList :: UniqueMap a -> [(KeyOf UniqueMap, a)] #

mapFromList :: [(KeyOf UniqueMap, a)] -> UniqueMap a #

mapFromListWith :: (a -> a -> a) -> [(KeyOf UniqueMap, a)] -> UniqueMap a #

Eq v => Eq (UniqueMap v) # |
Methods (==) :: UniqueMap v -> UniqueMap v -> Bool # (/=) :: UniqueMap v -> UniqueMap v -> Bool #
Ord v => Ord (UniqueMap v) # |
Methods compare :: UniqueMap v -> UniqueMap v -> Ordering # (<) :: UniqueMap v -> UniqueMap v -> Bool # (<=) :: UniqueMap v -> UniqueMap v -> Bool # (>) :: UniqueMap v -> UniqueMap v -> Bool # (>=) :: UniqueMap v -> UniqueMap v -> Bool # max :: UniqueMap v -> UniqueMap v -> UniqueMap v # min :: UniqueMap v -> UniqueMap v -> UniqueMap v #
Show v => Show (UniqueMap v) # |
Methods showsPrec :: Int -> UniqueMap v -> ShowS Source # show :: UniqueMap v -> String Source # showList :: [UniqueMap v] -> ShowS Source #
type KeyOf UniqueMap # |
type KeyOf UniqueMap = Unique

class Monad m => UniqueMonad m where #

Minimal complete definition

freshUnique

Methods

freshUnique :: m Unique #

Instances

UniqueMonad SimpleUniqueMonad # |
Methods freshUnique :: SimpleUniqueMonad Unique #
Monad m => UniqueMonad (UniqueMonadT m) # |
Methods freshUnique :: UniqueMonadT m Unique #
UniqueMonad m => UniqueMonad (InfiniteFuelMonad m) # |
Methods freshUnique :: InfiniteFuelMonad m Unique #
UniqueMonad m => UniqueMonad (CheckingFuelMonad m) # |
Methods freshUnique :: CheckingFuelMonad m Unique #

data SimpleUniqueMonad a #

Instances

Monad SimpleUniqueMonad # |
Methods (>>=) :: SimpleUniqueMonad a -> (a -> SimpleUniqueMonad b) -> SimpleUniqueMonad b Source # (>>) :: SimpleUniqueMonad a -> SimpleUniqueMonad b -> SimpleUniqueMonad b Source # return :: a -> SimpleUniqueMonad a Source # fail :: String -> SimpleUniqueMonad a Source #
Functor SimpleUniqueMonad # |
Methods fmap :: (a -> b) -> SimpleUniqueMonad a -> SimpleUniqueMonad b Source # (<$) :: a -> SimpleUniqueMonad b -> SimpleUniqueMonad a Source #
Applicative SimpleUniqueMonad # |

Methods

pure :: a -> SimpleUniqueMonad a Source #

(<*>) :: SimpleUniqueMonad (a -> b) -> SimpleUniqueMonad a -> SimpleUniqueMonad b Source #

liftA2 :: (a -> b -> c) -> SimpleUniqueMonad a -> SimpleUniqueMonad b -> SimpleUniqueMonad c Source #

(*>) :: SimpleUniqueMonad a -> SimpleUniqueMonad b -> SimpleUniqueMonad b Source #

(<*) :: SimpleUniqueMonad a -> SimpleUniqueMonad b -> SimpleUniqueMonad a Source #

CheckpointMonad SimpleUniqueMonad # |
Associated Types type Checkpoint (SimpleUniqueMonad :: * -> *) :: * # Methods checkpoint :: SimpleUniqueMonad (Checkpoint SimpleUniqueMonad) # restart :: Checkpoint SimpleUniqueMonad -> SimpleUniqueMonad () #
UniqueMonad SimpleUniqueMonad # |
Methods freshUnique :: SimpleUniqueMonad Unique #
type Checkpoint SimpleUniqueMonad # |
type Checkpoint SimpleUniqueMonad = [Unique]

runSimpleUniqueMonad :: SimpleUniqueMonad a -> a #

data UniqueMonadT m a #

Instances

Monad m => Monad (UniqueMonadT m) # |
Methods (>>=) :: UniqueMonadT m a -> (a -> UniqueMonadT m b) -> UniqueMonadT m b Source # (>>) :: UniqueMonadT m a -> UniqueMonadT m b -> UniqueMonadT m b Source # return :: a -> UniqueMonadT m a Source # fail :: String -> UniqueMonadT m a Source #
Monad m => Functor (UniqueMonadT m) # |
Methods fmap :: (a -> b) -> UniqueMonadT m a -> UniqueMonadT m b Source # (<$) :: a -> UniqueMonadT m b -> UniqueMonadT m a Source #
Monad m => Applicative (UniqueMonadT m) # |
Methods pure :: a -> UniqueMonadT m a Source # (<*>) :: UniqueMonadT m (a -> b) -> UniqueMonadT m a -> UniqueMonadT m b Source # liftA2 :: (a -> b -> c) -> UniqueMonadT m a -> UniqueMonadT m b -> UniqueMonadT m c Source # (*>) :: UniqueMonadT m a -> UniqueMonadT m b -> UniqueMonadT m b Source # (<*) :: UniqueMonadT m a -> UniqueMonadT m b -> UniqueMonadT m a Source #
Monad m => UniqueMonad (UniqueMonadT m) # |
Methods freshUnique :: UniqueMonadT m Unique #

runUniqueMonadT :: Monad m => UniqueMonadT m a -> m a #

uniqueToInt :: Unique -> Int #

type TraceFn = forall a. String -> a -> a #

debugFwdJoins :: forall m n f. Show f => TraceFn -> ChangePred -> FwdPass m n f -> FwdPass m n f #

Debugging combinators: Each combinator takes a dataflow pass and produces a dataflow pass that can output debugging messages. You provide the function, we call it with the applicable message.

The most common use case is probably to:

1. import `Trace`
2. pass `trace` as the 1st argument to the debug combinator
3. pass 'const true' as the 2nd argument to the debug combinator

There are two kinds of debugging messages for a join, depending on whether the join is higher in the lattice than the old fact: 1. If the join is higher, we show: + Join`L: f1 `join` f2 = f' where: + indicates a change L is the label where the join takes place f1 is the old fact at the label f2 is the new fact we are joining to f1 f' is the result of the join 2. _ Join`L: f2 <= f1 where: _ indicates no change L is the label where the join takes place f1 is the old fact at the label (which remains unchanged) f2 is the new fact we joined with f1

debugBwdJoins :: forall m n f. Show f => TraceFn -> ChangePred -> BwdPass m n f -> BwdPass m n f #

debugFwdTransfers :: forall m n f. Show f => TraceFn -> ShowN n -> FPred n f -> FwdPass m n f -> FwdPass m n f #

debugBwdTransfers :: forall m n f. Show f => TraceFn -> ShowN n -> BPred n f -> BwdPass m n f -> BwdPass m n f #

showGraph :: forall n e x. Showing n -> Graph n e x -> String #

showFactBase :: Show f => FactBase f -> String #

type Showing n = forall e x. n e x -> String #