Skip to content

Commit 82ae692

Browse files
committed
Fix lint - use nubOrd on the values map keys
1 parent 808cec8 commit 82ae692

File tree

13 files changed

+56
-42
lines changed

13 files changed

+56
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ modifyFileExists state changes = do
102102
type instance RuleResult GetFileExists = Bool
103103

104104
data GetFileExists = GetFileExists
105-
deriving (Eq, Show, Typeable, Generic)
105+
deriving (Eq, Ord, Show, Typeable, Generic)
106106

107107
instance NFData GetFileExists
108108
instance Hashable GetFileExists

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ instance IsIdeGlobal OfInterestVar
4040
type instance RuleResult GetFilesOfInterest = HashMap NormalizedFilePath FileOfInterestStatus
4141

4242
data GetFilesOfInterest = GetFilesOfInterest
43-
deriving (Eq, Show, Typeable, Generic)
43+
deriving (Eq, Ord, Show, Typeable, Generic)
4444
instance Hashable GetFilesOfInterest
4545
instance NFData GetFilesOfInterest
4646
instance Binary GetFilesOfInterest

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ type instance RuleResult GetKnownTargets = KnownTargets
7373
type instance RuleResult GenerateCore = ModGuts
7474

7575
data GenerateCore = GenerateCore
76-
deriving (Eq, Show, Typeable, Generic)
76+
deriving (Eq, Ord, Show, Typeable, Generic)
7777
instance Hashable GenerateCore
7878
instance NFData GenerateCore
7979
instance Binary GenerateCore
8080

8181
data GetImportMap = GetImportMap
82-
deriving (Eq, Show, Typeable, Generic)
82+
deriving (Eq, Ord, Show, Typeable, Generic)
8383
instance Hashable GetImportMap
8484
instance NFData GetImportMap
8585
instance Binary GetImportMap
@@ -197,7 +197,7 @@ type instance RuleResult GetModIfaceWithoutLinkable = HiFileResult
197197
type instance RuleResult GetFileContents = (FileVersion, Maybe Text)
198198

199199
-- The Shake key type for getModificationTime queries
200-
data GetModificationTime = GetModificationTime_
200+
newtype GetModificationTime = GetModificationTime_
201201
{ missingFileDiagnostics :: Bool
202202
-- ^ If false, missing file diagnostics are not reported
203203
}
@@ -208,6 +208,11 @@ instance Eq GetModificationTime where
208208
-- independent from the 'missingFileDiagnostics' field
209209
_ == _ = True
210210

211+
instance Ord GetModificationTime where
212+
-- Since the diagnostics are not part of the answer, the query identity is
213+
-- independent from the 'missingFileDiagnostics' field
214+
compare _ _ = EQ
215+
211216
instance Hashable GetModificationTime where
212217
-- Since the diagnostics are not part of the answer, the query identity is
213218
-- independent from the 'missingFileDiagnostics' field
@@ -236,20 +241,20 @@ vfsVersion (VFSVersion i) = Just i
236241
vfsVersion ModificationTime{} = Nothing
237242

238243
data GetFileContents = GetFileContents
239-
deriving (Eq, Show, Generic)
244+
deriving (Eq, Ord, Show, Generic)
240245
instance Hashable GetFileContents
241246
instance NFData GetFileContents
242247
instance Binary GetFileContents
243248

244249

245250
data FileOfInterestStatus = OnDisk | Modified
246-
deriving (Eq, Show, Typeable, Generic)
251+
deriving (Eq, Ord, Show, Typeable, Generic)
247252
instance Hashable FileOfInterestStatus
248253
instance NFData FileOfInterestStatus
249254
instance Binary FileOfInterestStatus
250255

251256
data IsFileOfInterestResult = NotFOI | IsFOI FileOfInterestStatus
252-
deriving (Eq, Show, Typeable, Generic)
257+
deriving (Eq, Ord, Show, Typeable, Generic)
253258
instance Hashable IsFileOfInterestResult
254259
instance NFData IsFileOfInterestResult
255260
instance Binary IsFileOfInterestResult
@@ -265,13 +270,13 @@ type instance RuleResult GetModSummary = (ModSummary,[LImportDecl GhcPs])
265270
type instance RuleResult GetModSummaryWithoutTimestamps = (ModSummary,[LImportDecl GhcPs])
266271

267272
data GetParsedModule = GetParsedModule
268-
deriving (Eq, Show, Typeable, Generic)
273+
deriving (Eq, Ord, Show, Typeable, Generic)
269274
instance Hashable GetParsedModule
270275
instance NFData GetParsedModule
271276
instance Binary GetParsedModule
272277

