Skip to content

Commit 41bf8b8

Browse files
authored
Wingman: FIx evidence when using GADT constructors (#1889)
* Fix unification pertaining to evidence * Cleanup interface; better names * Need to reapply the substituion after each arg * Reenable error debugging * Add destruct_all evidence test * Fix tests that were accidentally sorted incorrectly * FIx evidence when splitting GADTs
1 parent 1163ae7 commit 41bf8b8

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

Diff for: plugins/hls-tactics-plugin/src/Wingman/CodeGen.hs

+16-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,22 @@ buildDataCon
253253
-> [Type] -- ^ Type arguments for the data con
254254
-> RuleM (Synthesized (LHsExpr GhcPs))
255255
buildDataCon should_blacklist jdg dc tyapps = do
256-
let args = conLikeInstOrigArgTys' dc tyapps
256+
args <- case dc of
257+
RealDataCon dc' -> do
258+
let (skolems', theta, args) = dataConInstSig dc' tyapps
259+
modify $ \ts ->
260+
evidenceToSubst (foldMap mkEvidence theta) ts
261+
& #ts_skolems <>~ S.fromList skolems'
262+
pure args
263+
_ ->
264+
-- If we have a 'PatSyn', we can't continue, since there is no
265+
-- 'dataConInstSig' equivalent for 'PatSyn's. I don't think this is
266+
-- a fundamental problem, but I don't know enough about the GHC internals
267+
-- to implement it myself.
268+
--
269+
-- Fortunately, this isn't an issue in practice, since 'PatSyn's are
270+
-- never in the hypothesis.
271+
throwError $ TacticPanic "Can't build Pattern constructors yet"
257272
ext
258273
<- fmap unzipTrace
259274
$ traverse ( \(arg, n) ->

Diff for: plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ spec = do
6666
autoTest 6 10 "AutoThetaRefl"
6767
autoTest 6 8 "AutoThetaReflDestruct"
6868
autoTest 19 30 "AutoThetaMultipleUnification"
69+
autoTest 16 9 "AutoThetaSplitUnification"
6970

7071
describe "known" $ do
7172
autoTest 25 13 "GoldenArbitrary"
@@ -83,4 +84,5 @@ spec = do
8384

8485
describe "messages" $ do
8586
mkShowMessageTest allFeatures Auto "" 2 8 "MessageForallA" TacticErrors
87+
mkShowMessageTest allFeatures Auto "" 7 8 "MessageCantUnify" TacticErrors
8688

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE GADTs #-}
3+
{-# LANGUAGE KindSignatures #-}
4+
{-# LANGUAGE TypeOperators #-}
5+
6+
data A = A
7+
data B = B
8+
data X = X
9+
data Y = Y
10+
11+
12+
data Pairrow ax by where
13+
Pairrow :: (a -> b) -> (x -> y) -> Pairrow '(a, x) '(b, y)
14+
15+
test2 :: (A -> B) -> (X -> Y) -> Pairrow '(A, X) '(B, Y)
16+
test2 = Pairrow
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE GADTs #-}
3+
{-# LANGUAGE KindSignatures #-}
4+
{-# LANGUAGE TypeOperators #-}
5+
6+
data A = A
7+
data B = B
8+
data X = X
9+
data Y = Y
10+
11+
12+
data Pairrow ax by where
13+
Pairrow :: (a -> b) -> (x -> y) -> Pairrow '(a, x) '(b, y)
14+
15+
test2 :: (A -> B) -> (X -> Y) -> Pairrow '(A, X) '(B, Y)
16+
test2 = _
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE DataKinds, GADTs #-}
2+
3+
data Z ab where
4+
Z :: (a -> b) -> Z '(a, b)
5+
6+
test :: Z ab
7+
test = _
8+

0 commit comments

Comments
 (0)