Fix the implementation of the "push rules"
authorSimon Peyton Jones <simonpj@microsoft.com>
Fri, 6 Jan 2017 09:35:37 +0000 (09:35 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Fri, 6 Jan 2017 10:51:19 +0000 (10:51 +0000)
commitb4f2afe70ddbd0576b4eba3f82ba1ddc52e9b3bd
tree74b5534b1c427df695e2ca6b1f228ce40601c07b
parent3540d1e1a23926ce0a8a6ae83a36f5f6b2497ccf
Fix the implementation of the "push rules"

Richard pointed out (comment:12 of Trac #13025) that my
implementation of the coercion "push rules", newly added
in exprIsConAppMaybe by commit b4c3a66, wasn't quite right.

But in fact that means that the implementation of those same
rules in Simplify.simplCast was wrong too.

Hence this commit:

* Refactor the push rules so they are implemented in just
  one place (CoreSubst.pushCoArgs, pushCoTyArg, pushCoValArg)
  The code in Simplify gets simpler, which is nice.

* Fix the bug that Richard pointed out (to do with hetero-kinded
  coercions)

Then compiler performance worsened, which led mt do discover
two performance bugs:

* The smart constructor Coercion.mkNthCo didn't have a case
  for ForAllCos, which meant we stupidly build a complicated
  coercion where a simple one would do

* In OptCoercion there was one place where we used CoherenceCo
  (the data constructor) rather than mkCoherenceCo (the smart
  constructor), which meant that the the stupid complicated
  coercion wasn't optimised away

For reasons I don't fully understand, T5321Fun did 2% less compiler
allocation after all this, which is good.
compiler/coreSyn/CoreSubst.hs
compiler/simplCore/Simplify.hs
compiler/types/Coercion.hs
compiler/types/OptCoercion.hs
testsuite/tests/perf/compiler/all.T