273278
data GetLocatedImports = GetLocatedImports
274-
deriving (Eq, Show, Typeable, Generic)
279+
deriving (Eq, Ord, Show, Typeable, Generic)
275280
instance Hashable GetLocatedImports
276281
instance NFData GetLocatedImports
277282
instance Binary GetLocatedImports
@@ -280,109 +285,109 @@ instance Binary GetLocatedImports
280285
type instance RuleResult NeedsCompilation = Bool
281286

282287
data NeedsCompilation = NeedsCompilation
283-
deriving (Eq, Show, Typeable, Generic)
288+
deriving (Eq, Ord, Show, Typeable, Generic)
284289
instance Hashable NeedsCompilation
285290
instance NFData NeedsCompilation
286291
instance Binary NeedsCompilation
287292

288293
data GetDependencyInformation = GetDependencyInformation
289-
deriving (Eq, Show, Typeable, Generic)
294+
deriving (Eq, Ord, Show, Typeable, Generic)
290295
instance Hashable GetDependencyInformation
291296
instance NFData GetDependencyInformation
292297
instance Binary GetDependencyInformation
293298

294299
data GetModuleGraph = GetModuleGraph
295-
deriving (Eq, Show, Typeable, Generic)
300+
deriving (Eq, Ord, Show, Typeable, Generic)
296301
instance Hashable GetModuleGraph
297302
instance NFData GetModuleGraph
298303
instance Binary GetModuleGraph
299304

300305
data ReportImportCycles = ReportImportCycles
301-
deriving (Eq, Show, Typeable, Generic)
306+
deriving (Eq, Ord, Show, Typeable, Generic)
302307
instance Hashable ReportImportCycles
303308
instance NFData ReportImportCycles
304309
instance Binary ReportImportCycles
305310

306311
data GetDependencies = GetDependencies
307-
deriving (Eq, Show, Typeable, Generic)
312+
deriving (Eq, Ord, Show, Typeable, Generic)
308313
instance Hashable GetDependencies
309314
instance NFData GetDependencies
310315
instance Binary GetDependencies
311316

312317
data TypeCheck = TypeCheck
313-
deriving (Eq, Show, Typeable, Generic)
318+
deriving (Eq, Ord, Show, Typeable, Generic)
314319
instance Hashable TypeCheck
315320
instance NFData TypeCheck
316321
instance Binary TypeCheck
317322

318323
data GetDocMap = GetDocMap
319-
deriving (Eq, Show, Typeable, Generic)
324+
deriving (Eq, Ord, Show, Typeable, Generic)
320325
instance Hashable GetDocMap
321326
instance NFData GetDocMap
322327
instance Binary GetDocMap
323328

324329
data GetHieAst = GetHieAst
325-
deriving (Eq, Show, Typeable, Generic)
330+
deriving (Eq, Ord, Show, Typeable, Generic)
326331
instance Hashable GetHieAst
327332
instance NFData GetHieAst
328333
instance Binary GetHieAst
329334

330335
data GetBindings = GetBindings
331-
deriving (Eq, Show, Typeable, Generic)
336+
deriving (Eq, Ord, Show, Typeable, Generic)
332337
instance Hashable GetBindings
333338
instance NFData GetBindings
334339
instance Binary GetBindings
335340

336341
data GhcSession = GhcSession
337-
deriving (Eq, Show, Typeable, Generic)
342+
deriving (Eq, Ord, Show, Typeable, Generic)
338343
instance Hashable GhcSession
339344
instance NFData GhcSession
340345
instance Binary GhcSession
341346

342-
data GhcSessionDeps = GhcSessionDeps deriving (Eq, Show, Typeable, Generic)
347+
data GhcSessionDeps = GhcSessionDeps deriving (Eq, Ord, Show, Typeable, Generic)
343348
instance Hashable GhcSessionDeps
344349
instance NFData GhcSessionDeps
345350
instance Binary GhcSessionDeps
346351

347352
data GetModIfaceFromDisk = GetModIfaceFromDisk
348-
deriving (Eq, Show, Typeable, Generic)
353+
deriving (Eq, Ord, Show, Typeable, Generic)
349354
instance Hashable GetModIfaceFromDisk
350355
instance NFData GetModIfaceFromDisk
351356
instance Binary GetModIfaceFromDisk
352357

353358
data GetModIface = GetModIface
354-
deriving (Eq, Show, Typeable, Generic)
359+
deriving (Eq, Ord, Show, Typeable, Generic)
355360
instance Hashable GetModIface
356361
instance NFData GetModIface
357362
instance Binary GetModIface
358363

