Skip to content

Commit a0def3c

Browse files
authored
Initialize ExportsMap using hiedb exports (#1989)
* Initialize ExportsMap using hiedb exports * bump version number * Add temporary source package to ghc901 cabal project as well * fix stack descriptors * remove source package overrides * refresh cabal index state * fix 9.0.1 build
1 parent d6de2bb commit a0def3c

16 files changed

+53
-51
lines changed

cabal-ghc901.project

+1-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ source-repository-package
4141
tag: b6245884ae83e00dd2b5261762549b37390179f8
4242
-- https://github.com/lspitzner/czipwith/pull/2
4343

44-
4544
source-repository-package
4645
type: git
4746
location: https://github.com/jneira/hie-bios/
@@ -67,12 +66,6 @@ source-repository-package
6766
subdir: dependent-sum-template
6867
-- https://github.com/obsidiansystems/dependent-sum/pull/57
6968

70-
source-repository-package
71-
type: git
72-
location: https://github.com/anka-213/HieDb
73-
tag: a3f7521f6c5af1b977040cce09c8f7354f8984eb
74-
-- https://github.com/wz1000/HieDb/pull/31
75-
7669
source-repository-package
7770
type: git
7871
location: https://github.com/anka-213/lsp
@@ -84,7 +77,7 @@ source-repository-package
8477

8578
write-ghc-environment-files: never
8679

87-
index-state: 2021-06-21T19:57:32Z
80+
index-state: 2021-06-30T16:00:00Z
8881

8982
constraints:
9083
-- These plugins doesn't work on GHC9 yet

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ source-repository-package
3636

3737
write-ghc-environment-files: never
3838

39-
index-state: 2021-06-21T19:57:32Z
39+
index-state: 2021-06-30T16:00:00Z
4040

4141
constraints:
4242
-- Diagrams doesn't support optparse-applicative >= 0.16 yet

ghcide/ghcide.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cabal-version: 2.4
22
build-type: Simple
33
category: Development
44
name: ghcide
5-
version: 1.4.0.2
5+
version: 1.4.0.3
66
license: Apache-2.0
77
license-file: LICENSE
88
author: Digital Asset and Ghcide contributors
@@ -59,7 +59,7 @@ library
5959
hie-compat ^>= 0.2.0.0,
6060
hls-plugin-api ^>= 1.1.0.0,
6161
lens,
62-
hiedb == 0.3.0.*,
62+
hiedb == 0.4.0.*,
6363
lsp-types >= 1.2 && < 1.4,
6464
lsp == 1.2.*,
6565
mtl,

ghcide/src/Development/IDE/Core/OfInterest.hs

+8-25
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,19 @@ module Development.IDE.Core.OfInterest(
1919
import Control.Concurrent.Strict
2020
import Control.Monad
2121
import Control.Monad.IO.Class
22-
import Data.HashMap.Strict (HashMap)
23-
import qualified Data.HashMap.Strict as HashMap
24-
import qualified Data.Text as T
22+
import Data.HashMap.Strict (HashMap)
23+
import qualified Data.HashMap.Strict as HashMap
24+
import qualified Data.Text as T
2525
import Development.IDE.Graph
2626

27-
import Control.Monad.Trans.Class
28-
import Control.Monad.Trans.Maybe
29-
import qualified Data.ByteString as BS
30-
import Data.List.Extra (nubOrd)
31-
import Data.Maybe (catMaybes)
27+
import qualified Data.ByteString as BS
28+
import Data.Maybe (catMaybes)
3229
import Development.IDE.Core.ProgressReporting
3330
import Development.IDE.Core.RuleTypes
3431
import Development.IDE.Core.Shake
35-
import Development.IDE.Import.DependencyInformation
3632
import Development.IDE.Types.Exports
3733
import Development.IDE.Types.Location
3834
import Development.IDE.Types.Logger
39-
import Development.IDE.Types.Options
4035

4136
newtype OfInterestVar = OfInterestVar (Var (HashMap NormalizedFilePath FileOfInterestStatus))
4237
instance IsIdeGlobal OfInterestVar
@@ -98,25 +93,13 @@ deleteFileOfInterest state f = do
9893
kick :: Action ()
9994
kick = do
10095
files <- HashMap.keys <$> getFilesOfInterestUntracked
101-
ShakeExtras{progress} <- getShakeExtras
96+
ShakeExtras{exportsMap, progress} <- getShakeExtras
10297
liftIO $ progressUpdate progress KickStarted
10398

104-
-- Update the exports map for FOIs
99+
-- Update the exports map
105100
results <- uses GenerateCore files <* uses GetHieAst files
106-
107-
-- Update the exports map for non FOIs
108-
-- We can skip this if checkProject is True, assuming they never change under our feet.
109-
IdeOptions{ optCheckProject = doCheckProject } <- getIdeOptions
110-
checkProject <- liftIO doCheckProject
111-
ifaces <- if checkProject then return Nothing else runMaybeT $ do
112-
deps <- MaybeT $ sequence <$> uses GetDependencies files
113-
hiResults <- lift $ uses GetModIface (nubOrd $ foldMap transitiveModuleDeps deps)
114-
return $ map hirModIface $ catMaybes hiResults
115-
116-
ShakeExtras{exportsMap} <- getShakeExtras
117101
let mguts = catMaybes results
118102
!exportsMap' = createExportsMapMg mguts
119-
!exportsMap'' = maybe mempty createExportsMap ifaces
120-
void $ liftIO $ modifyVar' exportsMap $ (exportsMap'' <>) . (exportsMap' <>)
103+
void $ liftIO $ modifyVar' exportsMap (exportsMap' <>)
121104

