Improve the interaction of 'seq' and associated data types
authorsimonpj@microsoft.com <unknown>
Wed, 23 May 2007 11:48:18 +0000 (11:48 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 23 May 2007 11:48:18 +0000 (11:48 +0000)
commit9670d6643e55adeb15f998a0efd5799d499ea2a4
tree802ab26b0226dff0191e59e227e415aaced28b7c
parent800dba35d6ad4dde3d54a293687307f160a05dea
Improve the interaction of 'seq' and associated data types

Roman produced programs involving associated types that did not optimise well.
His programs were something like this:

  data family T a
  data instance T Int = MkT Bool Char

  bar :: T Int -> Int
  bar t = t `seq` loop 0
where
  loop = ...

You'd think that the `seq` should unbox 't' outside the loop, since
a (T Int) is just a MkT pair.

The most robust way to make this happen is for the simplifier to understand
a bit about type-family instances.   See
Note [Improving seq]
in Simplify.lhs.  We use FamInstEnv.topNormaliseType to do the interesting
work.

To make this happen I did a bit of refactoring to the simplifier
monad.

I'd previously done a very similar transformation in LiberateCase, but it
was happening too late.  So this patch takes it out of LiberateCase as
well as adding it to Simplify.
compiler/simplCore/LiberateCase.lhs
compiler/simplCore/SimplCore.lhs
compiler/simplCore/SimplEnv.lhs
compiler/simplCore/SimplMonad.lhs
compiler/simplCore/Simplify.lhs
compiler/types/FamInstEnv.lhs