Skip to content

Commit ada1b3d

Browse files
committed
hls-graph - avoid duplicating key texts
1 parent eafda04 commit ada1b3d

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti
12071207
addTagUnsafe :: String -> String -> String -> a -> a
12081208
addTagUnsafe msg t x v = unsafePerformIO(addTag (msg <> t) x) `seq` v
12091209
update :: (forall a. String -> String -> a -> a) -> [Diagnostic] -> STMDiagnosticStore -> STM [Diagnostic]
1210-
update addTagUnsafe new store = addTagUnsafe "count" (show $ Prelude.length new) $ setStageDiagnostics addTagUnsafe uri ver (T.pack $ show k) new store
1210+
update addTagUnsafe new store = addTagUnsafe "count" (show $ Prelude.length new) $ setStageDiagnostics addTagUnsafe uri ver (renderKey k) new store
12111211
addTag "version" (show ver)
12121212
mask_ $ do
12131213
-- Mask async exceptions to ensure that updated diagnostics are always

hls-graph/hls-graph.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ library
8282
, transformers
8383
, unliftio
8484
, unordered-containers
85+
, text
8586

8687
if flag(embed-files)
8788
cpp-options: -DFILE_EMBED

hls-graph/src/Development/IDE/Graph.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Development.IDE.Graph(
44
Rules,
55
Action, action,
66
Key(.., Key),
7-
newKey,
7+
newKey, renderKey,
88
actionFinally, actionBracket, actionCatch, actionFork,
99
-- * Configuration
1010
ShakeOptions(shakeAllowRedefineRules, shakeExtra),

hls-graph/src/Development/IDE/Graph/Internal/Types.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import qualified Data.HashMap.Strict as Map
2525
import Data.HashSet (HashSet, member)
2626
import qualified Data.IntMap as IM
2727
import qualified Data.HashSet as Set
28+
import qualified Data.Text as T
29+
import Data.Text (Text)
2830
import Data.IORef
2931
import Data.List (intercalate)
3032
import Data.Maybe
@@ -86,11 +88,11 @@ newtype Step = Step Int
8688
---------------------------------------------------------------------
8789
-- Keys
8890

89-
data KeyValue = forall a . (Typeable a, Hashable a, Show a) => KeyValue a
91+
data KeyValue = forall a . (Typeable a, Hashable a, Show a) => KeyValue a Text
9092

9193
newtype Key = UnsafeMkKey Int
9294

93-
pattern Key a <- (lookupKeyValue -> KeyValue a)
95+
pattern Key a <- (lookupKeyValue -> KeyValue a _)
9496

9597
data KeyMap = KeyMap !(Map.HashMap KeyValue Key) !(IM.IntMap KeyValue) {-# UNPACK #-} !Int
9698

@@ -101,7 +103,7 @@ keyMap = unsafePerformIO $ newIORef (KeyMap Map.empty IM.empty 0)
101103

102104
newKey :: (Typeable a, Hashable a, Show a) => a -> Key
103105
newKey k = unsafePerformIO $ do
104-
let !newKey = KeyValue k
106+
let !newKey = KeyValue k (T.pack (show k))
105107
atomicModifyIORef' keyMap $ \km@(KeyMap hm im n) ->
106108
let new_key = Map.lookup newKey hm
107109
in case new_key of
@@ -126,11 +128,14 @@ instance Show Key where
126128
show (Key x) = show x
127129

128130
instance Eq KeyValue where
129-
KeyValue a == KeyValue b = Just a == cast b
131+
KeyValue a _ == KeyValue b _ = Just a == cast b
130132
instance Hashable KeyValue where
131-
hashWithSalt i (KeyValue x) = hashWithSalt i (typeOf x, x)
133+
hashWithSalt i (KeyValue x _) = hashWithSalt i (typeOf x, x)
132134
instance Show KeyValue where
133-
show (KeyValue x) = show x
135+
show (KeyValue x t) = T.unpack t
136+
137+
renderKey :: Key -> Text
138+
renderKey (lookupKeyValue -> KeyValue _ t) = t
134139

135140
newtype Value = Value Dynamic
136141

0 commit comments

Comments
 (0)