122105
liftIO $ progressUpdate progress KickCompleted

ghcide/src/Development/IDE/Core/Shake.hs

+8
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ import Data.HashSet (HashSet)
152152
import qualified Data.HashSet as HSet
153153
import Data.IORef.Extra (atomicModifyIORef'_,
154154
atomicModifyIORef_)
155+
import Data.Text (pack)
156+
import qualified Development.IDE.Types.Exports as ExportsMap
155157
import HieDb.Types
156158
import Ide.Plugin.Config
157159
import qualified Ide.PluginUtils as HLS
@@ -507,6 +509,12 @@ shakeOpen lspEnv defaultConfig logger debouncer
507509
indexProgressToken <- newVar Nothing
508510
let hiedbWriter = HieDbWriter{..}
509511
exportsMap <- newVar mempty
512+
-- lazily initialize the exports map with the contents of the hiedb
513+
_ <- async $ do
514+
logDebug logger "Initializing exports map from hiedb"
515+
em <- createExportsMapHieDb hiedb
516+
modifyVar' exportsMap (<> em)
517+
logDebug logger $ "Done initializing exports map from hiedb (" <> pack(show (ExportsMap.size em)) <> ")"
510518

511519
progress <- do
512520
let (before, after) = if testing then (0,0.1) else (0.1,0.1)

ghcide/src/Development/IDE/Types/Exports.hs

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ module Development.IDE.Types.Exports
77
createExportsMap,
88
createExportsMapMg,
99
createExportsMapTc
10-
) where
10+
,createExportsMapHieDb,size) where
1111

1212
import Avail (AvailInfo (..))
1313
import Control.DeepSeq (NFData (..))
14+
import Control.Monad
1415
import Data.Bifunctor (Bifunctor (second))
15-
import Data.HashMap.Strict (HashMap)
16+
import Data.HashMap.Strict (HashMap, elems)
1617
import qualified Data.HashMap.Strict as Map
1718
import Data.HashSet (HashSet)
1819
import qualified Data.HashSet as Set
@@ -23,13 +24,17 @@ import Development.IDE.GHC.Util
2324
import FieldLabel (flSelector)
2425
import GHC.Generics (Generic)
2526
import GhcPlugins (IfaceExport, ModGuts (..))
27+
import HieDb
2628
import Name
2729
import TcRnTypes (TcGblEnv (..))
2830

2931
newtype ExportsMap = ExportsMap
3032
{getExportsMap :: HashMap IdentifierText (HashSet IdentInfo)}
3133
deriving newtype (Monoid, NFData, Show)
3234

35+
size :: ExportsMap -> Int
36+
size = sum . map length . elems . getExportsMap
37+
3338
instance Semigroup ExportsMap where
3439
ExportsMap a <> ExportsMap b = ExportsMap $ Map.unionWith (<>) a b
3540

@@ -104,6 +109,22 @@ createExportsMapTc = ExportsMap . Map.fromListWith (<>) . concatMap doOne
104109
where
105110
mn = moduleName $ tcg_mod mi
106111

112+
createExportsMapHieDb :: HieDb -> IO ExportsMap
113+
createExportsMapHieDb hiedb = do
114+
mods <- getAllIndexedMods hiedb
115+
idents <- forM mods $ \m -> do
116+
let mn = modInfoName $ hieModInfo m
117+
mText = pack $ moduleNameString mn
118+
fmap (wrap . unwrap mText) <$> getExportsForModule hiedb mn
119+
return $ ExportsMap $ Map.fromListWith (<>) (concat idents)
120+
where
121+
wrap identInfo = (name identInfo, Set.fromList [identInfo])
122+
-- unwrap :: ExportRow -> IdentInfo
123+
unwrap m ExportRow{..} = IdentInfo n n p exportIsDatacon m
124+
where
125+
n = pack (occNameString exportName)
126+
p = pack . occNameString <$> exportParent
127+
107128
unpackAvail :: ModuleName -> IfaceExport -> [(Text, [IdentInfo])]
108129
unpackAvail !(pack . moduleNameString -> mod) = map f . mkIdentInfos mod
109130
where

stack-8.10.2.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extra-deps:
5959
- temporary-1.2.1.1
6060
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
6161
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
62-
- hiedb-0.3.0.1
62+
- hiedb-0.4.0.0
6363
- dependent-map-0.4.0.0@sha256:ca2b131046f4340a1c35d138c5a003fe4a5be96b14efc26291ed35fd08c62221,1657
6464
- dependent-sum-0.7.1.0@sha256:5599aa89637db434431b1dd3fa7c34bc3d565ee44f0519bfbc877be1927c2531,2068
6565
- dependent-sum-template-0.1.0.3@sha256:0bbbacdfbd3abf2a15aaf0cf2c27e5bdd159b519441fec39e1e6f2f54424adde,1682

