Skip to content

Commit 30fd152

Browse files
Account for boot files in processDependencyInformation
Fixes #4912
1 parent afc8779 commit 30fd152

10 files changed

Lines changed: 54 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Clash.Promoted.Nat (SNat) where
2+
3+
import Clash.XException ()
4+
5+
data SNat = SNat
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
3+
module Clash.Promoted.Nat.Literals where
4+
5+
import Clash.Promoted.Nat.TH
6+
7+
$(snatSplice)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module Clash.Promoted.Nat.TH (snatSplice) where
3+
4+
import Language.Haskell.TH (Q, Dec)
5+
import Clash.Promoted.Nat ()
6+
7+
snatSplice :: Q [Dec]
8+
snatSplice = pure []
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Clash.XException () where
2+
3+
import Clash.XException.Internal ()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Clash.XException where
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Clash.XException.Internal where
2+
3+
import {-# SOURCE #-} Clash.XException ()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cradle:
2+
direct:
3+
arguments:
4+
- "Clash.XException"
5+
- "Clash.XException.Internal"
6+
- "Clash.Promoted.Nat"
7+
- "Clash.Promoted.Nat.Literals"
8+
- "Clash.Promoted.Nat.TH"

ghcide-test/exe/BootTests.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,8 @@ tests = testGroup "boot"
5252
, testCase "graph with boot modules" $ runWithExtraFiles "boot2" $ \dir -> do
5353
_ <- openDoc (dir </> "A.hs") "haskell"
5454
expectNoMoreDiagnostics 2
55+
, testCase "GetLinkable on hs-boot via TH splice (clash-compiler reproducer)" $
56+
runWithExtraFiles "boot-linkable" $ \dir -> do
57+
_ <- openDoc (dir </> "Clash" </> "Promoted" </> "Nat.hs") "haskell"
58+
expectNoMoreDiagnostics 10
5559
]

ghcide/src/Development/IDE/Import/DependencyInformation.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ import Development.IDE.GHC.Compat
5353
import Development.IDE.GHC.Compat.Util (Fingerprint)
5454
import qualified Development.IDE.GHC.Compat.Util as Util
5555
import Development.IDE.GHC.Orphans ()
56-
import Development.IDE.Import.FindImports (ArtifactsLocation (..))
56+
import Development.IDE.Import.FindImports (ArtifactsLocation (..),
57+
isBootLocation)
5758
import Development.IDE.Types.Diagnostics
5859
import Development.IDE.Types.Location
5960
import GHC.Generics (Generic)
@@ -273,7 +274,17 @@ processDependencyInformation RawDependencyInformation{..} rawBootMap mg shallowF
273274
foldr (\(p, cs) res ->
274275
let new = IntMap.fromList (map (, IntSet.singleton (coerce p)) (coerce cs))
275276
in IntMap.unionWith IntSet.union new res ) IntMap.empty successEdges
276-
reverseModuleMap = mkModuleEnv $ map (\(i,sm) -> (showableModule sm, FilePathId i)) $ IntMap.toList rawModuleMap
277+
-- Map 'Module' to 'FilePathId', but skip hs-boot files: 'Module'
278+
-- does not distinguish boot from non-boot, so the real source file
279+
-- and its hs-boot share the same key. Callers (notably the
280+
-- 'GetLinkable' rule via 'lookupModuleFile') need the non-boot
281+
-- file because hs-boot files don't have linkables.
282+
reverseModuleMap = mkModuleEnv
283+
[ (showableModule sm, FilePathId i)
284+
| (i, sm) <- IntMap.toList rawModuleMap
285+
, Just al <- [IntMap.lookup i (idToPathMap rawPathIdMap)]
286+
, not (isBootLocation al)
287+
]
277288

278289

279290
-- | Given a dependency graph, buildResultGraph detects and propagates errors in that graph as follows:

ghcide/src/Development/IDE/Import/FindImports.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ data Import
4141
data ArtifactsLocation = ArtifactsLocation
4242
{ artifactFilePath :: !NormalizedFilePath
4343
, artifactModLocation :: !(Maybe ModLocation)
44-
, artifactIsSource :: !Bool -- ^ True if a module is a source input
44+
, artifactIsSource :: !Bool -- ^ 'True' for a real Haskell source file ('HsSrcFile');
45+
-- 'False' for a boot ('HsBootFile') or signature ('HsigFile') file.
4546
, artifactModule :: !(Maybe Module)
4647
} deriving Show
4748

0 commit comments

Comments
 (0)