From: simonpj@microsoft.com Date: Thu, 11 Jan 2007 13:10:29 +0000 (+0000) Subject: Avoid duplicate defns of 'main' in module Main X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=b991caa149dd65f04ad4723b51571ded76bb2c76 Avoid duplicate defns of 'main' in module Main --- diff --git a/compiler/iface/MkIface.lhs b/compiler/iface/MkIface.lhs index 0fc3972..a9b9f03 100644 --- a/compiler/iface/MkIface.lhs +++ b/compiler/iface/MkIface.lhs @@ -257,11 +257,13 @@ mkIface hsc_env maybe_old_iface ; let { entities = typeEnvElts type_env ; decls = [ tyThingToIfaceDecl entity | entity <- entities, - not (isImplicitTyThing entity - || isWiredInName (getName entity)) ] - -- Don't put implicit Ids and class tycons in - -- the interface file, Nor wired-in things; the - -- compiler knows about them anyhow + let name = getName entity, + not (isImplicitTyThing entity), + -- No implicit Ids and class tycons in the interface file + not (isWiredInName name), + -- Nor wired-in things; the compiler knows about them anyhow + nameIsLocalOrFrom this_mod name ] + -- Sigh: see Note [Root-main Id] in TcRnDriver ; fixities = [(occ,fix) | FixItem occ fix _ <- nameEnvElts fix_env] ; deprecs = mkIfaceDeprec src_deprecs diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs index eabd3bc..6c4a35f 100644 --- a/compiler/typecheck/TcRnDriver.lhs +++ b/compiler/typecheck/TcRnDriver.lhs @@ -726,18 +726,7 @@ check_main ghc_mode tcg_env main_mod main_fn ; (main_expr, ty) <- setSrcSpan (srcLocSpan (getSrcLoc main_name)) $ tcInferRho rhs - -- The function that the RTS invokes is always :Main.main, - -- which we call root_main_id. - -- (Because GHC allows the user to have a module not called - -- Main as the main module, we can't rely on the main function - -- being called "Main.main". That's why root_main_id has a fixed - -- module ":Main".) - -- We also make root_main_id an implicit Id, by making main_name - -- its parent (hence (Just main_name)). That has the effect - -- of preventing its type and unfolding from getting out into - -- the interface file. Otherwise we can end up with two defns - -- for 'main' in the interface file! - + -- See Note [Root-main Id] ; let { root_main_name = mkExternalName rootMainKey rOOT_MAIN (mkVarOccFS FSLIT("main")) (getSrcLoc main_name) @@ -766,6 +755,19 @@ check_main ghc_mode tcg_env main_mod main_fn <+> ptext SLIT("is not defined in module") <+> quotes (ppr main_mod) \end{code} +Note [Root-main Id] +~~~~~~~~~~~~~~~~~~~ +The function that the RTS invokes is always :Main.main, which we call +root_main_id. (Because GHC allows the user to have a module not +called Main as the main module, we can't rely on the main function +being called "Main.main". That's why root_main_id has a fixed module +":Main".) + +This is unusual: it's a LocalId whose Name has a Module from another +module. Tiresomely, we must filter it out again in MkIface, les we +get two defns for 'main' in the interface file! + + %********************************************************* %* * GHCi stuff