Change the block representation (version bumped to 3.9.0.0)
authorSimon Marlow <marlowsd@gmail.com>
Wed, 4 Jul 2012 15:57:45 +0000 (16:57 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 4 Jul 2012 15:57:45 +0000 (16:57 +0100)
commitc6c6e93ed198a2a31820562d673b6af77aebb632
tree3ce5eff72745dbaa45a6b8e68edb962b7f8d8fda
parent1ef68d6f2a8a7e89a5ed4cc78e3fefc89dc8ccab
Change the block representation (version bumped to 3.9.0.0)

This patch implements the change to the block representation as agreed
with Norman.  I also took the liberty of doing a lot of refactoring
and rearrangement to make the code organisation more logical.  A
summary of the API changes is below.

Summary of refactorings:

 - Compiler.Hoopl.Block contains the Block datatype and all the
   operations on Blocks.  It seemed like a good idea to collect all
   this stuff together in one place.

 - Compiler.Hoopl.Graph now has the operations on Graphs.

 - Compiler.Hoopl.Util and Compiler.Hoopl.GraphUtil are no more; their
   contents have been moved to other homes.  (and a bit of duplicated
   functionality has been removed).

 - I removed the newtypes around Unique and Label, these are now just
   type synonyms.  The newtype wrappers were costing some performance in
   GHC, because in cases like mapToList the newtype isn't optimised away.

   This change might be controversial.  Feel free to complain.

Other changes:

 - Optimisations to the Dataflow algorithms.  I'm not actually using
   this implementation of Dataflow in GHC any more, instead I have a
   local copy specialised to our monad, for speed.  Nevertheless I've
   put some of the optimisations I'm using in the GHC version into the
   generic library version too.

Summary of API changes:

ADDED

 - IsMap(mapInsertWith, mapFromListWith)

 - mapGraphBlocks
   (was previously called graphMapBlocks, and not exported)

 - mapBlock'
   (strict version of mapBlock)

 - New API for working with Blocks:

    -- ** Predicates on Blocks
  , isEmptyBlock

    -- ** Constructing blocks
  , emptyBlock, blockCons, blockSnoc
  , blockJoinHead, blockJoinTail, blockJoin, blockJoinAny
  , blockAppend

    -- ** Deconstructing blocks
  , firstNode, lastNode, endNodes
  , blockSplitHead, blockSplitTail, blockSplit, blockSplitAny

    -- ** Modifying blocks
  , replaceFirstNode, replaceLastNode

    -- ** Converting to and from lists
  , blockToList, blockFromList

    -- ** Maps and folds
  , mapBlock, mapBlock', mapBlock3'
  , foldBlockNodesF, foldBlockNodesF3
  , foldBlockNodesB, foldBlockNodesB3

REMOVED

 - mapMaybeO, mapMaybeC
   (no need: we have Functor instances)

 - Block constructors are no longer exported
   (use the block API instead)

 - blockToNodeList, blockToNodeList', blockToNodeList'', blockToNodeList'''
   (use the block API instead)

 - tfFoldBlock, ScottBlock, scottFoldBlock, fbnf3,
   BlockResult(..), lookupBlock,
   (I don't know what any of these are for, if they're still important
   we could reinstate)

CHANGED

 - Compiler.Hoopl.GHC is now Compiler.Hoopl.Internals and exports some
   more stuff.

 - Label is not a newtype; type Label = Unique
 - Unique is not a newtype: type Unique = Int
   (these newtypes were adding overhead)

 - blockMapNodes3 is now mapBlock3'

 - Lots of internal refactoring and tidying up
25 files changed:
FAQ [deleted file]
LICENSE
hoopl.cabal
src/Compiler/Hoopl.hs
src/Compiler/Hoopl/Block.hs [new file with mode: 0644]
src/Compiler/Hoopl/Collections.hs
src/Compiler/Hoopl/Combinators.hs
src/Compiler/Hoopl/Dataflow.hs
src/Compiler/Hoopl/DataflowFold.hs
src/Compiler/Hoopl/Graph.hs
src/Compiler/Hoopl/GraphUtil.hs [deleted file]
src/Compiler/Hoopl/Internals.hs [new file with mode: 0644]
src/Compiler/Hoopl/Label.hs
src/Compiler/Hoopl/MkGraph.hs
src/Compiler/Hoopl/OldDataflow.hs
src/Compiler/Hoopl/Pointed.hs
src/Compiler/Hoopl/Show.hs
src/Compiler/Hoopl/Unique.hs
src/Compiler/Hoopl/Util.hs [deleted file]
src/Compiler/Hoopl/XUtil.hs
src/README [deleted file]
testing/EvalMonad.hs
testing/Main.hs
testing/Test.hs
testing/tests/ExpectedOutput