Refactor derived Generic instances to reduce allocations
authorRyan Scott <ryan.gl.scott@gmail.com>
Sat, 18 Jun 2016 10:23:12 +0000 (12:23 +0200)
committerBen Gamari <ben@smart-cactus.org>
Sat, 18 Jun 2016 22:27:06 +0000 (00:27 +0200)
commit9649fc0ae45e006c2ed54cc5ea2414158949fadb
treefcc11b8f17032b950fcf2af043f05d8f3232fcf1
parent270d545d557352d5f264247987ee8388f0812187
Refactor derived Generic instances to reduce allocations

Previously, derived implementations of `to`/`from` in `Generic`
instances were wastefully putting extra `M1`s in every case, which led
to an O(n) increase in the number of coercions, resulting in a slowdown
during the typechecker phase.

This factors out the common `M1` in every case of a `to`/`from`
definition so that the typechecker has far fewer coercions to deal with.
For a datatype with 300 constructors, this change has been observed to
save almost 3 seconds of compilation time.

This is one step towards coming up with a solution for #5642.

Test Plan: ./validate

Reviewers: hvr, austin, simonpj, bgamari

Reviewed By: bgamari

Subscribers: basvandijk, carter, thomie, osa1

Differential Revision: https://phabricator.haskell.org/D2304

GHC Trac Issues: #5642
compiler/typecheck/TcGenGenerics.hs
testsuite/tests/generics/GenDerivOutput.stderr
testsuite/tests/generics/GenDerivOutput1_0.stderr
testsuite/tests/generics/GenDerivOutput1_1.stderr
testsuite/tests/generics/T10604/T10604_deriving.stderr
testsuite/tests/perf/compiler/T5642.hs
testsuite/tests/perf/compiler/all.T
testsuite/tests/perf/haddock/all.T