359364
data GetModIfaceWithoutLinkable = GetModIfaceWithoutLinkable
360-
deriving (Eq, Show, Typeable, Generic)
365+
deriving (Eq, Ord, Show, Typeable, Generic)
361366
instance Hashable GetModIfaceWithoutLinkable
362367
instance NFData GetModIfaceWithoutLinkable
363368
instance Binary GetModIfaceWithoutLinkable
364369

365370
data IsFileOfInterest = IsFileOfInterest
366-
deriving (Eq, Show, Typeable, Generic)
371+
deriving (Eq, Ord, Show, Typeable, Generic)
367372
instance Hashable IsFileOfInterest
368373
instance NFData IsFileOfInterest
369374
instance Binary IsFileOfInterest
370375

371376
data GetModSummaryWithoutTimestamps = GetModSummaryWithoutTimestamps
372-
deriving (Eq, Show, Typeable, Generic)
377+
deriving (Eq, Ord, Show, Typeable, Generic)
373378
instance Hashable GetModSummaryWithoutTimestamps
374379
instance NFData GetModSummaryWithoutTimestamps
375380
instance Binary GetModSummaryWithoutTimestamps
376381

377382
data GetModSummary = GetModSummary
378-
deriving (Eq, Show, Typeable, Generic)
383+
deriving (Eq, Ord, Show, Typeable, Generic)
379384
instance Hashable GetModSummary
380385
instance NFData GetModSummary
381386
instance Binary GetModSummary
382387

383388
-- | Get the vscode client settings stored in the ide state
384389
data GetClientSettings = GetClientSettings
385-
deriving (Eq, Show, Typeable, Generic)
390+
deriving (Eq, Ord, Show, Typeable, Generic)
386391
instance Hashable GetClientSettings
387392
instance NFData GetClientSettings
388393
instance Binary GetClientSettings
@@ -394,7 +399,7 @@ type instance RuleResult GetClientSettings = Hashed (Maybe Value)
394399
-- https://github.com/digital-asset/daml/pull/2808#issuecomment-529639547
395400
type instance RuleResult GhcSessionIO = IdeGhcSession
396401

