Refactor tuple constraints
authorSimon Peyton Jones <simonpj@microsoft.com>
Mon, 11 May 2015 22:19:14 +0000 (23:19 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Mon, 18 May 2015 12:44:15 +0000 (13:44 +0100)
commitffc21506894c7887d3620423aaf86bc6113a1071
treec36353b98b3e5eeb9a257b39d95e56f441aa36da
parent76024fdbad0f6daedd8757b974eace3314bd4eec
Refactor tuple constraints

Make tuple constraints be handled by a perfectly ordinary
type class, with the component constraints being the
superclasses:
    class (c1, c2) => (c2, c2)

This change was provoked by

  #10359  inability to re-use a given tuple
          constraint as a whole

  #9858   confusion between term tuples
          and constraint tuples

but it's generally a very nice simplification. We get rid of
 -  In Type, the TuplePred constructor of PredTree,
    and all the code that dealt with TuplePreds
 -  In TcEvidence, the constructors EvTupleMk, EvTupleSel

See Note [How tuples work] in TysWiredIn.

Of course, nothing is ever entirely simple. This one
proved quite fiddly.

- I did quite a bit of renaming, which makes this patch
  touch a lot of modules. In partiuclar tupleCon -> tupleDataCon.

- I made constraint tuples known-key rather than wired-in.
  This is different to boxed/unboxed tuples, but it proved
  awkward to have all the superclass selectors wired-in.
  Easier just to use the standard mechanims.

- While I was fiddling with known-key names, I split the TH Name
  definitions out of DsMeta into a new module THNames.  That meant
  that the known-key names can all be gathered in PrelInfo, without
  causing module loops.

- I found that the parser was parsing an import item like
      T( .. )
  as a *data constructor* T, and then using setRdrNameSpace to
  fix it.  Stupid!  So I changed the parser to parse a *type
  constructor* T, which means less use of setRdrNameSpace.

  I also improved setRdrNameSpace to behave better on Exact Names.
  Largely on priciple; I don't think it matters a lot.

- When compiling a data type declaration for a wired-in thing like
  tuples (,), or lists, we don't really need to look at the
  declaration.  We have the wired-in thing!  And not doing so avoids
  having to line up the uniques for data constructor workers etc.
  See Note [Declarations for wired-in things]

- I found that FunDeps.oclose wasn't taking superclasses into
  account; easily fixed.

- Some error message refactoring for invalid constraints in TcValidity

- Haddock needs to absorb the change too; so there is a submodule update
86 files changed:
compiler/basicTypes/BasicTypes.hs
compiler/basicTypes/DataCon.hs
compiler/basicTypes/RdrName.hs
compiler/basicTypes/Unique.hs
compiler/basicTypes/VarSet.hs
compiler/coreSyn/CoreLint.hs
compiler/coreSyn/MkCore.hs
compiler/coreSyn/PprCore.hs
compiler/deSugar/Check.hs
compiler/deSugar/DsArrows.hs
compiler/deSugar/DsBinds.hs
compiler/deSugar/DsCCall.hs
compiler/deSugar/DsExpr.hs
compiler/deSugar/DsMeta.hs
compiler/deSugar/Match.hs
compiler/ghc.cabal.in
compiler/ghci/RtClosureInspect.hs
compiler/hsSyn/Convert.hs
compiler/hsSyn/HsExpr.hs
compiler/hsSyn/HsPat.hs
compiler/hsSyn/HsTypes.hs
compiler/iface/BinIface.hs
compiler/iface/BuildTyCl.hs
compiler/iface/IfaceSyn.hs
compiler/iface/IfaceType.hs
compiler/iface/TcIface.hs
compiler/main/Constants.hs
compiler/main/HscMain.hs
compiler/parser/Parser.y
compiler/parser/RdrHsSyn.hs
compiler/prelude/PrelInfo.hs
compiler/prelude/PrelNames.hs
compiler/prelude/PrelRules.hs
compiler/prelude/PrimOp.hs
compiler/prelude/THNames.hs [new file with mode: 0644]
compiler/prelude/TysWiredIn.hs
compiler/rename/RnEnv.hs
compiler/rename/RnNames.hs
compiler/rename/RnSplice.hs
compiler/simplStg/UnariseStg.hs
compiler/specialise/Specialise.hs
compiler/stranal/WwLib.hs
compiler/typecheck/FunDeps.hs
compiler/typecheck/TcBinds.hs
compiler/typecheck/TcCanonical.hs
compiler/typecheck/TcErrors.hs
compiler/typecheck/TcEvidence.hs
compiler/typecheck/TcExpr.hs
compiler/typecheck/TcGenDeriv.hs
compiler/typecheck/TcHsSyn.hs
compiler/typecheck/TcHsType.hs
compiler/typecheck/TcInstDcls.hs
compiler/typecheck/TcInteract.hs
compiler/typecheck/TcMType.hs
compiler/typecheck/TcPat.hs
compiler/typecheck/TcRnMonad.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcSplice.hs
compiler/typecheck/TcTyClsDecls.hs
compiler/typecheck/TcType.hs
compiler/typecheck/TcValidity.hs
compiler/types/TyCon.hs
compiler/types/Type.hs
compiler/types/TypeRep.hs
compiler/vectorise/Vectorise/Builtins/Base.hs
compiler/vectorise/Vectorise/Builtins/Initialise.hs
compiler/vectorise/Vectorise/Utils/Closure.hs
libraries/ghc-prim/GHC/Classes.hs
libraries/ghc-prim/GHC/Tuple.hs
libraries/ghc-prim/GHC/Types.hs
testsuite/tests/indexed-types/should_fail/NotRelaxedExamples.stderr
testsuite/tests/indexed-types/should_fail/TyFamUndec.stderr
testsuite/tests/module/all.T
testsuite/tests/module/mod89.hs
testsuite/tests/module/mod89.stderr
testsuite/tests/typecheck/should_fail/T9858a.stderr
testsuite/tests/typecheck/should_fail/fd-loop.stderr
testsuite/tests/typecheck/should_fail/tcfail108.stderr
testsuite/tests/typecheck/should_fail/tcfail154.stderr
testsuite/tests/typecheck/should_fail/tcfail157.stderr
testsuite/tests/typecheck/should_fail/tcfail213.stderr
testsuite/tests/typecheck/should_fail/tcfail214.stderr
testsuite/tests/typecheck/should_fail/tcfail220.hsig
testsuite/tests/typecheck/should_fail/tcfail220.stderr
utils/genprimopcode/Main.hs
utils/haddock