Skip to content

Commit b1f3c31

Browse files
authored
Merge pull request #474 from konn/tactic-exclude-dictionary
Tactic plugin: Excludes Dictionary arguments in GADTs in Destruct Tactic
2 parents a06b3b8 + 5863127 commit b1f3c31

File tree

9 files changed

+48
-2
lines changed

9 files changed

+48
-2
lines changed

hie.yaml.cbl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ cradle:
2525
- path: "./plugins/default/src"
2626
component: "haskell-language-server:exe:haskell-language-server"
2727

28+
- path: "./plugins/tactics/src"
29+
component: "haskell-language-server:exe:haskell-language-server"
30+
2831
- path: "./exe/Wrapper.hs"
2932
component: "haskell-language-server:exe:haskell-language-server-wrapper"
3033

hie.yaml.stack

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ cradle:
2121

2222
- path: "./plugins/default/src"
2323
component: "haskell-language-server:exe:haskell-language-server"
24+
- path: "./plugins/tactics/src"
25+
component: "haskell-language-server:exe:haskell-language-server"
2426

2527
- path: "./exe/Arguments.hs"
2628
component: "haskell-language-server:exe:haskell-language-server"

plugins/tactics/src/Ide/Plugin/Tactic/CodeGen.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ destructMatches f f2 t jdg = do
3838
case dcs of
3939
[] -> throwError $ GoalMismatch "destruct" g
4040
_ -> for dcs $ \dc -> do
41-
let args = dataConInstArgTys dc apps
41+
let args = dataConInstOrigArgTys' dc apps
4242
names <- mkManyGoodNames hy args
4343

4444
let pat :: Pat GhcPs
@@ -51,9 +51,19 @@ destructMatches f f2 t jdg = do
5151
pure $ match [pat] $ unLoc sg
5252

5353

54+
-- | Essentially same as 'dataConInstOrigArgTys' in GHC,
55+
-- but we need some tweaks in GHC >= 8.8.
56+
-- Since old 'dataConInstArgTys' seems working with >= 8.8,
57+
-- we just filter out non-class types in the result.
58+
dataConInstOrigArgTys' :: DataCon -> [Type] -> [Type]
59+
dataConInstOrigArgTys' con ty =
60+
let tys0 = dataConInstArgTys con ty
61+
in filter (maybe True (not . isClassTyCon) . tyConAppTyCon_maybe) tys0
62+
5463
------------------------------------------------------------------------------
5564
-- | Combinator for performing case splitting, and running sub-rules on the
5665
-- resulting matches.
66+
5767
destruct' :: (DataCon -> Judgement -> Rule) -> OccName -> Judgement -> Rule
5868
destruct' f term jdg = do
5969
let hy = jHypothesis jdg
@@ -85,7 +95,7 @@ buildDataCon
8595
-> [Type] -- ^ Type arguments for the data con
8696
-> RuleM (LHsExpr GhcPs)
8797
buildDataCon jdg dc apps = do
88-
let args = dataConInstArgTys dc apps
98+
let args = dataConInstOrigArgTys' dc apps
8999
sgs <- traverse (newSubgoal . flip withNewGoal jdg . CType) args
90100
pure
91101
. noLoc

stack-8.10.2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extra-deps:
1414
commit: c59655f10d5ad295c2481537fc8abf0a297d9d1c
1515
- Cabal-3.0.2.0
1616
- clock-0.7.2
17+
- data-tree-print-0.1.0.2
1718
- floskell-0.10.4
1819
- fourmolu-0.2.0.0
1920
- monad-dijkstra-0.1.1.2

test/functional/Tactic.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ tests = testGroup
9393
, goldenTest "GoldenEitherHomomorphic.hs" 2 15 Auto ""
9494
, goldenTest "GoldenNote.hs" 2 8 Auto ""
9595
, goldenTest "GoldenPureList.hs" 2 12 Auto ""
96+
, goldenTest "GoldenGADTDestruct.hs" 7 17 Destruct "gadt"
97+
, goldenTest "GoldenGADTAuto.hs" 7 13 Auto ""
9698
]
9799

98100

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE GADTs #-}
2+
module GoldenGADTAuto where
3+
data CtxGADT a where
4+
MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT a
5+
6+
ctxGADT :: CtxGADT ()
7+
ctxGADT = _auto
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE GADTs #-}
2+
module GoldenGADTAuto where
3+
data CtxGADT a where
4+
MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT a
5+
6+
ctxGADT :: CtxGADT ()
7+
ctxGADT = (MkCtxGADT ())
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE GADTs #-}
2+
module GoldenGADTDestruct where
3+
data CtxGADT where
4+
MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT
5+
6+
ctxGADT :: CtxGADT -> String
7+
ctxGADT gadt = _decons
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE GADTs #-}
2+
module GoldenGADTDestruct where
3+
data CtxGADT where
4+
MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT
5+
6+
ctxGADT :: CtxGADT -> String
7+
ctxGADT gadt = (case gadt of { (MkCtxGADT a) -> _ })

0 commit comments

Comments
 (0)