-setNameVisibility is applied to names in the final program
-
-The Maybe Module argument is (Just mod) for top-level values,
-and Nothing for all others (local values and type variables)
-
-For top-level things, it globalises Local names
- (if all top-level things should be visible)
- and localises non-exported Global names
- (if only exported things should be visible)
-
-For nested things it localises Global names.
-
-In all cases except an exported global, it gives it a new occurrence name.
-
-The "visibility" here concerns whether the .o file's symbol table
-mentions the thing; if so, it needs a module name in its symbol.
-The Global things are "visible" and the Local ones are not
-
-Why should things be "visible"? Certainly they must be if they
-are exported. But also:
-
-(a) In certain (prelude only) modules we split up the .hc file into
- lots of separate little files, which are separately compiled by the C
- compiler. That gives lots of little .o files. The idea is that if
- you happen to mention one of them you don't necessarily pull them all
- in. (Pulling in a piece you don't need can be v bad, because it may
- mention other pieces you don't need either, and so on.)
-
- Sadly, splitting up .hc files means that local names (like s234) are
- now globally visible, which can lead to clashes between two .hc
- files. So unlocaliseWhatnot goes through making all the local things
- into global things, essentially by giving them full names so when they
- are printed they'll have their module name too. Pretty revolting
- really.
-
-(b) When optimisation is on we want to make all the internal
- top-level defns externally visible
-
-\begin{code}
-setNameVisibility :: Maybe Module -> Unique -> Name -> Name
-
-setNameVisibility maybe_mod occ_uniq name@(Global uniq mod occ (LocalDef loc NotExported))
- | not all_toplev_ids_visible || not_top_level maybe_mod
- = Local uniq (uniqToOccName occ_uniq) loc -- Localise Global name
-
-setNameVisibility maybe_mod occ_uniq name@(Global _ _ _ _)
- = name -- Otherwise don't fiddle with Global
-
-setNameVisibility (Just mod) occ_uniq (Local uniq occ loc)
- | all_toplev_ids_visible
- = Global uniq mod -- Globalise Local name
- (uniqToOccName occ_uniq)
- (LocalDef loc NotExported)
-
-setNameVisibility maybe_mod occ_uniq (Local uniq occ loc)
- = Local uniq (uniqToOccName occ_uniq) loc -- New OccName for Local
-
-uniqToOccName uniq = VarOcc (_PK_ ('$':showUnique uniq))
- -- The "$" is to make sure that this OccName is distinct from all user-defined ones
-
-not_top_level (Just m) = False
-not_top_level Nothing = True
-
-all_toplev_ids_visible = not opt_OmitInterfacePragmas || -- Pragmas can make them visible
- opt_EnsureSplittableC -- Splitting requires visiblilty
-\end{code}