+
+-- Rename kind signatures (signatures of indexed data types/newtypes and
+-- signatures of type functions)
+--
+-- * This function is parametrised by the routine handling the index
+-- variables. On the toplevel, these are defining occurences, whereas they
+-- are usage occurences for associated types.
+--
+rnTySig :: TyClDecl RdrName
+ -> (SDoc -> [LHsTyVarBndr RdrName] ->
+ ([LHsTyVarBndr Name] -> RnM (TyClDecl Name, FreeVars)) ->
+ RnM (TyClDecl Name, FreeVars))
+ -> RnM (TyClDecl Name, FreeVars)
+
+rnTySig (tydecl@TyData {tcdCtxt = context, tcdLName = tycon,
+ tcdTyVars = tyvars, tcdTyPats = mb_typats,
+ tcdCons = condecls, tcdKindSig = sig,
+ tcdDerivs = derivs})
+ bindIdxVars =
+ ASSERT( null condecls ) -- won't have constructors
+ ASSERT( isNothing mb_typats ) -- won't have type patterns
+ ASSERT( isNothing derivs ) -- won't have deriving
+ ASSERT( isJust sig ) -- will have kind signature
+ do { checkM (not . null $ tyvars) $ addErr needOneIdx -- #indexes >= 1
+ ; bindIdxVars (ksig_doc tycon) tyvars $ \tyvars' -> do {
+ ; tycon' <- lookupLocatedTopBndrRn tycon
+ ; context' <- rnContext (ksig_doc tycon) context
+ ; returnM (TyData {tcdND = tcdND tydecl, tcdCtxt = context',
+ tcdLName = tycon', tcdTyVars = tyvars',
+ tcdTyPats = Nothing, tcdKindSig = sig,
+ tcdCons = [], tcdDerivs = Nothing},
+ delFVs (map hsLTyVarName tyvars') $
+ extractHsCtxtTyNames context') } }
+ where
+
+rnTySig (tydecl@TyFunction {tcdLName = tycon, tcdTyVars = tyvars,
+ tcdKind = sig})
+ bindIdxVars =
+ do { checkM (not . null $ tyvars) $ addErr needOneIdx -- #indexes >= 1
+ ; bindIdxVars (ksig_doc tycon) tyvars $ \tyvars' -> do {
+ ; tycon' <- lookupLocatedTopBndrRn tycon
+ ; returnM (TyFunction {tcdLName = tycon', tcdTyVars = tyvars',
+ tcdIso = tcdIso tydecl, tcdKind = sig},
+ emptyFVs) } }
+
+ksig_doc tycon = text "In the kind signature for" <+> quotes (ppr tycon)
+needOneIdx = text "Kind signature requires at least one type index"
+
+-- Rename associated type declarations (in classes)
+--
+-- * This can be data declarations, type function signatures, and (default)
+-- type function equations.
+--
+rnATs :: [LTyClDecl RdrName] -> RnM ([LTyClDecl Name], FreeVars)
+rnATs ats = mapFvRn (wrapLocFstM rn_at) ats
+ where
+ rn_at (tydecl@TyData {}) = rnTySig tydecl lookupIdxVars
+ rn_at (tydecl@TyFunction {}) = rnTySig tydecl lookupIdxVars
+ rn_at (tydelc@TySynonym {}) = panic "!!!TODO: case not impl yet"
+ rn_at _ = panic "RnSource.rnATs: invalid TyClDecl"
+
+ lookupIdxVars _ tyvars cont = mappM lookupIdxVar tyvars >>= cont
+ --
+ -- Type index variables must be class parameters, which are the only
+ -- type variables in scope at this point.
+ lookupIdxVar (L l tyvar) =
+ do
+ name' <- lookupOccRn (hsTyVarName tyvar)
+ return $ L l (replaceTyVarName tyvar name')