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-13 09:02:13 +0100 |
| commit | 130e93aab220bdf14d08028771f83df210da340b (patch) | |
| tree | 4bd4ca6cbccea45d6c977122bc375fa101ff199a /compiler/rename | |
| parent | 8da785d59f5989b9a9df06386d5bd13f65435bc0 (diff) | |
| download | haskell-130e93aab220bdf14d08028771f83df210da340b.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
Diffstat (limited to 'compiler/rename')
| -rw-r--r-- | compiler/rename/RnEnv.hs | 1 | ||||
| -rw-r--r-- | compiler/rename/RnNames.hs | 42 | ||||
| -rw-r--r-- | compiler/rename/RnSplice.hs | 6 |
3 files changed, 33 insertions, 16 deletions
diff --git a/compiler/rename/RnEnv.hs b/compiler/rename/RnEnv.hs index 0794412051..28da6cb413 100644 --- a/compiler/rename/RnEnv.hs +++ b/compiler/rename/RnEnv.hs @@ -53,6 +53,7 @@ import RdrName import HscTypes import TcEnv ( tcLookupDataCon, tcLookupField, isBrackStage ) import TcRnMonad +import RdrHsSyn ( setRdrNameSpace ) import Id ( isRecordSelector ) import Name import NameSet diff --git a/compiler/rename/RnNames.hs b/compiler/rename/RnNames.hs index 036d6520fb..00381b3567 100644 --- a/compiler/rename/RnNames.hs +++ b/compiler/rename/RnNames.hs @@ -32,6 +32,7 @@ import NameSet import Avail import HscTypes import RdrName +import RdrHsSyn ( setRdrNameSpace ) import Outputable import Maybes import SrcLoc @@ -652,10 +653,14 @@ Then M's export_avails are (recall the AvailTC invariant from Avails.hs) C(C,T), T(T,T1,T2,T3) Notice that T appears *twice*, once as a child and once as a parent. From this we construct the imp_occ_env - C -> (C, C(C,T), Nothing + C -> (C, C(C,T), Nothing) T -> (T, T(T,T1,T2,T3), Just C) T1 -> (T1, T(T1,T2,T3), Nothing) -- similarly T2,T3 +If we say + import M( T(T1,T2) ) +then we get *two* Avails: C(T), T(T1,T2) + Note that the imp_occ_env will have entries for data constructors too, although we never look up data constructors. -} @@ -763,19 +768,30 @@ filterImports ifaces decl_spec (Just (want_hiding, L l import_items)) return ([(IEVar (L l name), trimAvail avail name)], []) IEThingAll (L l tc) -> do - (name, avail@(AvailTC name2 subs), mb_parent) <- lookup_name tc - let warns | null (drop 1 subs) = [DodgyImport tc] - | not (is_qual decl_spec) = [MissingImportList] - | otherwise = [] + (name, avail, mb_parent) <- lookup_name tc + let warns = case avail of + Avail {} -- e.g. f(..) + -> [DodgyImport tc] + + AvailTC _ subs + | null (drop 1 subs) -- e.g. T(..) where T is a synonym + -> [DodgyImport tc] + + | not (is_qual decl_spec) -- e.g. import M( T(..) ) + -> [MissingImportList] + + | otherwise + -> [] + + renamed_ie = IEThingAll (L l name) + sub_avails = case avail of + Avail {} -> [] + AvailTC name2 subs -> [(renamed_ie, AvailTC name2 (subs \\ [name]))] case mb_parent of - -- non-associated ty/cls - Nothing -> return ([(IEThingAll (L l name), avail)], warns) - -- associated ty - Just parent -> return ([(IEThingAll (L l name), - AvailTC name2 (subs \\ [name])), - (IEThingAll (L l name), - AvailTC parent [name])], - warns) + Nothing -> return ([(renamed_ie, avail)], warns) + -- non-associated ty/cls + Just parent -> return ((renamed_ie, AvailTC parent [name]) : sub_avails, warns) + -- associated type IEThingAbs (L l tc) | want_hiding -- hiding ( C ) diff --git a/compiler/rename/RnSplice.hs b/compiler/rename/RnSplice.hs index 5d12720e2c..737dcc9584 100644 --- a/compiler/rename/RnSplice.hs +++ b/compiler/rename/RnSplice.hs @@ -37,15 +37,15 @@ import {-# SOURCE #-} RnExpr ( rnLExpr ) import PrelNames ( isUnboundName ) import TcEnv ( checkWellStaged ) -import DsMeta ( liftName ) +import THNames ( liftName ) #ifdef GHCI import ErrUtils ( dumpIfSet_dyn_printer ) -import DsMeta ( decsQTyConName, expQTyConName, patQTyConName, typeQTyConName, ) import TcEnv ( tcMetaTy ) import Hooks import Var ( Id ) -import DsMeta ( quoteExpName, quotePatName, quoteDecName, quoteTypeName ) +import THNames ( quoteExpName, quotePatName, quoteDecName, quoteTypeName + , decsQTyConName, expQTyConName, patQTyConName, typeQTyConName, ) import Util import {-# SOURCE #-} TcExpr ( tcMonoExpr ) |
