+%*********************************************************
+%* *
+\subsection{Implicit free vars and sugar names}
+%* *
+%*********************************************************
+
+@getXImplicitFVs@ forces the renamer to slurp in some things which aren't
+mentioned explicitly, but which might be needed by the type checker.
+
+\begin{code}
+getImplicitStmtFVs -- Compiling a statement
+ = returnRn (mkFVs [printName, bindIOName, returnIOName, failIOName]
+ `plusFV` ubiquitousNames)
+ -- These are all needed implicitly when compiling a statement
+ -- See TcModule.tc_stmts
+
+getImplicitModuleFVs mod_name decls -- Compiling a module
+ = lookupOrigNames deriv_occs `thenRn` \ deriving_names ->
+ returnRn (deriving_names `plusFV` implicit_main `plusFV` ubiquitousNames)
+ where
+ -- Add occurrences for IO or PrimIO
+ implicit_main | mod_name == mAIN_Name
+ || mod_name == pREL_MAIN_Name = unitFV ioTyConName
+ | otherwise = emptyFVs
+
+ deriv_occs = [occ | TyClD (TyData {tcdDerivs = Just deriv_classes}) <- decls,
+ cls <- deriv_classes,
+ occ <- lookupWithDefaultUFM derivingOccurrences [] cls ]
+
+-- ubiquitous_names are loaded regardless, because
+-- they are needed in virtually every program
+ubiquitousNames
+ = mkFVs [unpackCStringName, unpackCStringFoldrName,
+ unpackCStringUtf8Name, eqStringName]
+ -- Virtually every program has error messages in it somewhere
+
+ `plusFV`
+ mkFVs [getName unitTyCon, funTyConName, boolTyConName, intTyConName]
+ -- Add occurrences for very frequently used types.
+ -- (e.g. we don't want to be bothered with making funTyCon a
+ -- free var at every function application!)
+\end{code}
+
+\begin{code}
+rnSyntaxNames :: GlobalRdrEnv -> FreeVars -> RnMG (FreeVars, SyntaxMap)
+-- Look up the re-bindable syntactic sugar names
+-- Any errors arising from these lookups may surprise the
+-- programmer, since they aren't explicitly mentioned, and
+-- the src line will be unhelpful (ToDo)
+
+rnSyntaxNames gbl_env source_fvs
+ = doptRn Opt_NoImplicitPrelude `thenRn` \ no_prelude ->
+ if not no_prelude then
+ returnRn (source_fvs, vanillaSyntaxMap)
+ else
+
+ -- There's a -fno-implicit-prelude flag,
+ -- so build the re-mapping function
+ let
+ reqd_syntax_list = filter is_reqd syntaxList
+ is_reqd (n,_) = n `elemNameSet` source_fvs
+ lookup (n,rn) = lookupSrcName gbl_env rn `thenRn` \ rn' ->
+ returnRn (n,rn')
+ in
+ mapRn lookup reqd_syntax_list `thenRn` \ rn_syntax_list ->
+ let
+ -- Delete the proxies and add the actuals
+ proxies = map fst rn_syntax_list
+ actuals = map snd rn_syntax_list
+ new_source_fvs = (proxies `delFVs` source_fvs) `plusFV` mkFVs actuals
+
+ syntax_env = mkNameEnv rn_syntax_list
+ syntax_map n = lookupNameEnv syntax_env n `orElse` n
+ in
+ returnRn (new_source_fvs, syntax_map)
+\end{code}
+