import RnMonad
import Name ( Name, Provenance(..), ExportFlag(..), NamedThing(..),
ImportReason(..), getSrcLoc,
- mkLocalName, mkImportedLocalName, mkGlobalName, isSystemName,
+ mkLocalName, mkImportedLocalName, mkGlobalName, mkUnboundName,
+ mkIPName, isSystemName,
nameOccName, setNameModule, nameModule,
pprOccName, isLocallyDefined, nameUnique, nameOccName,
+ occNameUserString,
setNameProvenance, getNameProvenance, pprNameProvenance
)
import NameSet
import OccName ( OccName,
- mkDFunOcc,
+ mkDFunOcc, occNameUserString, occNameString,
occNameFlavour
)
import TysWiredIn ( tupleTyCon, unboxedTupleTyCon, listTyCon )
import Type ( funTyCon )
-import Module ( ModuleName, mkThisModule, mkVanillaModule, moduleName )
+import Module ( ModuleName, mkThisModule, moduleName )
import TyCon ( TyCon )
import FiniteMap
import Unique ( Unique, Uniquable(..) )
%*********************************************************
\begin{code}
+newImportedGlobalName :: ModuleName -> OccName -> Module -> RnM d Name
newImportedGlobalName mod_name occ mod
- = getNameSupplyRn `thenRn` \ (us, inst_ns, cache) ->
+ = getNameSupplyRn `thenRn` \ (us, inst_ns, cache, ipcache) ->
let
key = (mod_name, occ)
in
case lookupFM cache key of
Just name -> returnRn name
- Nothing -> setNameSupplyRn (us', inst_ns, new_cache) `thenRn_`
+ Nothing -> setNameSupplyRn (us', inst_ns, new_cache, ipcache) `thenRn_`
returnRn name
where
(us', us1) = splitUniqSupply us
updateProvenances :: [Name] -> RnM d ()
updateProvenances names
- = getNameSupplyRn `thenRn` \ (us, inst_ns, cache) ->
- setNameSupplyRn (us, inst_ns, update cache names)
+ = getNameSupplyRn `thenRn` \ (us, inst_ns, cache, ipcache) ->
+ setNameSupplyRn (us, inst_ns, update cache names, ipcache)
where
update cache [] = cache
update cache (name:names) = WARN( not (key `elemFM` cache), ppr name )
-- Make an imported global name, checking first to see if it's in the cache
mkImportedGlobalName :: ModuleName -> OccName -> RnM d Name
mkImportedGlobalName mod_name occ
- = newImportedGlobalName mod_name occ (mkVanillaModule mod_name)
+ = lookupModuleRn mod_name `thenRn` \ mod ->
+ newImportedGlobalName mod_name occ mod
+mkImportedGlobalFromRdrName :: RdrName -> RnM d Name
mkImportedGlobalFromRdrName rdr_name
| isQual rdr_name
= mkImportedGlobalName (rdrNameModule rdr_name) (rdrNameOcc rdr_name)
-> RnM d Name
newLocalTopBinder mod occ rec_exp_fn loc
= -- First check the cache
- getNameSupplyRn `thenRn` \ (us, inst_ns, cache) ->
+ getNameSupplyRn `thenRn` \ (us, inst_ns, cache, ipcache) ->
let
key = (moduleName mod,occ)
mk_prov name = LocalDef loc (rec_exp_fn name)
new_name = setNameProvenance name (mk_prov new_name)
new_cache = addToFM cache key new_name
in
- setNameSupplyRn (us, inst_ns, new_cache) `thenRn_`
+ setNameSupplyRn (us, inst_ns, new_cache, ipcache) `thenRn_`
returnRn new_name
-- Miss in the cache!
new_name = mkGlobalName uniq mod occ (mk_prov new_name)
new_cache = addToFM cache key new_name
in
- setNameSupplyRn (us', inst_ns, new_cache) `thenRn_`
+ setNameSupplyRn (us', inst_ns, new_cache, ipcache) `thenRn_`
returnRn new_name
+
+getIPName rdr_name
+ = getNameSupplyRn `thenRn` \ (us, inst_ns, cache, ipcache) ->
+ case lookupFM ipcache key of
+ Just name -> returnRn name
+ Nothing -> setNameSupplyRn (us', inst_ns, cache, new_ipcache) `thenRn_`
+ returnRn name
+ where
+ (us', us1) = splitUniqSupply us
+ uniq = uniqFromSupply us1
+ name = mkIPName uniq key
+ new_ipcache = addToFM ipcache key name
+ where key = (rdrNameOcc rdr_name)
\end{code}
%*********************************************************
\begin{code}
newDFunName :: (OccName, OccName) -> SrcLoc -> RnMS Name
newDFunName key@(cl_occ, tycon_occ) loc
- = newInstUniq key `thenRn` \ inst_uniq ->
- newImplicitBinder (mkDFunOcc cl_occ tycon_occ inst_uniq) loc
+ = newInstUniq string `thenRn` \ inst_uniq ->
+ newImplicitBinder (mkDFunOcc string inst_uniq) loc
+ where
+ -- Any string that is somewhat unique will do
+ string = occNameString cl_occ ++ occNameString tycon_occ
\end{code}
\begin{code}
returnRn ()
) `thenRn_`
- getNameSupplyRn `thenRn` \ (us, inst_ns, cache) ->
+ getNameSupplyRn `thenRn` \ (us, inst_ns, cache, ipcache) ->
getModeRn `thenRn` \ mode ->
let
n = length rdr_names_w_loc
-- Keep track of whether the name originally came from
-- an interface file.
in
- setNameSupplyRn (us', inst_ns, cache) `thenRn_`
+ setNameSupplyRn (us', inst_ns, cache, ipcache) `thenRn_`
let
new_name_env = addListToRdrEnv name_env (map fst rdr_names_w_loc `zip` names)
bindCoreLocalFVRn rdr_name enclosed_scope
= getSrcLocRn `thenRn` \ loc ->
getLocalNameEnv `thenRn` \ name_env ->
- getNameSupplyRn `thenRn` \ (us, inst_ns, cache) ->
+ getNameSupplyRn `thenRn` \ (us, inst_ns, cache, ipcache) ->
let
(us', us1) = splitUniqSupply us
uniq = uniqFromSupply us1
name = mkImportedLocalName uniq (rdrNameOcc rdr_name) loc
in
- setNameSupplyRn (us', inst_ns, cache) `thenRn_`
+ setNameSupplyRn (us', inst_ns, cache, ipcache) `thenRn_`
let
new_name_env = extendRdrEnv name_env rdr_name name
in
returnRn (thing, delListFromNameSet fvs names)
-------------------------------------
+bindUVarRn :: SDoc -> RdrName -> (Name -> RnMS (a, FreeVars)) -> RnMS (a, FreeVars)
+bindUVarRn = bindLocalRn
+
+-------------------------------------
extendTyVarEnvFVRn :: [HsTyVar Name] -> RnMS (a, FreeVars) -> RnMS (a, FreeVars)
-- This tiresome function is used only in rnDecl on InstDecl
extendTyVarEnvFVRn tyvars enclosed_scope
The name cache should have the correct provenance, though.
\begin{code}
-lookupImplicitOccRn :: RdrName -> RnMS Name
+lookupImplicitOccRn :: RdrName -> RnM d Name
lookupImplicitOccRn rdr_name = mkImportedGlobalFromRdrName rdr_name
\end{code}
plusExportAvails :: ExportAvails -> ExportAvails -> ExportAvails
plusExportAvails (m1, e1) (m2, e2)
- = (plusFM_C (++) m1 m2, plusUFM_C plusAvail e1 e2)
+ = (plusFM_C (++) m1 m2, plusAvailEnv e1 e2)
-- ToDo: wasteful: we do this once for each constructor!
\end{code}
\begin{code}
plusAvail (Avail n1) (Avail n2) = Avail n1
-plusAvail (AvailTC n1 ns1) (AvailTC n2 ns2) = AvailTC n1 (nub (ns1 ++ ns2))
+plusAvail (AvailTC n1 ns1) (AvailTC n2 ns2) = AvailTC n2 (nub (ns1 ++ ns2))
-- Added SOF 4/97
#ifdef DEBUG
plusAvail a1 a2 = pprPanic "RnEnv.plusAvail" (hsep [pprAvail a1,pprAvail a2])
#endif
+addAvail :: AvailEnv -> AvailInfo -> AvailEnv
+addAvail avails avail = addToNameEnv_C plusAvail avails (availName avail) avail
+
+emptyAvailEnv = emptyNameEnv
+unitAvailEnv :: AvailInfo -> AvailEnv
+unitAvailEnv a = unitNameEnv (availName a) a
+
+plusAvailEnv :: AvailEnv -> AvailEnv -> AvailEnv
+plusAvailEnv = plusNameEnv_C plusAvail
+
+availEnvElts = nameEnvElts
+
addAvailToNameSet :: NameSet -> AvailInfo -> NameSet
addAvailToNameSet names avail = addListToNameSet names (availNames avail)
availNames (Avail n) = [n]
availNames (AvailTC n ns) = ns
+addSysAvails :: AvailInfo -> [Name] -> AvailInfo
+addSysAvails avail [] = avail
+addSysAvails (AvailTC n ns) sys = AvailTC n (sys ++ ns)
+
filterAvail :: RdrNameIE -- Wanted
-> AvailInfo -- Available
-> Maybe AvailInfo -- Resulting available;
-- import A( op )
-- where op is a class operation
-filterAvail (IEThingAll _) avail@(AvailTC _ _) = Just avail
+filterAvail (IEThingAll _) avail@(AvailTC _ _) = Just avail
+ -- We don't complain even if the IE says T(..), but
+ -- no constrs/class ops of T are available
+ -- Instead that's caught with a warning by the caller
filterAvail ie avail = Nothing
+pprAvail :: AvailInfo -> SDoc
+pprAvail (AvailTC n ns) = ppr n <> case filter (/= n) ns of
+ [] -> empty
+ ns' -> parens (hsep (punctuate comma (map ppr ns')))
--- In interfaces, pprAvail gets given the OccName of the "host" thing
-pprAvail avail = getPprStyle $ \ sty ->
- if ifaceStyle sty then
- ppr_avail (pprOccName . nameOccName) avail
- else
- ppr_avail ppr avail
-
-ppr_avail pp_name (AvailTC n ns) = hsep [
- pp_name n,
- parens $ hsep $ punctuate comma $
- map pp_name ns
- ]
-ppr_avail pp_name (Avail n) = pp_name n
+pprAvail (Avail n) = ppr n
\end{code}
%************************************************************************
+
\begin{code}
-warnUnusedLocalBinds, warnUnusedTopNames, warnUnusedMatches :: [Name] -> RnM d ()
+warnUnusedLocalBinds, warnUnusedImports, warnUnusedMatches :: [Name] -> RnM d ()
-warnUnusedTopNames names
- | not opt_WarnUnusedBinds && not opt_WarnUnusedImports
- = returnRn () -- Don't force ns unless necessary
+warnUnusedImports names
+ | not opt_WarnUnusedImports
+ = returnRn () -- Don't force names unless necessary
| otherwise
- = warnUnusedBinds (\ is_local -> not is_local) names
+ = warnUnusedBinds (const True) names
warnUnusedLocalBinds ns
| not opt_WarnUnusedBinds = returnRn ()
- | otherwise = warnUnusedBinds (\ is_local -> is_local) ns
+ | otherwise = warnUnusedBinds (const True) ns
warnUnusedMatches names
| opt_WarnUnusedMatches = warnUnusedGroup (const True) names
-------------------------
-warnUnusedGroup :: (Bool -> Bool) -> [Name] -> RnM d ()
-warnUnusedGroup _ []
- = returnRn ()
+-- NOTE: the function passed to warnUnusedGroup is
+-- now always (const True) so we should be able to
+-- simplify the code slightly. I'm leaving it there
+-- for now just in case I havn't realised why it was there.
+-- Looks highly bogus to me. SLPJ Dec 99
+warnUnusedGroup :: (Bool -> Bool) -> [Name] -> RnM d ()
warnUnusedGroup emit_warning names
+ | null filtered_names = returnRn ()
| not (emit_warning is_local) = returnRn ()
| otherwise
= pushSrcLocRn def_loc $
addWarnRn $
- sep [msg <> colon, nest 4 (fsep (punctuate comma (map ppr names)))]
+ sep [msg <> colon, nest 4 (fsep (punctuate comma (map ppr filtered_names)))]
where
- name1 = head names
+ filtered_names = filter reportable names
+ name1 = head filtered_names
(is_local, def_loc, msg)
= case getNameProvenance name1 of
LocalDef loc _ -> (True, loc, text "Defined but not used")
(True, loc, text "Imported from" <+> quotes (ppr mod) <+>
text "but not used")
other -> (False, getSrcLoc name1, text "Strangely defined but not used")
+
+ reportable name = case occNameUserString (nameOccName name) of
+ ('_' : _) -> False
+ zz_other -> True
+ -- Haskell 98 encourages compilers to suppress warnings about
+ -- unused names in a pattern if they start with "_".
\end{code}
\begin{code}
$$
(ptext SLIT("in") <+> descriptor))
\end{code}
-