+ stmt_fvs = mkFVs [printName, bindIOName, thenIOName, returnIOName, failIOName]
+ -- These are all needed implicitly when compiling a statement
+ -- See TcModule.tc_stmts
+
+implicitModuleFVs source_fvs
+ = mkTemplateHaskellFVs source_fvs `plusFV`
+ namesNeededForFlattening `plusFV`
+ ubiquitousNames
+
+ -- This is a bit of a hack. When we see the Template-Haskell construct
+ -- [| expr |]
+ -- we are going to need lots of the ``smart constructors'' defined in
+ -- the main Template Haskell data type module. Rather than treat them
+ -- all as free vars at every occurrence site, we just make the Q type
+ -- consructor a free var.... and then use that here to haul in the others
+mkTemplateHaskellFVs source_fvs
+#ifdef GHCI
+ -- Only if Template Haskell is enabled
+ | qTyConName `elemNameSet` source_fvs = templateHaskellNames
+#endif
+ | otherwise = emptyFVs
+
+-- 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)
+ * "do" notation
+
+We store the relevant Name in the HsSyn tree, in
+ * HsIntegral/HsFractional
+ * NegApp
+ * NPlusKPatIn
+ * HsDo
+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.
+
+We treat the orignal (standard) names as free-vars too, because the type checker
+checks the type of the user thing against the type of the standard thing.
+
+\begin{code}
+lookupSyntaxName :: Name -- The standard name
+ -> RnM (Name, FreeVars) -- Possibly a non-standard name
+lookupSyntaxName std_name
+ = getModeRn `thenM` \ mode ->
+ if isInterfaceMode mode then
+ returnM (std_name, unitFV std_name)
+ -- Happens for 'derived' code
+ -- where we don't want to rebind
+ else
+
+ doptM Opt_NoImplicitPrelude `thenM` \ no_prelude ->
+ if not no_prelude then
+ returnM (std_name, unitFV std_name) -- Normal case
+
+ else
+ -- Get the similarly named thing from the local environment
+ lookupOccRn (mkRdrUnqual (nameOccName std_name)) `thenM` \ usr_name ->
+ returnM (usr_name, mkFVs [usr_name, std_name])