+\begin{code}
+emptyModIface :: Module -> ModIface
+emptyModIface mod
+ = ModIface { mi_module = mod,
+ mi_package = preludePackage, -- XXX fully bogus
+ mi_version = initialVersionInfo,
+ mi_usages = [],
+ mi_orphan = False,
+ mi_boot = False,
+ mi_exports = [],
+ mi_fixities = emptyNameEnv,
+ mi_globals = Nothing,
+ mi_deprecs = NoDeprecs,
+ mi_decls = panic "emptyModIface: decls"
+ }
+\end{code}
+
+Symbol tables map modules to ModDetails:
+
+\begin{code}
+type SymbolTable = ModuleEnv ModDetails
+type IfaceTable = ModuleEnv ModIface
+
+type HomeIfaceTable = IfaceTable
+type PackageIfaceTable = IfaceTable
+
+type HomeSymbolTable = SymbolTable -- Domain = modules in the home package
+
+emptySymbolTable :: SymbolTable
+emptySymbolTable = emptyModuleEnv
+
+emptyIfaceTable :: IfaceTable
+emptyIfaceTable = emptyModuleEnv
+\end{code}
+
+Simple lookups in the symbol table.
+
+\begin{code}
+lookupIface :: HomeIfaceTable -> PackageIfaceTable -> Name -> Maybe ModIface
+-- We often have two IfaceTables, and want to do a lookup
+lookupIface hit pit name
+ = lookupModuleEnv hit mod `seqMaybe` lookupModuleEnv pit mod
+ where
+ mod = nameModule name
+
+lookupIfaceByModName :: HomeIfaceTable -> PackageIfaceTable -> ModuleName -> Maybe ModIface
+-- We often have two IfaceTables, and want to do a lookup
+lookupIfaceByModName hit pit mod
+ = lookupModuleEnvByName hit mod `seqMaybe` lookupModuleEnvByName pit mod
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{The interactive context}
+%* *
+%************************************************************************
+
+\begin{code}
+data InteractiveContext
+ = InteractiveContext {
+ ic_toplev_scope :: [Module], -- Include the "top-level" scope of
+ -- these modules
+
+ ic_exports :: [Module], -- Include just the exports of these
+ -- modules
+
+ ic_rn_gbl_env :: GlobalRdrEnv, -- The cached GlobalRdrEnv, built from
+ -- ic_toplev_scope and ic_exports
+
+ ic_print_unqual :: PrintUnqualified,
+ -- cached PrintUnqualified, as above
+
+ ic_rn_local_env :: LocalRdrEnv, -- Lexical context for variables bound
+ -- during interaction
+
+ ic_type_env :: TypeEnv -- Ditto for types
+ }
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Type environment stuff}
+%* *
+%************************************************************************
+
+\begin{code}
+data TyThing = AnId Id
+ | ATyCon TyCon
+ | AClass Class
+
+isTyClThing :: TyThing -> Bool
+isTyClThing (ATyCon _) = True
+isTyClThing (AClass _) = True
+isTyClThing (AnId _) = False
+
+instance NamedThing TyThing where
+ getName (AnId id) = getName id
+ getName (ATyCon tc) = getName tc
+ getName (AClass cl) = getName cl
+
+instance Outputable TyThing where
+ ppr (AnId id) = ptext SLIT("AnId") <+> ppr id
+ ppr (ATyCon tc) = ptext SLIT("ATyCon") <+> ppr tc
+ ppr (AClass cl) = ptext SLIT("AClass") <+> ppr cl
+
+
+typeEnvElts :: TypeEnv -> [TyThing]
+typeEnvClasses :: TypeEnv -> [Class]
+typeEnvTyCons :: TypeEnv -> [TyCon]
+typeEnvIds :: TypeEnv -> [Id]
+
+typeEnvElts env = nameEnvElts env
+typeEnvClasses env = [cl | AClass cl <- typeEnvElts env]
+typeEnvTyCons env = [tc | ATyCon tc <- typeEnvElts env]
+typeEnvIds env = [id | AnId id <- typeEnvElts env]
+
+implicitTyThingIds :: [TyThing] -> [Id]
+-- Add the implicit data cons and selectors etc
+implicitTyThingIds things
+ = concat (map go things)
+ where
+ go (AnId f) = []
+ go (AClass cl) = classSelIds cl
+ go (ATyCon tc) = tyConGenIds tc ++
+ tyConSelIds tc ++
+ [ n | dc <- tyConDataCons_maybe tc `orElse` [],
+ n <- implicitConIds tc dc]
+ -- Synonyms return empty list of constructors and selectors
+
+ implicitConIds tc dc -- Newtypes have a constructor wrapper,
+ -- but no worker
+ | isNewTyCon tc = [dataConWrapId dc]
+ | otherwise = [dataConWorkId dc, dataConWrapId dc]
+\end{code}
+