stack-8.10.3.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extra-deps:
5656
- temporary-1.2.1.1
5757
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
5858
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
59-
- hiedb-0.3.0.1
59+
- hiedb-0.4.0.0
6060
- lsp-1.2.0.0
6161
- lsp-types-1.2.0.0
6262
- lsp-test-0.14.0.0

stack-8.10.4.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extra-deps:
5252
- temporary-1.2.1.1
5353
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
5454
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
55-
- hiedb-0.3.0.1
55+
- hiedb-0.4.0.0
5656
- lsp-1.2.0.0
5757
- lsp-types-1.2.0.0
5858
- lsp-test-0.14.0.0

stack-8.10.5.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extra-deps:
5454
- temporary-1.2.1.1
5555
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
5656
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
57-
- hiedb-0.3.0.1
57+
- hiedb-0.4.0.0
5858
- lsp-1.2.0.0
5959
- lsp-types-1.2.0.0
6060
- lsp-test-0.14.0.0

stack-8.6.4.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ extra-deps:
9292
- th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370
9393
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
9494
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
95-
- hiedb-0.3.0.1
95+
- hiedb-0.4.0.0
9696
- extra-1.7.9@sha256:f1dec740f0f2025790c540732bfd52c556ec55bde4f5dfd7cf18e22bd44ff3d0,2683
9797
- lsp-1.2.0.0
9898
- lsp-types-1.2.0.0

stack-8.6.5.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extra-deps:
9393
- th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370
9494
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
9595
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
96-
- hiedb-0.3.0.1
96+
- hiedb-0.4.0.0
9797
- extra-1.7.9@sha256:f1dec740f0f2025790c540732bfd52c556ec55bde4f5dfd7cf18e22bd44ff3d0,2683
9898
- lsp-1.2.0.0
9999
- lsp-types-1.2.0.0

stack-8.8.3.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extra-deps:
7070
- uniplate-1.6.13
7171
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
7272
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
73-
- hiedb-0.3.0.1
73+
- hiedb-0.4.0.0
7474
- sqlite-simple-0.4.18.0@sha256:3ceea56375c0a3590c814e411a4eb86943f8d31b93b110ca159c90689b6b39e5,3002
7575
- direct-sqlite-2.3.26@sha256:04e835402f1508abca383182023e4e2b9b86297b8533afbd4e57d1a5652e0c23,3718
7676
- extra-1.7.9@sha256:f1dec740f0f2025790c540732bfd52c556ec55bde4f5dfd7cf18e22bd44ff3d0,2683

stack-8.8.4.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extra-deps:
6868
- temporary-1.2.1.1
6969
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
7070
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
71-
- hiedb-0.3.0.1
71+
- hiedb-0.4.0.0
7272
- sqlite-simple-0.4.18.0@sha256:3ceea56375c0a3590c814e411a4eb86943f8d31b93b110ca159c90689b6b39e5,3002
7373
- direct-sqlite-2.3.26@sha256:04e835402f1508abca383182023e4e2b9b86297b8533afbd4e57d1a5652e0c23,3718
7474
- lsp-1.2.0.0

stack-9.0.1.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extra-deps:
4343
- ghc-lib-parser-ex-9.0.0.4@sha256:8282b11c3797fc8ba225b245e736cc9a0745d9c48d0f9fea7f9bffb5c9997709,3642
4444
- haddock-library-1.10.0@sha256:2a6c239da9225951a5d837e1ce373faeeae60d1345c78dd0a0b0f29df30c4fe9,4098
4545
- heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417
46+
- hiedb-0.4.0.0
4647
- hlint-3.3@sha256:4218ad6e03050f5d68aeba0e025f5f05e366c8fd49657f2a19df04ee31b2bb23,4154
4748
- implicit-hie-0.1.2.5@sha256:517a98ef72f92f0a1617495222774fed3a751a64b0c06fbfc7b858d7aa5de279,2998
4849
- implicit-hie-cradle-0.3.0.2@sha256:7ad0d10c475ad2b45a068aa0c1b150078ec579746df3b1754d91820354c90696,2594
@@ -81,10 +82,6 @@ extra-deps:
8182
- dependent-sum-template
8283
# https://github.com/obsidiansystems/dependent-sum/pull/57
8384

84-
- github: anka-213/HieDb
85-
commit: a3f7521f6c5af1b977040cce09c8f7354f8984eb
86-
# https://github.com/wz1000/HieDb/pull/31
87-
8885
- github: anka-213/lsp
8986
commit: e96383ab19534128f12acc70a69fbc15d4f298cc
9087
subdirs:

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extra-deps:
4949
- temporary-1.2.1.1
5050
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
5151
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
52-
- hiedb-0.3.0.1
52+
- hiedb-0.4.0.0
5353
- lsp-1.2.0.0
5454
- lsp-types-1.2.0.0
5555
- lsp-test-0.14.0.0

0 commit comments

Comments
 (0)