Skip to content

Commit 2d8386c

Browse files
committed
wip: remove the normalized target
It does not seem to be used and apparently had never been used (after a quick look in the repository diff). Ask m.pickering about this.
1 parent c3c06ec commit 2d8386c

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

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

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,26 @@ import Development.IDE.Types.Location
1919
import GHC.Generics
2020

2121
-- | A mapping of module name to known files
22-
data KnownTargets = KnownTargets
23-
{ targetMap :: !(HashMap Target (HashSet NormalizedFilePath))
24-
-- | 'normalisingMap' is a cached copy of `HMap.mapKey const targetMap`
25-
--
26-
-- At startup 'GetLocatedImports' is called on all known files. Say you have 10000
27-
-- modules in your project then this leads to 10000 calls to 'GetLocatedImports'
28-
-- running concurrently.
29-
--
30-
-- In `GetLocatedImports` the known targets are consulted and the targetsMap
31-
-- is created by mapping the known targets. This map is used for introducing
32-
-- sharing amongst filepaths. This operation copies a local copy of the `target`
33-
-- map which is local to the rule.
34-
--
35-
-- @
36-
-- let targetsMap = HMap.mapWithKey const targets
37-
-- @
38-
--
39-
-- So now each rule has a 'HashMap' of size 10000 held locally to it and depending
40-
-- on how the threads are scheduled there will be 10000^2 elements in total
41-
-- allocated in 'HashMap's. This used a lot of memory.
42-
--
43-
-- Solution: Return the 'normalisingMap' in the result of the `GetKnownTargets` rule so it is shared across threads.
44-
, normalisingMap :: !(HashMap Target Target) } deriving Show
22+
newtype KnownTargets = KnownTargets
23+
{ targetMap :: (HashMap Target (HashSet NormalizedFilePath))
24+
} deriving (Show, Eq)
4525

4626

4727
unionKnownTargets :: KnownTargets -> KnownTargets -> KnownTargets
48-
unionKnownTargets (KnownTargets tm nm) (KnownTargets tm' nm') =
49-
KnownTargets (HMap.unionWith (<>) tm tm') (HMap.union nm nm')
28+
unionKnownTargets (KnownTargets tm) (KnownTargets tm') =
29+
KnownTargets (HMap.unionWith (<>) tm tm')
5030

5131
mkKnownTargets :: [(Target, HashSet NormalizedFilePath)] -> KnownTargets
52-
mkKnownTargets vs = KnownTargets (HMap.fromList vs) (HMap.fromList [(k,k) | (k,_) <- vs ])
32+
mkKnownTargets vs = KnownTargets (HMap.fromList vs)
5333

5434
instance NFData KnownTargets where
55-
rnf (KnownTargets tm nm) = rnf tm `seq` rnf nm `seq` ()
56-
57-
instance Eq KnownTargets where
58-
k1 == k2 = targetMap k1 == targetMap k2
35+
rnf (KnownTargets tm) = rnf tm `seq` ()
5936

6037
instance Hashable KnownTargets where
61-
hashWithSalt s (KnownTargets hm _) = hashWithSalt s hm
38+
hashWithSalt s (KnownTargets hm) = hashWithSalt s hm
6239

6340
emptyKnownTargets :: KnownTargets
64-
emptyKnownTargets = KnownTargets HMap.empty HMap.empty
41+
emptyKnownTargets = KnownTargets HMap.empty
6542

6643
data Target = TargetModule ModuleName | TargetFile NormalizedFilePath
6744
deriving ( Eq, Ord, Generic, Show )

0 commit comments

Comments
 (0)