+lookupSysBinder rdr_name
+ = ASSERT( isUnqual rdr_name )
+ getModuleRn `thenRn` \ mod ->
+ getSrcLocRn `thenRn` \ loc ->
+ newTopBinder mod rdr_name loc
+\end{code}
+
+
+%*********************************************************
+%* *
+\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}
+implicitGates :: Name -> FreeVars
+-- If we load class Num, add Integer to the gates
+-- This takes account of the fact that Integer might be needed for
+-- defaulting, but we don't want to load Integer (and all its baggage)
+-- if there's no numeric stuff needed.
+-- Similarly for class Fractional and Double
+--
+-- NB: If we load (say) Floating, we'll end up loading Fractional too,
+-- since Fractional is a superclass of Floating
+implicitGates cls | cls `hasKey` numClassKey = unitFV integerTyConName
+ | cls `hasKey` fractionalClassKey = unitFV doubleTyConName
+ | otherwise = emptyFVs
+\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}
+
+
+%*********************************************************
+%* *
+\subsection{Binding}
+%* *
+%*********************************************************
+
+\begin{code}
+newLocalsRn :: [(RdrName,SrcLoc)]
+ -> RnMS [Name]
+newLocalsRn rdr_names_w_loc
+ = getNameSupplyRn `thenRn` \ name_supply ->
+ let
+ n = length rdr_names_w_loc
+ (us', us1) = splitUniqSupply (nsUniqs name_supply)
+ uniqs = uniqsFromSupply n us1
+ names = [ mkLocalName uniq (rdrNameOcc rdr_name) loc
+ | ((rdr_name,loc), uniq) <- rdr_names_w_loc `zip` uniqs
+ ]
+ in
+ setNameSupplyRn (name_supply {nsUniqs = us'}) `thenRn_`
+ returnRn names
+
+
+bindLocatedLocalsRn :: SDoc -- Documentation string for error message