Skip to content

Tactic plugin: Excludes Dictionary arguments in GADTs in Destruct Tactic #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hie.yaml.cbl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ cradle:
- path: "./plugins/default/src"
component: "haskell-language-server:exe:haskell-language-server"

- path: "./plugins/tactics/src"
component: "haskell-language-server:exe:haskell-language-server"

- path: "./exe/Wrapper.hs"
component: "haskell-language-server:exe:haskell-language-server-wrapper"

Expand Down
2 changes: 2 additions & 0 deletions hie.yaml.stack
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ cradle:

- path: "./plugins/default/src"
component: "haskell-language-server:exe:haskell-language-server"
- path: "./plugins/tactics/src"
component: "haskell-language-server:exe:haskell-language-server"

- path: "./exe/Arguments.hs"
component: "haskell-language-server:exe:haskell-language-server"
Expand Down
14 changes: 12 additions & 2 deletions plugins/tactics/src/Ide/Plugin/Tactic/CodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ destructMatches f f2 t jdg = do
case dcs of
[] -> throwError $ GoalMismatch "destruct" g
_ -> for dcs $ \dc -> do
let args = dataConInstArgTys dc apps
let args = dataConInstOrigArgTys' dc apps
names <- mkManyGoodNames hy args

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


-- | Essentially same as 'dataConInstOrigArgTys' in GHC,
-- but we need some tweaks in GHC >= 8.8.
-- Since old 'dataConInstArgTys' seems working with >= 8.8,
-- we just filter out non-class types in the result.
dataConInstOrigArgTys' :: DataCon -> [Type] -> [Type]
dataConInstOrigArgTys' con ty =
let tys0 = dataConInstArgTys con ty
in filter (maybe True (not . isClassTyCon) . tyConAppTyCon_maybe) tys0

------------------------------------------------------------------------------
-- | Combinator for performing case splitting, and running sub-rules on the
-- resulting matches.

destruct' :: (DataCon -> Judgement -> Rule) -> OccName -> Judgement -> Rule
destruct' f term jdg = do
let hy = jHypothesis jdg
Expand Down Expand Up @@ -85,7 +95,7 @@ buildDataCon
-> [Type] -- ^ Type arguments for the data con
-> RuleM (LHsExpr GhcPs)
buildDataCon jdg dc apps = do
let args = dataConInstArgTys dc apps
let args = dataConInstOrigArgTys' dc apps
sgs <- traverse (newSubgoal . flip withNewGoal jdg . CType) args
pure
. noLoc
Expand Down
1 change: 1 addition & 0 deletions stack-8.10.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extra-deps:
commit: c59655f10d5ad295c2481537fc8abf0a297d9d1c
- Cabal-3.0.2.0
- clock-0.7.2
- data-tree-print-0.1.0.2
- floskell-0.10.4
- fourmolu-0.2.0.0
- monad-dijkstra-0.1.1.2
Expand Down
2 changes: 2 additions & 0 deletions test/functional/Tactic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ tests = testGroup
, goldenTest "GoldenEitherHomomorphic.hs" 2 15 Auto ""
, goldenTest "GoldenNote.hs" 2 8 Auto ""
, goldenTest "GoldenPureList.hs" 2 12 Auto ""
, goldenTest "GoldenGADTDestruct.hs" 7 17 Destruct "gadt"
, goldenTest "GoldenGADTAuto.hs" 7 13 Auto ""
]


Expand Down
7 changes: 7 additions & 0 deletions test/testdata/tactic/GoldenGADTAuto.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE GADTs #-}
module GoldenGADTAuto where
data CtxGADT a where
MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT a

ctxGADT :: CtxGADT ()
ctxGADT = _auto
7 changes: 7 additions & 0 deletions test/testdata/tactic/GoldenGADTAuto.hs.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE GADTs #-}
module GoldenGADTAuto where
data CtxGADT a where
MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT a

ctxGADT :: CtxGADT ()
ctxGADT = (MkCtxGADT ())
7 changes: 7 additions & 0 deletions test/testdata/tactic/GoldenGADTDestruct.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE GADTs #-}
module GoldenGADTDestruct where
data CtxGADT where
MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT

ctxGADT :: CtxGADT -> String
ctxGADT gadt = _decons
7 changes: 7 additions & 0 deletions test/testdata/tactic/GoldenGADTDestruct.hs.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE GADTs #-}
module GoldenGADTDestruct where
data CtxGADT where
MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT

ctxGADT :: CtxGADT -> String
ctxGADT gadt = (case gadt of { (MkCtxGADT a) -> _ })