- [Module] -- ^ entire top level scope of these modules
- -> [Module] -- ^ exports only of these modules
- -> m ()
-setContext toplev_mods export_mods = do
- hsc_env <- getSession
- let old_ic = hsc_IC hsc_env
- hpt = hsc_HPT hsc_env
- --
- export_env <- liftIO $ mkExportEnv hsc_env export_mods
- toplev_envs <- liftIO $ mapM (mkTopLevEnv hpt) toplev_mods
- let all_env = foldr plusGlobalRdrEnv export_env toplev_envs
- modifySession $ \_ ->
- hsc_env{ hsc_IC = old_ic { ic_toplev_scope = toplev_mods,
- ic_exports = export_mods,
- ic_rn_gbl_env = all_env }}
+ [Module] -- ^ entire top level scope of these modules
+ -> [(Module, Maybe (ImportDecl RdrName))] -- ^ exports of these modules
+ -> m ()
+setContext toplev_mods other_mods = do
+ hsc_env <- getSession
+ let old_ic = hsc_IC hsc_env
+ hpt = hsc_HPT hsc_env
+ (decls,mods) = partition (isJust . snd) other_mods -- time for tracing
+ export_mods = map fst mods
+ imprt_decls = map noLoc (catMaybes (map snd decls))
+ --
+ export_env <- liftIO $ mkExportEnv hsc_env export_mods
+ import_env <-
+ if null imprt_decls then return emptyGlobalRdrEnv else do
+ let imports = rnImports imprt_decls
+ this_mod = if null toplev_mods then pRELUDE else head toplev_mods
+ (_, env, _,_) <-
+ ioMsgMaybe $ liftIO $ initTc hsc_env HsSrcFile False this_mod imports
+ return env
+ toplev_envs <- liftIO $ mapM (mkTopLevEnv hpt) toplev_mods
+ let all_env = foldr plusGlobalRdrEnv (plusGlobalRdrEnv export_env import_env) toplev_envs
+ modifySession $ \_ ->
+ hsc_env{ hsc_IC = old_ic { ic_toplev_scope = toplev_mods,
+ ic_exports = other_mods,
+ ic_rn_gbl_env = all_env }}