+lookupOrigNames :: [RdrName] -> RnM d NameSet
+lookupOrigNames rdr_names
+ = mapRn lookupOrigName rdr_names `thenRn` \ names ->
+ returnRn (mkNameSet names)
+\end{code}
+
+lookupSysBinder is used for the "system binders" of a type, class, or
+instance decl. It ensures that the module is set correctly in the
+name cache, and sets the provenance on the returned name too. The
+returned name will end up actually in the type, class, or instance.
+
+\begin{code}
+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}
+
+%************************************************************************
+%* *
+\subsection{Re-bindable desugaring names}
+%* *
+%************************************************************************
+
+Haskell 98 says that when you say "3" you get the "fromInteger" from the
+Standard Prelude, regardless of what is in scope. However, to experiment
+with having a language that is less coupled to the standard prelude, we're
+trying a non-standard extension that instead gives you whatever "Prelude.fromInteger"
+happens to be in scope. Then you can
+ import Prelude ()
+ import MyPrelude as Prelude
+to get the desired effect.
+
+At the moment this just happens for
+ * fromInteger, fromRational on literals (in expressions and patterns)
+ * negate (in expressions)
+ * minus (arising from n+k patterns)
+
+We store the relevant Name in the HsSyn tree, in
+ * HsIntegral/HsFractional
+ * NegApp
+ * NPlusKPatIn
+respectively. Initially, we just store the "standard" name (PrelNames.fromIntegralName,
+fromRationalName etc), but the renamer changes this to the appropriate user
+name if Opt_NoImplicitPrelude is on. That is what lookupSyntaxName does.
+
+\begin{code}
+lookupSyntaxName :: Name -- The standard name
+ -> RnMS Name -- Possibly a non-standard name
+lookupSyntaxName std_name
+ = doptRn Opt_NoImplicitPrelude `thenRn` \ no_prelude ->
+ if not no_prelude then
+ returnRn std_name -- Normal case
+ else
+ let
+ rdr_name = mkRdrUnqual (nameOccName std_name)
+ -- Get the similarly named thing from the local environment
+ in
+ lookupOccRn rdr_name
+\end{code}
+
+
+%*********************************************************
+%* *
+\subsection{Binding}
+%* *
+%*********************************************************
+
+\begin{code}
+newLocalsRn :: [(RdrName,SrcLoc)]
+ -> RnMS [Name]
+newLocalsRn rdr_names_w_loc
+ = getNameSupplyRn `thenRn` \ name_supply ->
+ let
+ (us', us1) = splitUniqSupply (nsUniqs name_supply)
+ uniqs = uniqsFromSupply 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