Commit 3c4a732b authored by simonpj@microsoft.com's avatar simonpj@microsoft.com
Browse files

Remove unnecessary free-variables from renamer

The renamer used to be responsible for making sure that all interfaces
with instance decls (other than orphans) were loaded.  But TH makes that
impossible, so the typechecker does it, via checkWiredInTyCon.

This patch simply removes redundant additions to the free-variable set
in the renamer, which were there, I believe, solely to ensure that the 
instances came in.  Removing them should change nothing, but it's a 
useful clean up.
parent f750bec7
......@@ -118,6 +118,7 @@ loadInterfaceForName doc name
-- | An 'IfM' function to load the home interface for a wired-in thing,
-- so that we're sure that we see its instance declarations and rules
-- See Note [Loading instances]
loadWiredInHomeIface :: Name -> IfM lcl ()
loadWiredInHomeIface name
= ASSERT( isWiredInName name )
......@@ -134,6 +135,27 @@ loadSysInterface doc mod_name
Succeeded iface -> return iface }
\end{code}
Note [Loading instances]
~~~~~~~~~~~~~~~~~~~~~~~~
We need to make sure that we have at least *read* the interface files
for any module with an instance decl or RULE that we might want.
* If the instance decl is an orphan, we have a whole separate mechanism
(loadOprhanModules)
* If the instance decl not an orphan, then the act of looking at the
TyCon or Class will force in the defining module for the
TyCon/Class, and hence the instance decl
* BUT, if the TyCon is a wired-in TyCon, we don't really need its interface;
but we must make sure we read its interface in case it has instances or
rules. That is what LoadIface.loadWiredInHomeInterface does. It's called
from TcIface.{tcImportDecl, checkWiredInTyCon, ifCHeckWiredInThing}
All of this is done by the type checker. The renamer plays no role.
(It used to, but no longer.)
%*********************************************************
%* *
......
......@@ -105,6 +105,7 @@ tcImportDecl :: Name -> TcM TyThing
tcImportDecl name
| Just thing <- wiredInNameTyThing_maybe name
= do { initIfaceTcRn (loadWiredInHomeIface name)
-- See Note [Loading instances] in LoadIface
; return thing }
| otherwise
= do { traceIf (text "tcImportDecl" <+> ppr name)
......@@ -115,7 +116,8 @@ tcImportDecl name
checkWiredInTyCon :: TyCon -> TcM ()
-- Ensure that the home module of the TyCon (and hence its instances)
-- are loaded. See See Note [Loading instances] in LoadIface
-- It might not be a wired-in tycon (see the calls in TcUnify),
-- in which case this is a no-op.
checkWiredInTyCon tc
| not (isWiredInName tc_name)
......@@ -991,6 +993,7 @@ ifCheckWiredInThing :: Name -> IfL ()
-- Even though we are in an interface file, we want to make
-- sure the instances of a wired-in thing are loaded (imagine f :: Double -> Double)
-- Ditto want to ensure that RULES are loaded too
-- See Note [Loading instances] in LoadIface
ifCheckWiredInThing name
= do { mod <- getIfModule
-- Check whether we are typechecking the interface for this
......
......@@ -209,19 +209,16 @@ rnExpr e@(HsDo do_or_lc stmts body _)
rnExpr (ExplicitList _ exps)
= rnExprs exps `thenM` \ (exps', fvs) ->
returnM (ExplicitList placeHolderType exps', fvs `addOneFV` listTyCon_name)
returnM (ExplicitList placeHolderType exps', fvs)
rnExpr (ExplicitPArr _ exps)
= rnExprs exps `thenM` \ (exps', fvs) ->
returnM (ExplicitPArr placeHolderType exps', fvs)
rnExpr e@(ExplicitTuple exps boxity)
= checkTupSize tup_size `thenM_`
= checkTupSize (length exps) `thenM_`
rnExprs exps `thenM` \ (exps', fvs) ->
returnM (ExplicitTuple exps' boxity, fvs `addOneFV` tycon_name)
where
tup_size = length exps
tycon_name = tupleTyCon_name boxity tup_size
returnM (ExplicitTuple exps' boxity, fvs)
rnExpr (RecordCon con_id _ (HsRecordBinds rbinds))
= lookupLocatedOccRn con_id `thenM` \ conname ->
......
......@@ -603,7 +603,7 @@ rnPat (NPat lit mb_neg eq _)
) `thenM` \ (mb_neg', fvs2) ->
lookupSyntaxName eqName `thenM` \ (eq', fvs3) ->
returnM (NPat lit' mb_neg' eq' placeHolderType,
fvs1 `plusFV` fvs2 `plusFV` fvs3 `addOneFV` eqClassName)
fvs1 `plusFV` fvs2 `plusFV` fvs3)
-- Needed to find equality on pattern
rnPat (NPlusKPat name lit _ _)
......@@ -612,7 +612,7 @@ rnPat (NPlusKPat name lit _ _)
lookupSyntaxName minusName `thenM` \ (minus, fvs2) ->
lookupSyntaxName geName `thenM` \ (ge, fvs3) ->
returnM (NPlusKPat name' lit' ge minus,
fvs1 `plusFV` fvs2 `plusFV` fvs3 `addOneFV` integralClassName)
fvs1 `plusFV` fvs2 `plusFV` fvs3)
-- The Report says that n+k patterns must be in Integral
rnPat (LazyPat pat)
......@@ -637,23 +637,19 @@ rnPat (ParPat pat)
rnPat (ListPat pats _)
= rnLPats pats `thenM` \ (patslist, fvs) ->
returnM (ListPat patslist placeHolderType, fvs `addOneFV` listTyCon_name)
returnM (ListPat patslist placeHolderType, fvs)
rnPat (PArrPat pats _)
= rnLPats pats `thenM` \ (patslist, fvs) ->
returnM (PArrPat patslist placeHolderType,
fvs `plusFV` implicit_fvs `addOneFV` parrTyCon_name)
fvs `plusFV` implicit_fvs)
where
implicit_fvs = mkFVs [lengthPName, indexPName]
rnPat (TuplePat pats boxed _)
= checkTupSize tup_size `thenM_`
= checkTupSize (length pats) `thenM_`
rnLPats pats `thenM` \ (patslist, fvs) ->
returnM (TuplePat patslist boxed placeHolderType,
fvs `addOneFV` tycon_name)
where
tup_size = length pats
tycon_name = tupleTyCon_name boxed tup_size
returnM (TuplePat patslist boxed placeHolderType, fvs)
rnPat (TypePat name) =
rnHsTypeFVs (text "In a type pattern") name `thenM` \ (name', fvs) ->
......
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