Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Use hie files as source of truth for name source spans.
Browse files Browse the repository at this point in the history
Since we started reusing `.hi` files, this exposes a bug where definitions
aren't available since a bad source span from the `.hi` file gets put into
the NameCache. We rectify by ensuring the span in the NameCache always matches
the one from the `.hie` file.

This has surfaced because an interaction between the commit which uses `.hi`
instead of retypechecking and the change to use the shared global NameCache
to read `.hie` files.
  • Loading branch information
wz1000 committed Jul 6, 2020
1 parent 19106fd commit 96d1f30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src-ghc810/Development/IDE/GHC/HieBin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@ fromHieName :: NameCache -> HieName -> (NameCache, Name)
fromHieName nc (ExternalName mod occ span) =
let cache = nsNames nc
in case lookupOrigNameCache cache mod occ of
Just name -> (nc, name)
Just name
| nameSrcSpan name == span -> (nc, name)
| otherwise ->
let name' = setNameLoc name span
new_cache = extendNameCache cache mod occ name'
in ( nc{ nsNames = new_cache }, name' )
Nothing ->
let (uniq, us) = takeUniqFromSupply (nsUniqs nc)
name = mkExternalName uniq mod occ span
Expand Down
7 changes: 6 additions & 1 deletion src-ghc88/Development/IDE/GHC/HieBin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,12 @@ fromHieName :: NameCache -> HieName -> (NameCache, Name)
fromHieName nc (ExternalName mod occ span) =
let cache = nsNames nc
in case lookupOrigNameCache cache mod occ of
Just name -> (nc, name)
Just name
| nameSrcSpan name == span -> (nc, name)
| otherwise ->
let name' = setNameLoc name span
new_cache = extendNameCache cache mod occ name'
in ( nc{ nsNames = new_cache }, name' )
Nothing ->
let (uniq, us) = takeUniqFromSupply (nsUniqs nc)
name = mkExternalName uniq mod occ span
Expand Down

0 comments on commit 96d1f30

Please sign in to comment.