-exportsFromAvail Nothing
- = do { this_mod <- getModule ;
- if moduleName this_mod == mAIN_Name then
- return []
- -- Export nothing; Main.$main is automatically exported
- else
- exportsFromAvail (Just [IEModuleContents (moduleName this_mod)])
- -- but for all other modules export everything.
- }
-
-exportsFromAvail (Just exports)
- = do { TcGblEnv { tcg_imports = imports } <- getGblEnv ;
- warn_dup_exports <- doptM Opt_WarnDuplicateExports ;
- exports_from_avail exports warn_dup_exports imports }
-
-exports_from_avail export_items warn_dup_exports
- (ImportAvails { imp_unqual = mod_avail_env,
- imp_env = entity_avail_env })
- = foldlM exports_from_item emptyExportAccum
- export_items `thenM` \ (_, _, export_avail_map) ->
- returnM (nameEnvElts export_avail_map)
+
+exportsFromAvail explicit_mod exports
+ = do { TcGblEnv { tcg_rdr_env = rdr_env,
+ tcg_imports = imports } <- getGblEnv ;
+
+ -- If the module header is omitted altogether, then behave
+ -- as if the user had written "module Main(main) where..."
+ -- EXCEPT in interactive mode, when we behave as if he had
+ -- written "module Main where ..."
+ -- Reason: don't want to complain about 'main' not in scope
+ -- in interactive mode
+ ghci_mode <- getGhciMode ;
+ let { real_exports
+ | explicit_mod = exports
+ | ghci_mode == Interactive = Nothing
+ | otherwise = Just [noLoc (IEVar main_RDR_Unqual)] } ;
+ exports_from_avail real_exports rdr_env imports }
+
+
+exports_from_avail Nothing rdr_env imports
+ = -- Export all locally-defined things
+ -- We do this by filtering the global RdrEnv,
+ -- keeping only things that are locally-defined
+ return (mkNameSet [ gre_name gre
+ | gre <- globalRdrEnvElts rdr_env,
+ isLocalGRE gre ])
+
+exports_from_avail (Just export_items) rdr_env
+ (ImportAvails { imp_qual = mod_avail_env,
+ imp_env = entity_avail_env })
+ = foldlM (exports_from_litem) emptyExportAccum
+ export_items `thenM` \ (_, _, exports) ->
+ returnM exports