+newLocalTopBinder :: Module -> OccName
+ -> (Name -> ExportFlag) -> SrcLoc
+ -> RnM d Name
+newLocalTopBinder mod occ rec_exp_fn loc
+ = newTopBinder mod occ (\name -> setNameProvenance name (LocalDef loc (rec_exp_fn name)))
+ -- We must set the provenance of the thing in the cache
+ -- correctly, particularly whether or not it is locally defined.
+ --
+ -- Since newLocalTopBinder is used only
+ -- at binding occurrences, we may as well get the provenance
+ -- dead right first time; hence the rec_exp_fn passed in
+
+newImportedBinder :: Module -> RdrName -> RnM d Name
+newImportedBinder mod rdr_name
+ = ASSERT2( isUnqual rdr_name, ppr rdr_name )
+ newTopBinder mod (rdrNameOcc rdr_name) (\name -> name)
+ -- Provenance is already implicitImportProvenance
+
+implicitImportProvenance = NonLocalDef ImplicitImport False
+
+newTopBinder :: Module -> OccName -> (Name -> Name) -> RnM d Name
+newTopBinder mod occ set_prov
+ = -- First check the cache
+ getNameSupplyRn `thenRn` \ (us, inst_ns, cache, ipcache) ->
+ let
+ key = (moduleName mod, occ)
+ in
+ case lookupFM cache key of
+
+ -- A hit in the cache!
+ -- Set the Module of the thing, and set its provenance (hack pending
+ -- spj update)
+ --
+ -- It also means that if there are two defns for the same thing
+ -- in a module, then each gets a separate SrcLoc
+ --
+ -- There's a complication for wired-in names. We don't want to
+ -- forget that they are wired in even when compiling that module
+ -- (else we spit out redundant defns into the interface file)
+ -- So for them we just set the provenance
+
+ Just name -> let
+ new_name = set_prov (setNameModule name mod)
+ new_cache = addToFM cache key new_name
+ in
+ setNameSupplyRn (us, inst_ns, new_cache, ipcache) `thenRn_`
+ returnRn new_name
+
+ -- Miss in the cache!
+ -- Build a completely new Name, and put it in the cache
+ Nothing -> let
+ (us', us1) = splitUniqSupply us
+ uniq = uniqFromSupply us1
+ new_name = set_prov (mkGlobalName uniq mod occ implicitImportProvenance)
+ new_cache = addToFM cache key new_name
+ in
+ setNameSupplyRn (us', inst_ns, new_cache, ipcache) `thenRn_`
+ returnRn new_name
+
+
+mkImportedGlobalName :: 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
+ --
+ -- 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).
+mkImportedGlobalName mod_name occ
+ = getNameSupplyRn `thenRn` \ (us, inst_ns, cache, ipcache) ->