Skip to content

Commit 7bb6e18

Browse files
committed
Initialize ExportsMap using hiedb exports
1 parent e48e02a commit 7bb6e18

File tree

6 files changed

+48
-30
lines changed

6 files changed

+48
-30
lines changed

cabal.project

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ packages:
2222
./plugins/hls-pragmas-plugin
2323
./plugins/hls-module-name-plugin
2424
./plugins/hls-ormolu-plugin
25-
tests: true
25+
../HieDb
2626

2727
package *
2828
ghc-options: -haddock
@@ -34,6 +34,12 @@ source-repository-package
3434
location: https://github.com/hsyl20/ghc-api-compat
3535
tag: 8fee87eac97a538dbe81ff1ab18cff10f2f9fa15
3636

37+
source-repository-package
38+
type: git
39+
location: https://github.com/pepeiborra/HieDb
40+
tag: d983a61a0ff97b4e01e13d3da8e9023fcdff7f64
41+
42+
3743
write-ghc-environment-files: never
3844

3945
index-state: 2021-06-21T19:57:32Z

ghcide/ghcide.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.*,
6464
lsp == 1.2.*,
6565
mtl,

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
398398
restartShakeSession []
399399

400400
-- Typecheck all files in the project on startup
401-
checkProject <- getCheckProject
401+
checkProject <- pure False -- getCheckProject
402402
unless (null cs || not checkProject) $ do
403403
cfps' <- liftIO $ filterM (IO.doesFileExist . fromNormalizedFilePath) (concatMap targetLocations cs)
404404
void $ shakeEnqueue extras $ mkDelayedAction "InitialLoad" Debug $ void $ do

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

Lines changed: 8 additions & 25 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 23 additions & 2 deletions
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

0 commit comments

Comments
 (0)