summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
4adc89c)
Remember local decls when no recompilation is required
ConDecl(..), ConDetails(..),
BangType(..), getBangType,
DeprecDecl(..), DeprecTxt,
ConDecl(..), ConDetails(..),
BangType(..), getBangType,
DeprecDecl(..), DeprecTxt,
- hsDeclName, instDeclName, tyClDeclName, tyClDeclNames,
+ hsDeclName, instDeclName, tyClDeclName, tyClDeclNames, tyClDeclSysNames,
isClassDecl, isSynDecl, isDataDecl, isIfaceSigDecl, countTyClDecls,
mkClassDeclSysNames, isIfaceRuleDecl, ifaceRuleDeclName,
getClassDeclSysNames, conDetailsTys
isClassDecl, isSynDecl, isDataDecl, isIfaceSigDecl, countTyClDecls,
mkClassDeclSysNames, isIfaceRuleDecl, ifaceRuleDeclName,
getClassDeclSysNames, conDetailsTys
Dealing with names
\begin{code}
Dealing with names
\begin{code}
+--------------------------------
tyClDeclName :: TyClDecl name pat -> name
tyClDeclName (IfaceSig name _ _ _) = name
tyClDeclName (TyData _ _ name _ _ _ _ _ _ _) = name
tyClDeclName :: TyClDecl name pat -> name
tyClDeclName (IfaceSig name _ _ _) = name
tyClDeclName (TyData _ _ name _ _ _ _ _ _ _) = name
tyClDeclName (ClassDecl _ name _ _ _ _ _ _) = name
tyClDeclName (ClassDecl _ name _ _ _ _ _ _) = name
+--------------------------------
tyClDeclNames :: Eq name => TyClDecl name pat -> [(name, SrcLoc)]
-- Returns all the binding names of the decl, along with their SrcLocs
-- The first one is guaranteed to be the name of the decl
tyClDeclNames :: Eq name => TyClDecl name pat -> [(name, SrcLoc)]
-- Returns all the binding names of the decl, along with their SrcLocs
-- The first one is guaranteed to be the name of the decl
tyClDeclNames (IfaceSig name _ _ loc) = [(name,loc)]
tyClDeclNames (IfaceSig name _ _ loc) = [(name,loc)]
+--------------------------------
+tyClDeclSysNames :: TyClDecl name pat -> [(name, SrcLoc)]
+-- Similar to tyClDeclNames, but returns the "implicit"
+-- or "system" names of the declaration
+
+tyClDeclSysNames (ClassDecl _ _ _ _ _ _ names loc) = [(n,loc) | n <- names]
+tyClDeclSysNames (TyData _ _ _ _ cons _ _ _ _ _) = [(wkr_name,loc) | ConDecl _ wkr_name _ _ _ loc <- cons]
+tyClDeclSysNames decl = []
+
+
+--------------------------------
type ClassDeclSysNames name = [name]
-- [tycon, datacon wrapper, datacon worker,
-- superclass selector 1, ..., superclass selector n]
type ClassDeclSysNames name = [name]
-- [tycon, datacon wrapper, datacon worker,
-- superclass selector 1, ..., superclass selector n]
import RnExpr ( rnExpr )
import RnNames ( getGlobalNames, exportsFromAvail )
import RnSource ( rnSourceDecls, rnTyClDecl, rnIfaceRuleDecl, rnInstDecl )
import RnExpr ( rnExpr )
import RnNames ( getGlobalNames, exportsFromAvail )
import RnSource ( rnSourceDecls, rnTyClDecl, rnIfaceRuleDecl, rnInstDecl )
-import RnIfaces ( slurpImpDecls, mkImportInfo,
+import RnIfaces ( slurpImpDecls, mkImportInfo, recordLocalSlurps,
getInterfaceExports, closeDecls,
RecompileRequired, outOfDate, recompileRequired
)
getInterfaceExports, closeDecls,
RecompileRequired, outOfDate, recompileRequired
)
needed = unionManyNameSets (map ruleDeclFVs rule_decls) `unionNameSets`
unionManyNameSets (map instDeclFVs inst_decls) `unionNameSets`
unionManyNameSets (map tyClDeclFVs tycl_decls)
needed = unionManyNameSets (map ruleDeclFVs rule_decls) `unionNameSets`
unionManyNameSets (map instDeclFVs inst_decls) `unionNameSets`
unionManyNameSets (map tyClDeclFVs tycl_decls)
+ local_names = foldl add emptyNameSet tycl_decls
+ add names decl = addListToNameSet names (map fst (tyClDeclSysNames decl ++ tyClDeclNames decl))
+ recordLocalSlurps local_names `thenRn_`
closeDecls decls needed
\end{code}
closeDecls decls needed
\end{code}
availNames (AvailTC n ns) = ns
-------------------------------------
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;
filterAvail :: RdrNameIE -- Wanted
-> AvailInfo -- Available
-> Maybe AvailInfo -- Resulting available;
AvailInfo, GenAvailInfo(..), Avails, Deprecations(..)
)
import HsSyn ( TyClDecl(..), InstDecl(..),
AvailInfo, GenAvailInfo(..), Avails, Deprecations(..)
)
import HsSyn ( TyClDecl(..), InstDecl(..),
- HsType(..), ConDecl(..),
- FixitySig(..), RuleDecl(..),
- tyClDeclNames
+ HsType(..), FixitySig(..), RuleDecl(..),
+ tyClDeclNames, tyClDeclSysNames
)
import RdrHsSyn ( RdrNameTyClDecl, RdrNameInstDecl, RdrNameRuleDecl,
extractHsTyRdrNames
)
import RdrHsSyn ( RdrNameTyClDecl, RdrNameInstDecl, RdrNameRuleDecl,
extractHsTyRdrNames
-> RdrNameTyClDecl
-> RnM d AvailInfo
-> RdrNameTyClDecl
-> RnM d AvailInfo
-getIfaceDeclBinders mod tycl_decl
- = getTyClDeclBinders mod tycl_decl `thenRn` \ avail ->
- getSysTyClDeclBinders mod tycl_decl `thenRn` \ extras ->
- returnRn (addSysAvails avail extras)
- -- Add the sys-binders to avail. When we import the decl,
- -- it's full_avail that will get added to the 'already-slurped' set (iSlurp)
- -- If we miss out sys-binders, we'll read the decl multiple times!
-
getTyClDeclBinders mod (IfaceSig var ty prags src_loc)
= newTopBinder mod var src_loc `thenRn` \ var_name ->
returnRn (Avail var_name)
getTyClDeclBinders mod tycl_decl
getTyClDeclBinders mod (IfaceSig var ty prags src_loc)
= newTopBinder mod var src_loc `thenRn` \ var_name ->
returnRn (Avail var_name)
getTyClDeclBinders mod tycl_decl
- = mapRn do_one (tyClDeclNames tycl_decl) `thenRn` \ (main_name:sub_names) ->
+ = new_top_bndrs mod (tyClDeclNames tycl_decl) `thenRn` \ (main_name:sub_names) ->
returnRn (AvailTC main_name (main_name : sub_names))
returnRn (AvailTC main_name (main_name : sub_names))
- where
- do_one (name,loc) = newTopBinder mod name loc
-\end{code}
-
-@getDeclSysBinders@ gets the implicit binders introduced by a decl.
-A the moment that's just the tycon and datacon that come with a class decl.
-They aren't returned by @getDeclBinders@ because they aren't in scope;
-but they {\em should} be put into the @DeclsMap@ of this module.
-
-Note that this excludes the default-method names of a class decl,
-and the dict fun of an instance decl, because both of these have
-bindings of their own elsewhere.
-\begin{code}
-getSysTyClDeclBinders mod (ClassDecl _ cname _ _ sigs _ names src_loc)
- = sequenceRn [newTopBinder mod n src_loc | n <- names]
+-----------------
+getIfaceDeclBinders mod (IfaceSig var ty prags src_loc)
+ = newTopBinder mod var src_loc `thenRn` \ var_name ->
+ returnRn (Avail var_name)
-getSysTyClDeclBinders mod (TyData _ _ _ _ cons _ _ _ _ _)
- = sequenceRn [newTopBinder mod wkr_name src_loc | ConDecl _ wkr_name _ _ _ src_loc <- cons]
+getIfaceDeclBinders mod tycl_decl
+ = new_top_bndrs mod (tyClDeclNames tycl_decl) `thenRn` \ (main_name:sub_names) ->
+ new_top_bndrs mod (tyClDeclSysNames tycl_decl) `thenRn` \ sys_names ->
+ returnRn (AvailTC main_name (main_name : (sys_names ++ sub_names)))
-getSysTyClDeclBinders mod other_decl
- = returnRn []
+-----------------
+new_top_bndrs mod names_w_locs
+ = sequenceRn [newTopBinder mod name loc | (name,loc) <- names_w_locs]
%*********************************************************
%* *
\subsection{Reading an interface file}
%*********************************************************
%* *
\subsection{Reading an interface file}
new_vslurp | isModuleInThisPackage mod = (imp_mods, addOneToNameSet imp_names main_name)
| otherwise = (extendModuleSet imp_mods mod, imp_names)
new_vslurp | isModuleInThisPackage mod = (imp_mods, addOneToNameSet imp_names main_name)
| otherwise = (extendModuleSet imp_mods mod, imp_names)
-recordLocalSlurps local_avails
+recordLocalSlurps new_names
= getIfacesRn `thenRn` \ ifaces ->
= getIfacesRn `thenRn` \ ifaces ->
- let
- new_slurped_names = foldl addAvailToNameSet (iSlurp ifaces) local_avails
- in
- setIfacesRn (ifaces { iSlurp = new_slurped_names })
+ setIfacesRn (ifaces { iSlurp = iSlurp ifaces `unionNameSets` new_names })
| HereItIs (Module, RdrNameTyClDecl)
importDecl name
| HereItIs (Module, RdrNameTyClDecl)
importDecl name
- = -- STEP 1: Check if it was loaded before beginning this module
- if isLocalName name then
- traceRn (text "Already (local)" <+> ppr name) `thenRn_`
- returnRn AlreadySlurped
- else
-
- -- STEP 2: Check if we've slurped it in while compiling this module
+ = -- STEP 1: Check if we've slurped it in while compiling this module
getIfacesRn `thenRn` \ ifaces ->
if name `elemNameSet` iSlurp ifaces then
returnRn AlreadySlurped
else
getIfacesRn `thenRn` \ ifaces ->
if name `elemNameSet` iSlurp ifaces then
returnRn AlreadySlurped
else
- -- STEP 3: Check if it's already in the type environment
+ -- STEP 2: Check if it's already in the type environment
getTypeEnvRn `thenRn` \ lookup ->
case lookup name of {
Just ty_thing | name `elemNameEnv` wiredInThingEnv
getTypeEnvRn `thenRn` \ lookup ->
case lookup name of {
Just ty_thing | name `elemNameEnv` wiredInThingEnv
- -- STEP 4: OK, we have to slurp it in from an interface file
+ -- STEP 3: OK, we have to slurp it in from an interface file
-- First load the interface file
traceRn nd_doc `thenRn_`
loadHomeInterface nd_doc name `thenRn_`
getIfacesRn `thenRn` \ ifaces ->
-- First load the interface file
traceRn nd_doc `thenRn_`
loadHomeInterface nd_doc name `thenRn_`
getIfacesRn `thenRn` \ ifaces ->
- -- STEP 5: Get the declaration out
+ -- STEP 4: Get the declaration out
let
(decls_map, _) = iDecls ifaces
in
let
(decls_map, _) = iDecls ifaces
in
(_, dups) = removeDups compare all_names
in
-- Check for duplicate definitions
(_, dups) = removeDups compare all_names
in
-- Check for duplicate definitions
- mapRn_ (addErrRn . dupDeclErr) dups `thenRn_`
+ mapRn_ (addErrRn . dupDeclErr) dups `thenRn_`
-- Record that locally-defined things are available
-- Record that locally-defined things are available
- recordLocalSlurps avails `thenRn_`
+ recordLocalSlurps (availsToNameSet avails) `thenRn_`
-- Build the environment
qualifyImports (moduleName this_mod)
-- Build the environment
qualifyImports (moduleName this_mod)
tcExtendTyVarEnvForMeths,
tcAddImportedIdInfo, tcInstId, tcLookupClass,
InstInfo(..), pprInstInfo, simpleInstInfoTyCon, simpleInstInfoTy,
tcExtendTyVarEnvForMeths,
tcAddImportedIdInfo, tcInstId, tcLookupClass,
InstInfo(..), pprInstInfo, simpleInstInfoTyCon, simpleInstInfoTy,
- newDFunName, tcExtendTyVarEnv
+ newDFunName, tcExtendTyVarEnv, tcGetInstEnv
-import InstEnv ( InstEnv, extendInstEnv )
+import InstEnv ( InstEnv, extendInstEnv, pprInstEnv )
import TcMonoType ( tcTyVars, tcHsSigType, kcHsSigType )
import TcSimplify ( tcSimplifyAndCheck )
import TcType ( zonkTcSigTyVars )
import TcMonoType ( tcTyVars, tcHsSigType, kcHsSigType )
import TcSimplify ( tcSimplifyAndCheck )
import TcType ( zonkTcSigTyVars )
returnTc inst_env'
where
bind x f = f x
returnTc inst_env'
where
bind x f = f x
module InstEnv (
DFunId, ClsInstEnv, InstEnv,
module InstEnv (
DFunId, ClsInstEnv, InstEnv,
- emptyInstEnv, extendInstEnv,
+ emptyInstEnv, extendInstEnv, pprInstEnv,
lookupInstEnv, InstLookupResult(..),
classInstEnv, simpleDFunClassTyCon
) where
lookupInstEnv, InstLookupResult(..),
classInstEnv, simpleDFunClassTyCon
) where
import Class ( Class )
import Var ( Id )
import Class ( Class )
import Var ( Id )
-import VarSet ( TyVarSet, unionVarSet, mkVarSet )
+import VarSet ( TyVarSet, unionVarSet, mkVarSet, varSetElems )
import VarEnv ( TyVarSubstEnv )
import Maybes ( MaybeErr(..), returnMaB, failMaB, thenMaB, maybeToBool )
import Name ( getSrcLoc )
import VarEnv ( TyVarSubstEnv )
import Maybes ( MaybeErr(..), returnMaB, failMaB, thenMaB, maybeToBool )
import Name ( getSrcLoc )
import TyCon ( TyCon )
import Outputable
import Unify ( matchTys, unifyTyListsX )
import TyCon ( TyCon )
import Outputable
import Unify ( matchTys, unifyTyListsX )
-import UniqFM ( UniqFM, lookupWithDefaultUFM, addToUFM, emptyUFM )
+import UniqFM ( UniqFM, lookupWithDefaultUFM, addToUFM, emptyUFM, eltsUFM )
import Id ( idType )
import ErrUtils ( Message )
import CmdLineOpts
import Id ( idType )
import ErrUtils ( Message )
import CmdLineOpts
where
(_,_,clas,[ty]) = splitDFunTy (idType dfun)
tycon = tyConAppTyCon ty
where
(_,_,clas,[ty]) = splitDFunTy (idType dfun)
tycon = tyConAppTyCon ty
+
+pprInstEnv :: InstEnv -> SDoc
+pprInstEnv env
+ = vcat [ brackets (pprWithCommas ppr (varSetElems tyvars)) <+>
+ brackets (pprWithCommas ppr tys) <+> ppr dfun
+ | cls_inst_env <- eltsUFM env
+ , (tyvars, tys, dfun) <- cls_inst_env
+ ]
\end{code}
%************************************************************************
\end{code}
%************************************************************************