Commit c8295c0b authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Simplify variable naming in tcDataKindSig

Now that we are very consistent about tidying when converting
to IfaceSyn, we don't need to worry about accidental capture
of the "extra" type variables in tcDataKindSig.  (Previously
we gave them weird names like $a.)

However, it is nicer for the user if we don't gratuitously
re-use an in-scope name, so we take care not to do that
.
parent e5257f8f
...@@ -54,6 +54,7 @@ import TcType ...@@ -54,6 +54,7 @@ import TcType
import Type import Type
import TypeRep( Type(..) ) -- For the mkNakedXXX stuff import TypeRep( Type(..) ) -- For the mkNakedXXX stuff
import Kind import Kind
import RdrName( lookupLocalRdrOcc )
import Var import Var
import VarSet import VarSet
import TyCon import TyCon
...@@ -73,6 +74,7 @@ import Outputable ...@@ -73,6 +74,7 @@ import Outputable
import FastString import FastString
import Util import Util
import Data.Maybe( isNothing )
import Control.Monad ( unless, when, zipWithM ) import Control.Monad ( unless, when, zipWithM )
import PrelNames( ipClassName, funTyConKey ) import PrelNames( ipClassName, funTyConKey )
\end{code} \end{code}
...@@ -1318,20 +1320,22 @@ tcDataKindSig kind ...@@ -1318,20 +1320,22 @@ tcDataKindSig kind
= do { checkTc (isLiftedTypeKind res_kind) (badKindSig kind) = do { checkTc (isLiftedTypeKind res_kind) (badKindSig kind)
; span <- getSrcSpanM ; span <- getSrcSpanM
; us <- newUniqueSupply ; us <- newUniqueSupply
; rdr_env <- getLocalRdrEnv
; let uniqs = uniqsFromSupply us ; let uniqs = uniqsFromSupply us
; return [ mk_tv span uniq str kind occs = [ occ | str <- strs
| ((kind, str), uniq) <- arg_kinds `zip` dnames `zip` uniqs ] } , let occ = mkOccName tvName str
, isNothing (lookupLocalRdrOcc rdr_env occ) ]
-- Note [Avoid name clashes for associated data types]
; return [ mk_tv span uniq occ kind
| ((kind, occ), uniq) <- arg_kinds `zip` occs `zip` uniqs ] }
where where
(arg_kinds, res_kind) = splitKindFunTys kind (arg_kinds, res_kind) = splitKindFunTys kind
mk_tv loc uniq str kind = mkTyVar name kind mk_tv loc uniq occ kind
where = mkTyVar (mkInternalName uniq occ loc) kind
name = mkInternalName uniq occ loc
occ = mkOccName tvName str
dnames = map ('$' :) names -- Note [Avoid name clashes for associated data types] strs :: [String]
strs = [ c:cs | cs <- "" : strs, c <- ['a'..'z'] ]
names :: [String]
names = [ c:cs | cs <- "" : names, c <- ['a'..'z'] ]
badKindSig :: Kind -> SDoc badKindSig :: Kind -> SDoc
badKindSig kind badKindSig kind
...@@ -1343,19 +1347,17 @@ Note [Avoid name clashes for associated data types] ...@@ -1343,19 +1347,17 @@ Note [Avoid name clashes for associated data types]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider class C a b where Consider class C a b where
data D b :: * -> * data D b :: * -> *
When typechecking the decl for D, we'll invent an extra type variable for D, When typechecking the decl for D, we'll invent an extra type variable
to fill out its kind. We *don't* want this type variable to be 'a', because for D, to fill out its kind. Ideally we don't want this type variable
in an .hi file we'd get to be 'a', because when pretty printing we'll get
class C a b where class C a b where
data D b a data D b a0
which makes it look as if there are *two* type indices. But there aren't! (NB: the tidying happens in the conversion to IfaceSyn, which happens
So we use $a instead, which cannot clash with a user-written type variable. as part of pretty-printing a TyThing.)
Remember that type variable binders in interface files are just FastStrings,
not proper Names. That's why we look in the LocalRdrEnv to see what's in scope. This is
important only to get nice-looking output when doing ":info C" in GHCi.
(The tidying phase can't help here because we don't tidy TyCons. Another It isn't essential for correctness.
alternative would be to record the number of indexing parameters in the
interface file.)
%************************************************************************ %************************************************************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment