Desugar applications of 'seq' specially; fix Trac #1031
authorsimonpj@microsoft.com <unknown>
Fri, 16 Mar 2007 15:17:12 +0000 (15:17 +0000)
committersimonpj@microsoft.com <unknown>
Fri, 16 Mar 2007 15:17:12 +0000 (15:17 +0000)
commit3bdbcf162f78f28d3d50d30456aced559473b878
tree8976af47656abc25bbdb14ac41300ef6dc380f92
parented81632e2112e76b88890e9893fb808593d6e4df
Desugar applications of 'seq' specially; fix Trac #1031

Merge to 6.6 branch.  Test case is dsrun014.

Note [Desugaring seq]  cf Trac #1031
~~~~~~~~~~~~~~~~~~~~~
   f x y = x `seq` (y `seq` (# x,y #))

The [CoreSyn let/app invariant] means that, other things being equal, because
the argument to the outer 'seq' has an unlifted type, we'll use call-by-value thus:

   f x y = case (y `seq` (# x,y #)) of v -> x `seq` v

But that is bad for two reasons:
  (a) we now evaluate y before x, and
  (b) we can't bind v to an unboxed pair

Seq is very, very special!  So we recognise it right here, and desugar to
case x of _ -> case y of _ -> (# x,y #)

The special case would be valid for all calls to 'seq', but it's only *necessary*
for ones whose second argument has an unlifted type. So we only catch the latter
case here, to avoid unnecessary tests.
compiler/deSugar/DsUtils.lhs