- -- * For locally defined names, we do a setProvenance on the Name
- -- right after newTopBinder, and then use updateProveances to finally
- -- set the provenances in the cache correctly.
- --
- -- NB: for wired-in names it's important not to
- -- forget that they are wired in even when compiling that module
- -- (else we spit out redundant defns into the interface file)
-
- Just name -> let
- new_name = setNameModule name mod
- new_cache = addToFM cache key new_name
- in
- setNameSupplyRn (us, new_cache, ipcache) `thenRn_`
- traceRn (text "newTopBinder: overwrite" <+> ppr new_name) `thenRn_`
- returnRn 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 -> let
- (us', us1) = splitUniqSupply us
- uniq = uniqFromSupply us1
- new_name = mkGlobalName uniq mod occ implicitImportProvenance
- new_cache = addToFM cache key new_name
- in
- setNameSupplyRn (us', new_cache, ipcache) `thenRn_`
- traceRn (text "newTopBinder: new" <+> ppr new_name) `thenRn_`
- returnRn new_name
-
-
-newGlobalName :: ModuleName -> OccName -> RnM d 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 (newImportedBinder)
- -- The place-holder Name doesn't have the right Provenance, 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
- = getNameSupplyRn `thenRn` \ (us, cache, ipcache) ->
- let
- key = (mod_name, occ)
- in
- case lookupFM cache key of
- Just name -> traceRn (text "newGlobalName: hit" <+> ppr name) `thenRn_`
- returnRn name
-
- Nothing -> setNameSupplyRn (us', new_cache, ipcache) `thenRn_`
- traceRn (text "newGlobalName: new" <+> ppr name) `thenRn_`
- returnRn name
- where
- (us', us1) = splitUniqSupply us
- uniq = uniqFromSupply us1
- mod = mkVanillaModule mod_name
- name = mkGlobalName uniq mod occ implicitImportProvenance
- new_cache = addToFM cache key name
-
-
-newIPName rdr_name
- = getNameSupplyRn `thenRn` \ (us, cache, ipcache) ->
- case lookupFM ipcache key of
- Just name -> returnRn name
- Nothing -> setNameSupplyRn (us', cache, new_ipcache) `thenRn_`
- returnRn name
- where
- (us', us1) = splitUniqSupply us
- uniq = uniqFromSupply us1
- name = mkIPName uniq key
- new_ipcache = addToFM ipcache key name
- where key = (rdrNameOcc rdr_name)
-
-updateProvenances :: [Name] -> RnM d ()
--- Update the provenances of everything that is in scope.
--- We must be careful not to disturb the Module package info
--- already in the cache. Why not? Consider
--- module A module M( f )
--- import M( f ) import N( f)
--- import N
--- So f is defined in N, and M re-exports it.
--- When processing module A:
--- 1. We read M.hi first, and make a vanilla name N.f
--- (without reading N.hi). The package info says <THIS>
--- for lack of anything better.
--- 2. Now we read N, which update the cache to record
--- the correct package for N.f.
--- 3. Finally we update provenances (once we've read all imports).
--- Step 3 must not destroy package info recorded in Step 2.
-
-updateProvenances names
- = getNameSupplyRn `thenRn` \ (us, cache, ipcache) ->
- setNameSupplyRn (us, foldr update cache names, ipcache)
- where
- update name cache = addToFM_C update_prov cache key name
- where
- key = (moduleName (nameModule name), nameOccName name)