Skip to content

Commit 982c4ee

Browse files
authored
Avoid duplicating known targets and import paths (#1590)
1 parent 3f2ea7c commit 982c4ee

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import Packages
8383

8484
import Control.Concurrent.STM (atomically)
8585
import Control.Concurrent.STM.TQueue
86+
import qualified Data.HashSet as Set
8687
import Database.SQLite.Simple
8788
import HIE.Bios.Cradle (yamlConfig)
8889
import HieDb.Create
@@ -247,10 +248,10 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
247248
found <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
248249
return (targetTarget, found)
249250
modifyVarIO' knownTargetsVar $ traverseHashed $ \known -> do
250-
let known' = HM.unionWith (<>) known $ HM.fromList knownTargets
251+
let known' = HM.unionWith (<>) known $ HM.fromList $ map (second Set.fromList) knownTargets
251252
when (known /= known') $
252253
logDebug logger $ "Known files updated: " <>
253-
T.pack(show $ (HM.map . map) fromNormalizedFilePath known')
254+
T.pack(show $ (HM.map . Set.map) fromNormalizedFilePath known')
254255
pure known'
255256

256257
-- Create a new HscEnv from a hieYaml root and a set of options

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import Control.Exception (evaluate, mask, throwIO)
1818
import Control.Monad.Extra (eitherM, join, mapMaybeM)
1919
import Control.Monad.IO.Class
2020
import Data.Either (fromRight)
21+
import Data.Set (Set)
22+
import qualified Data.Set as Set
2123
import Data.Unique
2224
import Development.IDE.GHC.Compat
2325
import Development.IDE.GHC.Error (catchSrcErrors)
@@ -48,7 +50,7 @@ data HscEnvEq = HscEnvEq
4850
-- ^ In memory components for this HscEnv
4951
-- This is only used at the moment for the import dirs in
5052
-- the DynFlags
51-
, envImportPaths :: Maybe [String]
53+
, envImportPaths :: Maybe (Set FilePath)
5254
-- ^ If Just, import dirs originally configured in this env
5355
-- If Nothing, the env import dirs are unaltered
5456
, envPackageExports :: IO ExportsMap
@@ -69,9 +71,9 @@ newHscEnvEq cradlePath hscEnv0 deps = do
6971
importPathsCanon <-
7072
mapM canonicalizePath $ relativeToCradle <$> importPaths (hsc_dflags hscEnv0)
7173

72-
newHscEnvEqWithImportPaths (Just importPathsCanon) hscEnv deps
74+
newHscEnvEqWithImportPaths (Just $ Set.fromList importPathsCanon) hscEnv deps
7375

74-
newHscEnvEqWithImportPaths :: Maybe [String] -> HscEnv -> [(InstalledUnitId, DynFlags)] -> IO HscEnvEq
76+
newHscEnvEqWithImportPaths :: Maybe (Set FilePath) -> HscEnv -> [(InstalledUnitId, DynFlags)] -> IO HscEnvEq
7577
newHscEnvEqWithImportPaths envImportPaths hscEnv deps = do
7678

7779
let dflags = hsc_dflags hscEnv
@@ -121,7 +123,7 @@ newHscEnvEqPreserveImportPaths = newHscEnvEqWithImportPaths Nothing
121123
hscEnvWithImportPaths :: HscEnvEq -> HscEnv
122124
hscEnvWithImportPaths HscEnvEq{..}
123125
| Just imps <- envImportPaths
124-
= hscEnv{hsc_dflags = (hsc_dflags hscEnv){importPaths = imps}}
126+
= hscEnv{hsc_dflags = (hsc_dflags hscEnv){importPaths = Set.toList imps}}
125127
| otherwise
126128
= hscEnv
127129

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import Development.IDE.Types.Location
1414
import GHC.Generics
1515

1616
-- | A mapping of module name to known files
17-
type KnownTargets = HashMap Target [NormalizedFilePath]
17+
type KnownTargets = HashMap Target (HashSet NormalizedFilePath)
1818

1919
data Target = TargetModule ModuleName | TargetFile NormalizedFilePath
2020
deriving ( Eq, Generic, Show )
2121
deriving anyclass (Hashable, NFData)
2222

2323
toKnownFiles :: KnownTargets -> HashSet NormalizedFilePath
24-
toKnownFiles = HSet.fromList . concat . HMap.elems
24+
toKnownFiles = HSet.unions . HMap.elems

0 commit comments

Comments
 (0)