[project @ 2002-10-28 11:21:13 by simonpj]
authorsimonpj <unknown>
Mon, 28 Oct 2002 11:21:14 +0000 (11:21 +0000)
committersimonpj <unknown>
Mon, 28 Oct 2002 11:21:14 +0000 (11:21 +0000)
Track locations for binders better (fixes several rn and mod failures)

ghc/compiler/basicTypes/Name.lhs
ghc/compiler/rename/RnEnv.lhs

index fd69b93..3a12947 100644 (file)
@@ -17,7 +17,7 @@ module Name (
 
        nameUnique, setNameUnique,
        nameOccName, nameModule, nameModule_maybe,
-       setNameOcc, setNameModuleAndLoc, 
+       setNameOcc, setNameSrcLoc, 
        hashName, externaliseName, localiseName,
 
        nameSrcLoc, eqNameByOcc,
@@ -230,10 +230,8 @@ externaliseName n mod = n { n_sort = External mod }
 localiseName :: Name -> Name
 localiseName n = n { n_sort = Internal }
                                
-setNameModuleAndLoc :: Name -> Module -> SrcLoc -> Name
-setNameModuleAndLoc name mod loc = name {n_sort = set (n_sort name), n_loc = loc}
-                      where
-                        set (External _) = External mod
+setNameSrcLoc :: Name -> SrcLoc -> Name
+setNameSrcLoc name loc = name {n_loc = loc}
 \end{code}
 
 
index f5f3eab..77e02b2 100644 (file)
@@ -31,7 +31,7 @@ import HscTypes               ( Provenance(..), pprNameProvenance, hasBetterProv,
 import TcRnMonad
 import Name            ( Name, getName, getSrcLoc, nameIsLocalOrFrom, isWiredInName,
                          mkInternalName, mkExternalName, mkIPName, nameSrcLoc,
-                         nameOccName, setNameModuleAndLoc, nameModule  )
+                         nameOccName, setNameSrcLoc, nameModule        )
 import NameSet
 import OccName         ( OccName, tcName, isDataOcc, occNameUserString, occNameFlavour )
 import Module          ( Module, ModuleName, moduleName, mkHomeModule,
@@ -66,13 +66,6 @@ import FastString    ( FastString )
 
 \begin{code}
 newTopBinder :: Module -> RdrName -> SrcLoc -> TcRn m Name
-       -- newTopBinder puts into the cache the binder with the
-       -- module information set correctly.  When the decl is later renamed,
-       -- the binding site will thereby get the correct module.
-       -- There maybe occurrences that don't have the correct Module, but
-       -- by the typechecker will propagate the binding definition to all 
-       -- the occurrences, so that doesn't matter
-
 newTopBinder mod rdr_name loc
   | Just name <- isExact_maybe rdr_name
   = returnM name
@@ -88,15 +81,21 @@ newGlobalName mod occ loc
 
        -- A hit in the cache!  We are at the binding site of the name.
        -- This is the moment when we know the defining SrcLoc
-       -- of the Name.  However, since we must have encountered an 
-       -- occurrence before the binding site, this must be an 
-       -- implicitly-imported name and we can't give a useful SrcLoc to
-       -- it.  So we just leave it alone.
+       -- of the Name, so we set the SrcLoc of the name we return.
+       --
+       -- Main reason: then (bogus) multiple bindings of the same Name
+       --              get different SrcLocs can can be reported as such.
        --
-       -- IMPORTANT: don't mess with wired-in names.  
-       -- Their wired-in-ness is in the SrcLoc
+       -- Possible other reason: it might be in the cache because we
+       --      encountered an occurrence before the binding site for an
+       --      implicitly-imported Name.  Perhaps the current SrcLoc is
+       --      better... but not really: it'll still just say 'imported'
+       --
+       -- IMPORTANT: Don't mess with wired-in names.  
+       --            Their wired-in-ness is in the SrcLoc
 
-       Just name -> returnM name
+       Just name | isWiredInName name -> returnM name
+                 | otherwise          -> returnM (setNameSrcLoc name loc)
                     
        -- Miss in the cache!
        -- Build a completely new Name, and put it in the cache