Derive the definition of null
authorDavid Feuer <david.feuer@gmail.com>
Sun, 2 Apr 2017 20:20:20 +0000 (16:20 -0400)
committerDavid Feuer <David.Feuer@gmail.com>
Sun, 2 Apr 2017 20:20:22 +0000 (16:20 -0400)
commitbf5e0eab60a11d494671793740122e381a707c1a
tree08c50b4294e3265d994a1452f829aca59e3dacd4
parent911055689eca26c7c2713e251646fa35359acba3
Derive the definition of null

We can sometimes produce much better code by deriving the
definition of `null` rather than using the default. For example,
given

    data SnocList a = Lin | Snoc (SnocList a) a

the default definition of `null` will walk the whole list, but of
course we can stop as soon as we see `Snoc`. Similarly, if a
constructor contains some other `Foldable` type, we want to use its
`null` rather than folding over the structure.

Partially fixes Trac #13280

Reviewers: austin, bgamari, RyanGlScott

Reviewed By: RyanGlScott

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3402
compiler/prelude/PrelNames.hs
compiler/typecheck/TcGenFunctor.hs
docs/users_guide/8.4.1-notes.rst
docs/users_guide/glasgow_exts.rst
testsuite/tests/perf/should_run/DeriveNullTermination.hs [new file with mode: 0644]
testsuite/tests/perf/should_run/DeriveNullTermination.stdout [new file with mode: 0644]
testsuite/tests/perf/should_run/all.T