Fix and refactor strict pattern bindings
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 25 Feb 2016 15:53:03 +0000 (15:53 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Fri, 26 Feb 2016 17:14:59 +0000 (17:14 +0000)
commite3f341f334d89c88f388d8e864ed8762d0890a64
treecbf769fab5ae1eb54324b33ec10b554488458b7b
parenta02611210b9846ee18de179c932915a838fdacb5
Fix and refactor strict pattern bindings

This patch was triggered by Trac #11601, where I discovered that
-XStrict was really not doing the right thing. In particular,

  f y = let !(Just x) = blah[y] in body[y,x]

This was evaluating 'blah' but not pattern matching it
against Just until x was demanded.  This is wrong.

The patch implements a new semantics which ensures that strict
patterns (i.e. ones with an explicit bang, or with -XStrict)
are evaluated fully when bound.

* There are extensive notes in DsUtils:
  Note [mkSelectorBinds]

* To do this I found I need one-tuples;
  see Note [One-tuples] in TysWiredIn

I updated the user manual to give the new semantics
12 files changed:
compiler/coreSyn/CoreLint.hs
compiler/coreSyn/MkCore.hs
compiler/deSugar/DsBinds.hs
compiler/deSugar/DsUtils.hs
compiler/deSugar/Match.hs
compiler/prelude/TysWiredIn.hs
docs/users_guide/glasgow_exts.rst
libraries/ghc-prim/GHC/Tuple.hs
testsuite/tests/deSugar/should_compile/T5455.stderr
testsuite/tests/deSugar/should_run/T11601.hs [new file with mode: 0644]
testsuite/tests/deSugar/should_run/T11601.stderr [new file with mode: 0644]
testsuite/tests/deSugar/should_run/all.T