X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FbasicTypes%2FRdrName.lhs;h=a33c2430bbe45a7cb2fff3d8a0b5676c7b7afb9c;hp=6b28786145bafddf41f3157dd13f1e90e92433d3;hb=65277a1c9ff86c28c656849d6f6cbb392f1eb3e7;hpb=66579ff945831c5fc9a17c58c722ff01f2268d76 diff --git a/compiler/basicTypes/RdrName.lhs b/compiler/basicTypes/RdrName.lhs index 6b28786..a33c243 100644 --- a/compiler/basicTypes/RdrName.lhs +++ b/compiler/basicTypes/RdrName.lhs @@ -40,7 +40,7 @@ module RdrName ( showRdrName, -- * Local mapping of 'RdrName' to 'Name.Name' - LocalRdrEnv, emptyLocalRdrEnv, extendLocalRdrEnv, + LocalRdrEnv, emptyLocalRdrEnv, extendLocalRdrEnv, extendLocalRdrEnvList, lookupLocalRdrEnv, lookupLocalRdrOcc, elemLocalRdrEnv, -- * Global mapping of 'RdrName' to 'GlobalRdrElt's @@ -48,7 +48,7 @@ module RdrName ( lookupGlobalRdrEnv, extendGlobalRdrEnv, pprGlobalRdrEnv, globalRdrEnvElts, lookupGRE_RdrName, lookupGRE_Name, getGRE_NameQualifier_maybes, - hideSomeUnquals, findLocalDupsRdrEnv, + hideSomeUnquals, findLocalDupsRdrEnv, pickGREs, -- ** Global 'RdrName' mapping elements: 'GlobalRdrElt', 'Provenance', 'ImportSpec' GlobalRdrElt(..), isLocalGRE, unQualOK, qualSpecOK, unQualSpecOK, @@ -251,7 +251,7 @@ instance Outputable RdrName where ppr (Exact name) = ppr name ppr (Unqual occ) = ppr occ ppr (Qual mod occ) = ppr mod <> dot <> ppr occ - ppr (Orig mod occ) = ppr mod <> dot <> ppr occ + ppr (Orig mod occ) = getPprStyle (\sty -> pprModulePrefix sty mod occ <> ppr occ) instance OutputableBndr RdrName where pprBndr _ n @@ -316,8 +316,12 @@ type LocalRdrEnv = OccEnv Name emptyLocalRdrEnv :: LocalRdrEnv emptyLocalRdrEnv = emptyOccEnv -extendLocalRdrEnv :: LocalRdrEnv -> [Name] -> LocalRdrEnv -extendLocalRdrEnv env names +extendLocalRdrEnv :: LocalRdrEnv -> Name -> LocalRdrEnv +extendLocalRdrEnv env name + = extendOccEnv env (nameOccName name) name + +extendLocalRdrEnvList :: LocalRdrEnv -> [Name] -> LocalRdrEnv +extendLocalRdrEnvList env names = extendOccEnvList env [(nameOccName n, n) | n <- names] lookupLocalRdrEnv :: LocalRdrEnv -> RdrName -> Maybe Name @@ -353,6 +357,12 @@ type GlobalRdrEnv = OccEnv [GlobalRdrElt] -- -- INVARIANT: All the members of the list have distinct -- 'gre_name' fields; that is, no duplicate Names +-- +-- INVARIANT: Imported provenance => Name is an ExternalName +-- However LocalDefs can have an InternalName. This +-- happens only when type-checking a [d| ... |] Template +-- Haskell quotation; see this note in RnNames +-- Note [Top-level Names in Template Haskell decl quotes] -- | An element of the 'GlobalRdrEnv' data GlobalRdrElt @@ -361,6 +371,12 @@ data GlobalRdrElt gre_prov :: Provenance -- ^ Why it's in scope } +-- | The children of a Name are the things that are abbreviated by the ".." +-- notation in export lists. Specifically: +-- TyCon Children are * data constructors +-- * record field ids +-- Class Children are * class operations +-- Each child has the parent thing as its Parent data Parent = NoParent | ParentIs Name deriving (Eq) @@ -412,10 +428,9 @@ lookupGlobalRdrEnv env occ_name = case lookupOccEnv env occ_name of Just gres -> gres extendGlobalRdrEnv :: GlobalRdrEnv -> GlobalRdrElt -> GlobalRdrEnv -extendGlobalRdrEnv env gre = extendOccEnv_C add env occ [gre] +extendGlobalRdrEnv env gre = extendOccEnv_Acc (:) singleton env occ gre where occ = nameOccName (gre_name gre) - add gres _ = gre:gres lookupGRE_RdrName :: RdrName -> GlobalRdrEnv -> [GlobalRdrElt] lookupGRE_RdrName rdr_name env @@ -461,16 +476,17 @@ pickGREs rdr_name gres pick :: GlobalRdrElt -> Maybe GlobalRdrElt pick gre@(GRE {gre_prov = LocalDef, gre_name = n}) -- Local def - | rdr_is_unqual = Just gre - | Just (mod,_) <- rdr_is_qual, - mod == moduleName (nameModule n) = Just gre - | otherwise = Nothing + | rdr_is_unqual = Just gre + | Just (mod,_) <- rdr_is_qual -- Qualified name + , Just n_mod <- nameModule_maybe n -- Binder is External + , mod == moduleName n_mod = Just gre + | otherwise = Nothing pick gre@(GRE {gre_prov = Imported [is]}) -- Single import (efficiency) | rdr_is_unqual, - not (is_qual (is_decl is)) = Just gre + not (is_qual (is_decl is)) = Just gre | Just (mod,_) <- rdr_is_qual, - mod == is_as (is_decl is) = Just gre - | otherwise = Nothing + mod == is_as (is_decl is) = Just gre + | otherwise = Nothing pick gre@(GRE {gre_prov = Imported is}) -- Multiple import | null filtered_is = Nothing | otherwise = Just (gre {gre_prov = Imported filtered_is}) @@ -498,9 +514,9 @@ mkGlobalRdrEnv :: [GlobalRdrElt] -> GlobalRdrEnv mkGlobalRdrEnv gres = foldr add emptyGlobalRdrEnv gres where - add gre env = extendOccEnv_C (foldr insertGRE) env - (nameOccName (gre_name gre)) - [gre] + add gre env = extendOccEnv_Acc insertGRE singleton env + (nameOccName (gre_name gre)) + gre findLocalDupsRdrEnv :: GlobalRdrEnv -> [OccName] -> (GlobalRdrEnv, [[Name]]) -- ^ For each 'OccName', see if there are multiple local definitions @@ -603,7 +619,7 @@ data ImpDeclSpec -- should be a Maybe PackageId here too. is_as :: ModuleName, -- ^ Import alias, e.g. from @as M@ (or @Muggle@ if there is no @as@ clause) is_qual :: Bool, -- ^ Was this import qualified? - is_dloc :: SrcSpan -- ^ The location of the import declaration + is_dloc :: SrcSpan -- ^ The location of the entire import declaration } -- | Describes import info a particular Name