• Simon Peyton Jones's avatar
    Fix the implementation of the "push rules" · b4f2afe7
    Simon Peyton Jones authored
    Richard pointed out (comment:12 of Trac #13025) that my
    implementation of the coercion "push rules", newly added
    in exprIsConAppMaybe by commit b4c3a668, 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.
    b4f2afe7
Coercion.hs 70.3 KB