[project @ 2005-10-26 12:35:12 by simonpj]
authorsimonpj <unknown>
Wed, 26 Oct 2005 12:35:12 +0000 (12:35 +0000)
committersimonpj <unknown>
Wed, 26 Oct 2005 12:35:12 +0000 (12:35 +0000)
Simplify Provenance (the LocalDef constructor) a little

ghc/compiler/basicTypes/RdrName.lhs
ghc/compiler/rename/RnExpr.lhs
ghc/compiler/rename/RnNames.lhs

index 172485c..900717e 100644 (file)
@@ -386,9 +386,9 @@ pickGREs rdr_name gres
     mod              = rdrNameModule rdr_name
 
     pick :: GlobalRdrElt -> Maybe GlobalRdrElt
-    pick gre@(GRE {gre_prov = LocalDef m})     -- Local def
-       | is_unqual || m == mod = Just gre
-       | otherwise             = Nothing
+    pick gre@(GRE {gre_prov = LocalDef, gre_name = n})         -- Local def
+       | is_unqual || nameModule n == mod = Just gre
+       | otherwise                        = Nothing
     pick gre@(GRE {gre_prov = Imported [is]})  -- Single import (efficiency)
        | is_unqual     = if not (is_qual (is_decl is)) then Just gre
                                                        else Nothing
@@ -402,12 +402,12 @@ pickGREs rdr_name gres
                      | otherwise = filter ((== mod) . is_as . is_decl) is
 
 isLocalGRE :: GlobalRdrElt -> Bool
-isLocalGRE (GRE {gre_prov = LocalDef _}) = True
-isLocalGRE other                        = False
+isLocalGRE (GRE {gre_prov = LocalDef}) = True
+isLocalGRE other                      = False
 
 unQualOK :: GlobalRdrElt -> Bool
 -- An unqualifed version of this thing is in scope
-unQualOK (GRE {gre_prov = LocalDef _})  = True
+unQualOK (GRE {gre_prov = LocalDef})    = True
 unQualOK (GRE {gre_prov = Imported is}) = not (all (is_qual . is_decl) is)
 
 plusGlobalRdrEnv :: GlobalRdrEnv -> GlobalRdrEnv -> GlobalRdrEnv
@@ -449,8 +449,6 @@ It's quite elaborate so that we can give accurate unused-name warnings.
 \begin{code}
 data Provenance
   = LocalDef           -- Defined locally
-       Module
-
   | Imported           -- Imported
        [ImportSpec]    -- INVARIANT: non-empty
 
@@ -504,9 +502,9 @@ instance Eq ImpItemSpec where
   p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False
 
 instance Ord Provenance where
-   compare (LocalDef _) (LocalDef _)            = EQ
-   compare (LocalDef _) (Imported _)    = LT
-   compare (Imported _ ) (LocalDef _)    = GT
+   compare LocalDef      LocalDef       = EQ
+   compare LocalDef      (Imported _)   = LT
+   compare (Imported _ ) LocalDef       = GT
    compare (Imported is1) (Imported is2) = compare (head is1) 
        {- See Note [Comparing provenance] -}      (head is2)
 
@@ -526,14 +524,14 @@ plusProv :: Provenance -> Provenance -> Provenance
 -- defined, and one might refer to it with a qualified name from
 -- the import -- but I'm going to ignore that because it makes
 -- the isLocalGRE predicate so much nicer this way
-plusProv (LocalDef m1) (LocalDef m2)     = pprPanic "plusProv" (ppr m1 <+> ppr m2)
-plusProv p1@(LocalDef _) p2             = p1
-plusProv p1             p2@(LocalDef _) = p2
+plusProv LocalDef       LocalDef        = panic "plusProv"
+plusProv LocalDef       p2              = LocalDef
+plusProv p1             LocalDef        = LocalDef
 plusProv (Imported is1)  (Imported is2)  = Imported (is1++is2)
 
 pprNameProvenance :: GlobalRdrElt -> SDoc
 -- Print out the place where the name was imported
-pprNameProvenance (GRE {gre_name = name, gre_prov = LocalDef _})
+pprNameProvenance (GRE {gre_name = name, gre_prov = LocalDef})
   = ptext SLIT("defined at") <+> ppr (nameSrcLoc name)
 pprNameProvenance (GRE {gre_name = name, gre_prov = Imported (why:whys)})
   = sep [ppr why, nest 2 (ppr_defn (nameSrcLoc name))]
index 6c8a18c..59f7076 100644 (file)
@@ -554,7 +554,7 @@ rnBracket (DecBr group)
        -- By using a pretend module, thFAKE, we keep them safely out of the way.
 
        ; names    <- getLocalDeclBinders gbl_env1 group
-       ; rdr_env' <- extendRdrEnvRn thFAKE emptyGlobalRdrEnv names
+       ; rdr_env' <- extendRdrEnvRn emptyGlobalRdrEnv names
        -- Furthermore, the names in the bracket shouldn't conflict with
        -- existing top-level names E.g.
        --      foo = 1
index 1f73462..1fddb33 100644 (file)
@@ -300,21 +300,21 @@ importsFromLocalDecls group
            ; this_mod = tcg_mod gbl_env
            ; imports = emptyImportAvails {
                          imp_env = unitModuleEnv this_mod $
-                                 mkNameSet filtered_names
+                                   mkNameSet filtered_names
                        }
            }
 
-       ; rdr_env' <- extendRdrEnvRn this_mod (tcg_rdr_env gbl_env) names
+       ; rdr_env' <- extendRdrEnvRn (tcg_rdr_env gbl_env) names
 
        ; returnM (gbl_env { tcg_rdr_env = rdr_env',
                             tcg_imports = imports `plusImportAvails` tcg_imports gbl_env }) 
        }
 
-extendRdrEnvRn :: Module -> GlobalRdrEnv -> [Name] -> RnM GlobalRdrEnv
+extendRdrEnvRn :: GlobalRdrEnv -> [Name] -> RnM GlobalRdrEnv
 -- Add the new locally-bound names one by one, checking for duplicates as
 -- we do so.  Remember that in Template Haskell the duplicates
 -- might *already be* in the GlobalRdrEnv from higher up the module
-extendRdrEnvRn mod rdr_env names
+extendRdrEnvRn rdr_env names
   = foldlM add_local rdr_env names
   where
     add_local rdr_env name
@@ -325,9 +325,7 @@ extendRdrEnvRn mod rdr_env names
        | otherwise
        = return (extendGlobalRdrEnv rdr_env new_gre)
        where
-         new_gre = GRE {gre_name = name, gre_prov = prov}
-
-    prov = LocalDef mod
+         new_gre = GRE {gre_name = name, gre_prov = LocalDef}
 \end{code}
 
 @getLocalDeclBinders@ returns the names for an @HsDecl@.  It's