Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit aaa6968

Browse files
committed
Add Pattern Synonyms for GHC 8.6.4
1 parent 1805ebb commit aaa6968

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

hie-plugin-api/Haskell/Ide/Engine/Compat.hs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE PatternSynonyms #-}
3+
{-# LANGUAGE ViewPatterns #-}
24
module Haskell.Ide.Engine.Compat where
35

6+
7+
import qualified GHC
8+
import qualified Type
9+
import qualified TcHsSyn
10+
import qualified TysWiredIn
11+
412
#if MIN_VERSION_filepath(1,4,2)
513
#else
614
import Data.List
@@ -27,3 +35,35 @@ isExtensionOf :: String -> FilePath -> Bool
2735
isExtensionOf ext@('.':_) = isSuffixOf ext . takeExtensions
2836
isExtensionOf ext = isSuffixOf ('.':ext) . takeExtensions
2937
#endif
38+
39+
40+
#if MIN_VERSION_ghc(8, 6, 0)
41+
42+
pattern HsOverLitType :: Type.Type -> GHC.HsExpr GHC.GhcTc
43+
pattern HsOverLitType t <- GHC.HsOverLit _ (GHC.overLitType -> t)
44+
45+
pattern HsLitType :: Type.Type -> GHC.HsExpr GHC.GhcTc
46+
pattern HsLitType t <- GHC.HsLit _ (TcHsSyn.hsLitType -> t)
47+
48+
pattern HsLamType :: Type.Type -> GHC.HsExpr GHC.GhcTc
49+
pattern HsLamType t <- GHC.HsLam _ ((\(GHC.MG { GHC.mg_ext = groupTy }) -> matchGroupType groupTy) -> t)
50+
51+
pattern HsLamCaseType :: Type.Type -> GHC.HsExpr GHC.GhcTc
52+
pattern HsLamCaseType t <- GHC.HsLamCase _ ((\(GHC.MG { GHC.mg_ext = groupTy }) -> matchGroupType groupTy) -> t)
53+
54+
pattern HsCaseType :: Type.Type -> GHC.HsExpr GHC.GhcTc
55+
pattern HsCaseType t <- GHC.HsCase _ _ ((\(GHC.MG { GHC.mg_ext = groupTy }) -> matchGroupType groupTy) -> t)
56+
57+
pattern ExplicitListType :: Type.Type -> GHC.HsExpr GHC.GhcTc
58+
pattern ExplicitListType t <- GHC.ExplicitList (TysWiredIn.mkListTy -> t) _ _
59+
60+
pattern ExplicitSumType :: Type.Type -> GHC.HsExpr GHC.GhcTc
61+
pattern ExplicitSumType t <- GHC.ExplicitSum (TysWiredIn.mkSumTy -> t) _ _ _
62+
63+
pattern HsMultiIfType :: Type.Type -> GHC.HsExpr GHC.GhcTc
64+
pattern HsMultiIfType t <- GHC.HsMultiIf t _
65+
66+
matchGroupType :: GHC.MatchGroupTc -> GHC.Type
67+
matchGroupType (GHC.MatchGroupTc args res) = Type.mkFunTys args res
68+
69+
#endif

hie-plugin-api/Haskell/Ide/Engine/TypeMap.hs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import Data.Data as Data
1515
import Control.Monad.IO.Class
1616
import Data.Maybe
1717
import qualified TcHsSyn
18-
import qualified TysWiredIn
1918
import qualified CoreUtils
2019
import qualified Type
2120
import qualified Desugar
21+
import Haskell.Ide.Engine.Compat
2222

2323
import Haskell.Ide.Engine.ArtifactMap
2424

@@ -118,20 +118,14 @@ getType hs_env e@(GHC.L spn e') =
118118
-- Some expression forms have their type immediately available
119119
let
120120
tyOpt = case e' of
121-
GHC.HsLit _ l -> Just (TcHsSyn.hsLitType l)
122-
GHC.HsOverLit _ o -> Just (GHC.overLitType o)
123-
124-
GHC.HsLam _ GHC.MG { GHC.mg_ext = groupTy } ->
125-
Just (matchGroupType groupTy)
126-
GHC.HsLamCase _ GHC.MG { GHC.mg_ext = groupTy } ->
127-
Just (matchGroupType groupTy)
128-
GHC.HsCase _ _ GHC.MG { GHC.mg_ext = groupTy } ->
129-
Just (GHC.mg_res_ty groupTy)
130-
131-
GHC.ExplicitList ty _ _ -> Just (TysWiredIn.mkListTy ty)
132-
GHC.ExplicitSum ty _ _ _ -> Just (TysWiredIn.mkSumTy ty)
133-
GHC.HsDo ty _ _ -> Just ty
134-
GHC.HsMultiIf ty _ -> Just ty
121+
HsOverLitType t -> Just t
122+
HsLitType t -> Just t
123+
HsLamType t -> Just t
124+
HsLamCaseType t -> Just t
125+
HsCaseType t -> Just t
126+
ExplicitListType t -> Just t
127+
ExplicitSumType t -> Just t
128+
HsMultiIfType t -> Just t
135129

136130
_ -> Nothing
137131
in case tyOpt of
@@ -142,8 +136,6 @@ getType hs_env e@(GHC.L spn e') =
142136
let res = (spn, ) . CoreUtils.exprType <$> mbe
143137
pure res
144138
where
145-
matchGroupType :: GHC.MatchGroupTc -> GHC.Type
146-
matchGroupType (GHC.MatchGroupTc args res) = Type.mkFunTys args res
147139
-- | Skip desugaring of these expressions for performance reasons.
148140
--
149141
-- See impact on Haddock output (esp. missing type annotations or links)

0 commit comments

Comments
 (0)