Skip to content

Commit 0344a5a

Browse files
MangoIVfendor
authored andcommitted
[chore] remove unnecessary instance and use of unsafeCoerce
- unsafeCoerce was used where `eqTypeRep` could be used, this was corrected - an incorrect instance for NFData existed which was removed because it's unused
1 parent 111ad4c commit 0344a5a

File tree

1 file changed

+10
-12
lines changed
  • ghcide/src/Development/IDE/Types

1 file changed

+10
-12
lines changed

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ import GHC.Generics
3333
import HieDb.Types (HieDb)
3434
import qualified StmContainers.Map as STM
3535
import Type.Reflection (SomeTypeRep (SomeTypeRep),
36-
pattern App, pattern Con,
37-
typeOf, typeRep,
38-
typeRepTyCon)
39-
import Unsafe.Coerce (unsafeCoerce)
36+
eqTypeRep, pattern App,
37+
type (:~~:) (HRefl),
38+
typeOf, typeRep)
4039

4140
-- | Intended to represent HieDb calls wrapped with (currently) retry
4241
-- functionality
@@ -86,11 +85,12 @@ fromKey (Key k)
8685

8786
-- | fromKeyType (Q (k,f)) = (typeOf k, f)
8887
fromKeyType :: Key -> Maybe (SomeTypeRep, NormalizedFilePath)
89-
fromKeyType (Key k) = case typeOf k of
90-
App (Con tc) a | tc == typeRepTyCon (typeRep @Q)
91-
-> case unsafeCoerce k of
92-
Q (_ :: (), f) -> Just (SomeTypeRep a, f)
93-
_ -> Nothing
88+
fromKeyType (Key k)
89+
| App tc a <- typeOf k
90+
, Just HRefl <- tc `eqTypeRep` (typeRep @Q)
91+
, Q (_, f) <- k
92+
= Just (SomeTypeRep a, f)
93+
| otherwise = Nothing
9494

9595
toNoFileKey :: (Show k, Typeable k, Eq k, Hashable k) => k -> Key
9696
toNoFileKey k = newKey $ Q (k, emptyFilePath)
@@ -101,13 +101,11 @@ newtype Q k = Q (k, NormalizedFilePath)
101101
instance Show k => Show (Q k) where
102102
show (Q (k, file)) = show k ++ "; " ++ fromNormalizedFilePath file
103103

104-
-- | Invariant: the 'v' must be in normal form (fully evaluated).
104+
-- | Invariant: the @v@ must be in normal form (fully evaluated).
105105
-- Otherwise we keep repeatedly 'rnf'ing values taken from the Shake database
106106
newtype A v = A (Value v)
107107
deriving Show
108108

109-
instance NFData (A v) where rnf (A v) = v `seq` ()
110-
111109
-- In the Shake database we only store one type of key/result pairs,
112110
-- namely Q (question) / A (answer).
113111
type instance RuleResult (Q k) = A (RuleResult k)

0 commit comments

Comments
 (0)