From: simonpj Date: Mon, 28 Oct 2002 11:21:14 +0000 (+0000) Subject: [project @ 2002-10-28 11:21:13 by simonpj] X-Git-Tag: Approx_11550_changesets_converted~1501 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=c7bd58b09eee8bb74333f3b8d2c5623dbb1f8b25 [project @ 2002-10-28 11:21:13 by simonpj] Track locations for binders better (fixes several rn and mod failures) --- diff --git a/ghc/compiler/basicTypes/Name.lhs b/ghc/compiler/basicTypes/Name.lhs index fd69b93..3a12947 100644 --- a/ghc/compiler/basicTypes/Name.lhs +++ b/ghc/compiler/basicTypes/Name.lhs @@ -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} diff --git a/ghc/compiler/rename/RnEnv.lhs b/ghc/compiler/rename/RnEnv.lhs index f5f3eab..77e02b2 100644 --- a/ghc/compiler/rename/RnEnv.lhs +++ b/ghc/compiler/rename/RnEnv.lhs @@ -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