diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2015-05-11 23:19:14 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2015-05-18 13:44:15 +0100 |
commit | ffc21506894c7887d3620423aaf86bc6113a1071 (patch) | |
tree | c36353b98b3e5eeb9a257b39d95e56f441aa36da /compiler/coreSyn | |
parent | 76024fdbad0f6daedd8757b974eace3314bd4eec (diff) | |
download | haskell-ffc21506894c7887d3620423aaf86bc6113a1071.tar.gz |
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
Diffstat (limited to 'compiler/coreSyn')
-rw-r--r-- | compiler/coreSyn/CoreLint.hs | 2 | ||||
-rw-r--r-- | compiler/coreSyn/MkCore.hs | 7 | ||||
-rw-r--r-- | compiler/coreSyn/PprCore.hs | 4 |
3 files changed, 7 insertions, 6 deletions
diff --git a/compiler/coreSyn/CoreLint.hs b/compiler/coreSyn/CoreLint.hs index ec0bb5e225..13285a5b3c 100644 --- a/compiler/coreSyn/CoreLint.hs +++ b/compiler/coreSyn/CoreLint.hs @@ -1570,7 +1570,7 @@ lookupIdInScope id oneTupleDataConId :: Id -- Should not happen -oneTupleDataConId = dataConWorkId (tupleCon BoxedTuple 1) +oneTupleDataConId = dataConWorkId (tupleDataCon Boxed 1) checkBndrIdInScope :: Var -> Var -> LintM () checkBndrIdInScope binder id diff --git a/compiler/coreSyn/MkCore.hs b/compiler/coreSyn/MkCore.hs index 6905641f56..3b76aef36d 100644 --- a/compiler/coreSyn/MkCore.hs +++ b/compiler/coreSyn/MkCore.hs @@ -379,7 +379,7 @@ mkCoreVarTupTy ids = mkBoxedTupleTy (map idType ids) mkCoreTup :: [CoreExpr] -> CoreExpr mkCoreTup [] = Var unitDataConId mkCoreTup [c] = c -mkCoreTup cs = mkConApp (tupleCon BoxedTuple (length cs)) +mkCoreTup cs = mkConApp (tupleDataCon Boxed (length cs)) (map (Type . exprType) cs ++ cs) -- | Build a big tuple holding the specified variables @@ -484,7 +484,7 @@ mkSmallTupleSelector [var] should_be_the_same_var _ scrut mkSmallTupleSelector vars the_var scrut_var scrut = ASSERT( notNull vars ) Case scrut scrut_var (idType the_var) - [(DataAlt (tupleCon BoxedTuple (length vars)), vars, Var the_var)] + [(DataAlt (tupleDataCon Boxed (length vars)), vars, Var the_var)] -- | A generalization of 'mkTupleSelector', allowing the body -- of the case to be an arbitrary expression. @@ -537,7 +537,8 @@ mkSmallTupleCase [var] body _scrut_var scrut = bindNonRec var scrut body mkSmallTupleCase vars body scrut_var scrut -- One branch no refinement? - = Case scrut scrut_var (exprType body) [(DataAlt (tupleCon BoxedTuple (length vars)), vars, body)] + = Case scrut scrut_var (exprType body) + [(DataAlt (tupleDataCon Boxed (length vars)), vars, body)] {- ************************************************************************ diff --git a/compiler/coreSyn/PprCore.hs b/compiler/coreSyn/PprCore.hs index 24abf1828a..ecea85021c 100644 --- a/compiler/coreSyn/PprCore.hs +++ b/compiler/coreSyn/PprCore.hs @@ -131,7 +131,7 @@ ppr_expr add_par expr@(App {}) let pp_args = sep (map pprArg args) val_args = dropWhile isTypeArg args -- Drop the type arguments for tuples - pp_tup_args = sep (punctuate comma (map pprCoreExpr val_args)) + pp_tup_args = pprWithCommas pprCoreExpr val_args in case fun of Var f -> case isDataConWorkId_maybe f of @@ -230,7 +230,7 @@ pprCoreAlt (con, args, rhs) ppr_case_pat :: OutputableBndr a => AltCon -> [a] -> SDoc ppr_case_pat (DataAlt dc) args | Just sort <- tyConTuple_maybe tc - = tupleParens sort (hsep (punctuate comma (map ppr_bndr args))) + = tupleParens sort (pprWithCommas ppr_bndr args) where ppr_bndr = pprBndr CaseBind tc = dataConTyCon dc |