- | otherwise
- = -- First check the cache
- getNameCache `thenM` \ name_supply ->
- let
- occ = rdrNameOcc rdr_name
- key = (moduleName mod, occ)
- cache = nsNames name_supply
- in
- case lookupFM cache key of
-
- -- A hit in the cache! We are at the binding site of the name, and
- -- this is the moment when we know all about
- -- a) the Name's host Module (in particular, which
- -- package it comes from)
- -- b) its defining SrcLoc
- -- So we update this info
-
- Just name
- | isWiredInName name -> returnM name
- -- Don't mess with wired-in names. Apart from anything
- -- else, their wired-in-ness is in the SrcLoca
- | otherwise
- -> let
- new_name = setNameModuleAndLoc name mod loc
- new_cache = addToFM cache key new_name
- in
- setNameCache (name_supply {nsNames = new_cache}) `thenM_`
- returnM new_name
-
- -- Miss in the cache!
- -- Build a completely new Name, and put it in the cache
- -- Even for locally-defined names we use implicitImportProvenance;
- -- updateProvenances will set it to rights
- Nothing -> addNewName name_supply key mod occ loc
-
-newGlobalName :: ModuleName -> OccName -> TcRn m Name
- -- Used for *occurrences*. We make a place-holder Name, really just
- -- to agree on its unique, which gets overwritten when we read in
- -- the binding occurence later (newTopBinder)
- -- The place-holder Name doesn't have the right SrcLoc, and its
- -- Module won't have the right Package either.
- --
- -- (We have to pass a ModuleName, not a Module, because we may be
- -- simply looking at an occurrence M.x in an interface file.)
- --
- -- This means that a renamed program may have incorrect info
- -- on implicitly-imported occurrences, but the correct info on the
- -- *binding* declaration. It's the type checker that propagates the
- -- correct information to all the occurrences.
- -- Since implicitly-imported names never occur in error messages,
- -- it doesn't matter that we get the correct info in place till later,
- -- (but since it affects DLL-ery it does matter that we get it right
- -- in the end).
-newGlobalName mod_name occ
- = getNameCache `thenM` \ name_supply ->
- let
- key = (mod_name, occ)
- cache = nsNames name_supply
- in
- case lookupFM cache key of
- Just name -> -- traceRn (text "newGlobalName: hit" <+> ppr name) `thenM_`
- returnM name
-
- Nothing -> -- traceRn (text "newGlobalName: new" <+> ppr name) `thenM_`
- addNewName name_supply key (mkVanillaModule mod_name) occ noSrcLoc
-
--- Look up a "system name" in the name cache.
--- This is done by the type checker...
--- For *source* declarations, this will put the thing into the name cache
--- For *interface* declarations, RnHiFiles.getSysBinders will already have
--- put it into the cache.
-lookupSysName :: Name -- Base name
- -> (OccName -> OccName) -- Occurrence name modifier
- -> TcRn m Name -- System name
-lookupSysName base_name mk_sys_occ
- = getNameCache `thenM` \ name_supply ->
- let
- mod = nameModule base_name
- occ = mk_sys_occ (nameOccName base_name)
- key = (moduleName mod, occ)
- in
- case lookupFM (nsNames name_supply) key of
- Just name -> returnM name
- Nothing -> addNewName name_supply key mod occ noSrcLoc
+ | isOrig rdr_name
+ = ASSERT( rdr_mod == moduleName mod || rdr_mod == rOOT_MAIN_Name )
+ -- When reading External Core we get Orig names as binders,
+ -- but they should agree with the module gotten from the monad
+ --
+ -- Except for the ":Main.main = ..." definition inserted into
+ -- the Main module
+ --
+ -- Because of this latter case, we take the module from the RdrName,
+ -- not from the environment. In principle, it'd be fine to have an
+ -- arbitrary mixture of external core definitions in a single module,
+ -- (apart from module-initialisation issues, perhaps).
+ newGlobalBinder (mkHomeModule rdr_mod) (rdrNameOcc rdr_name) mb_parent
+ (srcSpanStart loc) --TODO, should pass the whole span