-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
+
+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@(ImportAvails { imp_env = entity_avail_env })
+ = -- Export all locally-defined things
+ -- We do this by filtering the global RdrEnv,
+ -- keeping only things that are (a) qualified,
+ -- (b) locally defined, (c) a 'main' name
+ -- Then we look up in the entity-avail-env
+ return [ lookupAvailEnv entity_avail_env name
+ | gre <- globalRdrEnvElts rdr_env,
+ isLocalGRE gre,
+ let name = gre_name gre,
+ isNothing (nameParent_maybe name) -- Main things only
+ ]
+
+exports_from_avail (Just export_items) rdr_env