397-
data GhcSessionIO = GhcSessionIO deriving (Eq, Show, Typeable, Generic)
402+
data GhcSessionIO = GhcSessionIO deriving (Eq, Ord, Show, Typeable, Generic)
398403
instance Hashable GhcSessionIO
399404
instance NFData GhcSessionIO
400405
instance Binary GhcSessionIO

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ mainRule = do
973973
-- corresponding `.hi` file is stable, that is, if it is newer
974974
-- than the src file, and all its dependencies are stable too.
975975
data IsHiFileStable = IsHiFileStable
976-
deriving (Eq, Show, Typeable, Generic)
976+
deriving (Eq, Ord, Show, Typeable, Generic)
977977
instance Hashable IsHiFileStable
978978
instance NFData IsHiFileStable
979979
instance Binary IsHiFileStable

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ mappingForVersion allMappings file ver =
266266
type IdeRule k v =
267267
( Shake.RuleResult k ~ v
268268
, Shake.ShakeValue k
269+
, Ord k
269270
, Show v
270271
, Typeable v
271272
, NFData v
@@ -320,7 +321,7 @@ setValues state key file val = modifyVar_ state $ \vals -> do
320321

321322
-- | Delete the value stored for a given ide build key
322323
deleteValue
323-
:: (Typeable k, Hashable k, Eq k, Show k)
324+
:: (Typeable k, Hashable k, Ord k, Show k)
324325
=> IdeState
325326
-> k
326327
-> NormalizedFilePath
@@ -910,7 +911,7 @@ data OnDiskRule = OnDiskRule
910911
-- The reason why this code lives in ghcide and in particular in this module is that it depends quite heavily on
911912
-- the internals of this module that we do not want to expose.
912913
defineOnDisk
913-
:: (Shake.ShakeValue k, RuleResult k ~ ())
914+
:: (Shake.ShakeValue k, RuleResult k ~ (), Ord k)
914915
=> (k -> NormalizedFilePath -> OnDiskRule)
915916
-> Rules ()
916917
defineOnDisk act = addBuiltinRule noLint noIdentity $

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ performMeasurement logger stateRef instrumentFor mapCountInstrument = do
111111
`catch` \(e::SomeException) ->
112112
logInfo logger ("MEMORY PROFILING ERROR: " <> fromString (show e))
113113

114-
{-# ANN startTelemetry ("HLint: ignore Use nubOrd" :: String) #-}
114+
{-# ANN performMeasurement ("HLint: ignore Use nubOrd" :: String) #-}
115115

116116
type OurValueObserver = Int -> IO ()
117117

ghcide/src/Development/IDE/GHC/Util.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ instance Show HscEnvEq where
229229
instance Eq HscEnvEq where
230230
a == b = envUnique a == envUnique b
231231

232+
instance Ord HscEnvEq where
233+
a `compare` b = envUnique a `compare` envUnique b
234+
232235
instance NFData HscEnvEq where
233236
rnf (HscEnvEq a b c d) = rnf (hashUnique a) `seq` b `seq` c `seq` rnf d
234237

ghcide/src/Development/IDE/Plugin/CodeAction/RuleTypes.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import GHC.Generics (Generic)
1717
type instance RuleResult PackageExports = ExportsMap
1818

1919
newtype PackageExports = PackageExports HscEnvEq
20-
deriving (Eq, Show, Typeable, Generic)
20+
deriving (Eq, Ord, Show, Typeable, Generic)
2121

2222
instance Hashable PackageExports
2323
instance NFData PackageExports

ghcide/src/Development/IDE/Plugin/Completions.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ type instance RuleResult LocalCompletions = CachedCompletions
9797
type instance RuleResult NonLocalCompletions = CachedCompletions
9898

9999
data ProduceCompletions = ProduceCompletions
100-
deriving (Eq, Show, Typeable, Generic)
100+
deriving (Eq, Ord, Show, Typeable, Generic)
101101
instance Hashable ProduceCompletions
102102
instance NFData ProduceCompletions
103103
instance Binary ProduceCompletions
104104

105105
data LocalCompletions = LocalCompletions
106-
deriving (Eq, Show, Typeable, Generic)
106+
deriving (Eq, Ord, Show, Typeable, Generic)
107107
instance Hashable LocalCompletions
108108
instance NFData LocalCompletions
109109
instance Binary LocalCompletions
110110

111111
data NonLocalCompletions = NonLocalCompletions
112-
deriving (Eq, Show, Typeable, Generic)
112+
deriving (Eq, Ord, Show, Typeable, Generic)
113113
instance Hashable NonLocalCompletions
114114
instance NFData NonLocalCompletions
115115
instance Binary NonLocalCompletions

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ currentValue Failed = Nothing
2828
type Values = HashMap (NormalizedFilePath, Key) (Value Dynamic)
2929

3030
-- | Key type
31-
data Key = forall k . (Typeable k, Hashable k, Eq k, Show k) => Key k
31+
data Key = forall k . (Typeable k, Hashable k, Ord k, Show k) => Key k
3232

3333
instance Show Key where
3434
show (Key k) = show k
@@ -37,5 +37,10 @@ instance Eq Key where
3737
Key k1 == Key k2 | Just k2' <- cast k2 = k1 == k2'
3838
| otherwise = False
3939

40+
instance Ord Key where
41+
Key k1 `compare` Key k2 | Just k2' <- cast k2 = k1 `compare` k2'
42+
| otherwise = compare (typeOf k1) (typeOf k2)
43+
44+
4045
instance Hashable Key where
4146
hashWithSalt salt (Key key) = hashWithSalt salt (typeOf key, key)

plugins/default/src/Ide/Plugin/Example.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ blah _ (Position line col)
5959
-- ---------------------------------------------------------------------
6060

6161
data Example = Example
62-
deriving (Eq, Show, Typeable, Generic)
62+
deriving (Eq, Ord, Show, Typeable, Generic)
6363
instance Hashable Example
6464
instance NFData Example
6565
instance Binary Example

plugins/default/src/Ide/Plugin/Example2.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ blah _ (Position line col)
5858
-- ---------------------------------------------------------------------
5959

6060
data Example2 = Example2
61-
deriving (Eq, Show, Typeable, Generic)
61+
deriving (Eq, Ord, Show, Typeable, Generic)
6262
instance Hashable Example2
6363
instance NFData Example2
6464
instance Binary Example2

plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ descriptor plId = (defaultPluginDescriptor plId)
7777
-- This rule only exists for generating file diagnostics
7878
-- so the RuleResult is empty
7979
data GetHlintDiagnostics = GetHlintDiagnostics
80-
deriving (Eq, Show, Typeable, Generic)
80+
deriving (Eq, Ord, Show, Typeable, Generic)
8181
instance Hashable GetHlintDiagnostics
8282
instance NFData GetHlintDiagnostics
8383
instance Binary GetHlintDiagnostics
@@ -214,7 +214,7 @@ data HlintUsage
214214
deriving Show
215215

216216
data GetHlintSettings = GetHlintSettings
217-
deriving (Eq, Show, Typeable, Generic)
217+
deriving (Eq, Ord, Show, Typeable, Generic)
218218
instance Hashable GetHlintSettings
219219
instance NFData GetHlintSettings
220220
instance NFData Hint where rnf = rwhnf

0 commit comments

Comments
 (0)