Fix typechecking for pattern synonym signatures
authorSimon Peyton Jones <simonpj@microsoft.com>
Tue, 22 Dec 2015 13:33:35 +0000 (14:33 +0100)
committerBen Gamari <ben@smart-cactus.org>
Tue, 22 Dec 2015 13:34:36 +0000 (14:34 +0100)
commitf40e122b7709c11d4ad20fd5cb26bf719235dbf1
treea335cef2c5f5ff1a1a0f6dc57aef45937c18d864
parent29928f29d53cfc7aceb7e8ab81967f784cf06159
Fix typechecking for pattern synonym signatures

Various tickets have revealed bad shortcomings in the typechecking of
pattern type synonyms.  Discussed a lot in (the latter part of)
Trac #11224.

This patch fixes the most complex issues:

- Both parser and renamer now treat pattern synonyms as an
  ordinary LHsSigType.  Nothing special.  Hooray.

- tcPatSynSig (now in TcPatSyn) typechecks the signature, and
  decomposes it into its pieces.
  See Note [Pattern synonym signatures]

- tcCheckPatSyn has had a lot of refactoring.
  See Note [Checking against a pattern signature]

The result is a lot tidier and more comprehensible.
Plus, it actually works!

NB: this patch doesn't actually address the precise
    target of #11224, namely "inlining pattern synonym
    does not preserve semantics".  That's an unrelated
    bug, with a separate patch.

ToDo: better documentation in the user manual

Test Plan: Validate

Reviewers: austin, hvr, goldfire

Subscribers: goldfire, mpickering, thomie, simonpj

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

GHC Trac Issues: #11224
23 files changed:
compiler/basicTypes/PatSyn.hs
compiler/ghci/RtClosureInspect.hs
compiler/hsSyn/HsBinds.hs
compiler/parser/Parser.y
compiler/typecheck/Inst.hs
compiler/typecheck/TcBinds.hs
compiler/typecheck/TcExpr.hs
compiler/typecheck/TcHsType.hs
compiler/typecheck/TcMType.hs
compiler/typecheck/TcPat.hs
compiler/typecheck/TcPatSyn.hs
compiler/typecheck/TcPatSyn.hs-boot
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcUnify.hs
compiler/types/TyCoRep.hs
testsuite/tests/patsyn/should_compile/MoreEx.hs [new file with mode: 0644]
testsuite/tests/patsyn/should_compile/T11224b.hs [new file with mode: 0644]
testsuite/tests/patsyn/should_compile/all.T
testsuite/tests/patsyn/should_fail/T11010.stderr
testsuite/tests/patsyn/should_fail/T9793-fail.stderr
testsuite/tests/patsyn/should_fail/as-pattern.stderr
testsuite/tests/patsyn/should_run/T11224.hs
testsuite/tests/patsyn/should_run/all.T