summaryrefslogtreecommitdiff
path: root/testsuite/tests/dependent
diff options
context:
space:
mode:
authorRichard Eisenberg <rae@cs.brynmawr.edu>2017-08-03 15:18:39 -0400
committerRichard Eisenberg <rae@cs.brynmawr.edu>2018-03-26 17:23:48 -0400
commite3dbb44f53b2f9403d20d84e27f187062755a089 (patch)
tree43c519461c0693f5b5432f606aa36a941b135727 /testsuite/tests/dependent
parent97e1f300e4f6aef06863d056dc7992fef6b21538 (diff)
downloadhaskell-e3dbb44f53b2f9403d20d84e27f187062755a089.tar.gz
Fix #12919 by making the flattener homegeneous.
This changes a key invariant of the flattener. Previously, flattening a type meant flattening its kind as well. But now, flattening is always homogeneous -- that is, the kind of the flattened type is the same as the kind of the input type. This is achieved by various wizardry in the TcFlatten.flatten_many function, as described in Note [flatten_many]. There are several knock-on effects, including some refactoring in the canonicalizer to take proper advantage of the flattener's changed behavior. In particular, the tyvar case of can_eq_nc' no longer needs to take casts into account. Another effect is that flattening a tyconapp might change it into a casted tyconapp. This might happen if the result kind of the tycon contains a variable, and that variable changes during flattening. Because the flattener is homogeneous, it tacks on a cast to keep the tyconapp kind the same. However, this is problematic when flattening CFunEqCans, which need to have an uncasted tyconapp on the LHS and must remain homogeneous. The solution is a more involved canCFunEqCan, described in Note [canCFunEqCan]. This patch fixes #13643 (as tested in typecheck/should_compile/T13643) and the panic in typecheck/should_compile/T13822 (as reported in #14024). Actually, there were two bugs in T13822: the first was just some incorrect logic in tryFill (part of the unflattener) -- also fixed in this patch -- and the other was the main bug fixed in this ticket. The changes in this patch exposed a long-standing flaw in OptCoercion, in that breaking apart an AppCo sometimes has unexpected effects on kinds. See new Note [EtaAppCo] in OptCoercion, which explains the problem and fix. Also here is a reversion of the major change in 09bf135ace55ce2572bf4168124d631e386c64bb, affecting ctEvCoercion. It turns out that making the flattener homogeneous changes the invariants on the algorithm, making the change in that patch no longer necessary. This patch also fixes: #14038 (dependent/should_compile/T14038) #13910 (dependent/should_compile/T13910) #13938 (dependent/should_compile/T13938) #14441 (typecheck/should_compile/T14441) #14556 (dependent/should_compile/T14556) #14720 (dependent/should_compile/T14720) #14749 (typecheck/should_compile/T14749) Sadly, this patch negatively affects performance of type-family- heavy code. The following patch fixes these performance degradations. However, the performance fixes are somewhat invasive and so I've kept them as a separate patch, labeling this one as [skip ci] so that validation doesn't fail on the performance cases.
Diffstat (limited to 'testsuite/tests/dependent')
-rw-r--r--testsuite/tests/dependent/should_compile/T14556.hs38
-rw-r--r--testsuite/tests/dependent/should_compile/T14720.hs44
-rw-r--r--testsuite/tests/dependent/should_compile/all.T8
-rw-r--r--testsuite/tests/dependent/should_fail/RAE_T32a.stderr25
-rw-r--r--testsuite/tests/dependent/should_fail/all.T2
5 files changed, 100 insertions, 17 deletions
diff --git a/testsuite/tests/dependent/should_compile/T14556.hs b/testsuite/tests/dependent/should_compile/T14556.hs
new file mode 100644
index 0000000000..eebbdca888
--- /dev/null
+++ b/testsuite/tests/dependent/should_compile/T14556.hs
@@ -0,0 +1,38 @@
+{-# Language UndecidableInstances, DataKinds, TypeOperators, KindSignatures, PolyKinds, TypeInType, TypeFamilies, GADTs, LambdaCase, ScopedTypeVariables #-}
+
+module T14556 where
+
+import Data.Kind
+import Data.Proxy
+
+data Fn a b where
+ IdSym :: Fn Type Type
+
+type family
+ (@@) (f::Fn k k') (a::k)::k' where
+ IdSym @@ a = a
+
+data KIND = X | FNARR KIND KIND
+
+data TY :: KIND -> Type where
+ ID :: TY (FNARR X X)
+ FNAPP :: TY (FNARR k k') -> TY k -> TY k'
+
+data TyRep (kind::KIND) :: TY kind -> Type where
+ TID :: TyRep (FNARR X X) ID
+ TFnApp :: TyRep (FNARR k k') f
+ -> TyRep k a
+ -> TyRep k' (FNAPP f a)
+
+type family
+ IK (kind::KIND) :: Type where
+ IK X = Type
+ IK (FNARR k k') = Fn (IK k) (IK k')
+
+type family
+ IT (ty::TY kind) :: IK kind where
+ IT ID = IdSym
+ IT (FNAPP f x) = IT f @@ IT x
+
+zero :: TyRep X a -> IT a
+zero = undefined
diff --git a/testsuite/tests/dependent/should_compile/T14720.hs b/testsuite/tests/dependent/should_compile/T14720.hs
new file mode 100644
index 0000000000..c26a184689
--- /dev/null
+++ b/testsuite/tests/dependent/should_compile/T14720.hs
@@ -0,0 +1,44 @@
+{-# LANGUAGE AllowAmbiguousTypes #-}
+{-# LANGUAGE DefaultSignatures #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE TypeInType #-}
+{-# LANGUAGE TypeOperators #-}
+module T14720 where
+
+import Data.Kind (Type)
+import Data.Type.Equality ((:~:)(..), sym, trans)
+import Data.Void
+
+data family Sing (z :: k)
+
+class Generic (a :: Type) where
+ type Rep a :: Type
+ from :: a -> Rep a
+ to :: Rep a -> a
+
+class PGeneric (a :: Type) where
+ type PFrom (x :: a) :: Rep a
+ type PTo (x :: Rep a) :: a
+
+class SGeneric k where
+ sFrom :: forall (a :: k). Sing a -> Sing (PFrom a)
+ sTo :: forall (a :: Rep k). Sing a -> Sing (PTo a :: k)
+
+class (PGeneric k, SGeneric k) => VGeneric k where
+ sTof :: forall (a :: k). Sing a -> PTo (PFrom a) :~: a
+ sFot :: forall (a :: Rep k). Sing a -> PFrom (PTo a :: k) :~: a
+
+data Decision a = Proved a
+ | Disproved (a -> Void)
+
+class SDecide k where
+ (%~) :: forall (a :: k) (b :: k). Sing a -> Sing b -> Decision (a :~: b)
+ default (%~) :: forall (a :: k) (b :: k). (VGeneric k, SDecide (Rep k))
+ => Sing a -> Sing b -> Decision (a :~: b)
+ s1 %~ s2 = case sFrom s1 %~ sFrom s2 of
+ Proved (Refl :: PFrom a :~: PFrom b) ->
+ case (sTof s1, sTof s2) of
+ (Refl, Refl) -> Proved Refl
+ Disproved contra -> Disproved (\Refl -> contra Refl)
diff --git a/testsuite/tests/dependent/should_compile/all.T b/testsuite/tests/dependent/should_compile/all.T
index 684602cc94..ab7ab3c8df 100644
--- a/testsuite/tests/dependent/should_compile/all.T
+++ b/testsuite/tests/dependent/should_compile/all.T
@@ -25,7 +25,9 @@ test('T11966', normal, compile, [''])
test('T12442', normal, compile, [''])
test('T13538', normal, compile, [''])
test('T12176', normal, compile, [''])
-test('T14038', expect_broken(14038), compile, [''])
+test('T14038', normal, compile, [''])
test('T12742', normal, compile, [''])
-test('T13910', expect_broken(13910), compile, [''])
-test('T13938', expect_broken(13938), compile, [''])
+test('T13910', normal, compile, [''])
+test('T13938', normal, compile, [''])
+test('T14556', normal, compile, [''])
+test('T14720', normal, compile, [''])
diff --git a/testsuite/tests/dependent/should_fail/RAE_T32a.stderr b/testsuite/tests/dependent/should_fail/RAE_T32a.stderr
index cb94dd2854..046a1e1aa4 100644
--- a/testsuite/tests/dependent/should_fail/RAE_T32a.stderr
+++ b/testsuite/tests/dependent/should_fail/RAE_T32a.stderr
@@ -1,19 +1,18 @@
RAE_T32a.hs:28:1: error:
- Too many parameters to Sing:
- x is unexpected;
- expected only two parameters
- In the data instance declaration for ‘Sing’
+ • Expected kind ‘k0 -> *’,
+ but ‘Sing Sigma (Sigma p r)’ has kind ‘*’
+ • In the data instance declaration for ‘Sing’
RAE_T32a.hs:28:20: error:
- Expecting two more arguments to ‘Sigma’
- Expected a type, but
- ‘Sigma’ has kind
- ‘forall p -> TyPi p (MkStar p) -> *’
- In the first argument of ‘Sing’, namely ‘Sigma’
- In the data instance declaration for ‘Sing’
+ • Expecting two more arguments to ‘Sigma’
+ Expected a type, but
+ ‘Sigma’ has kind
+ ‘forall p -> TyPi p (MkStar p) -> *’
+ • In the first argument of ‘Sing’, namely ‘Sigma’
+ In the data instance declaration for ‘Sing’
RAE_T32a.hs:28:27: error:
- Expected kind ‘Sigma’, but ‘Sigma p r’ has kind ‘*’
- In the second argument of ‘Sing’, namely ‘(Sigma p r)’
- In the data instance declaration for ‘Sing’
+ • Expected kind ‘Sigma’, but ‘Sigma p r’ has kind ‘*’
+ • In the second argument of ‘Sing’, namely ‘(Sigma p r)’
+ In the data instance declaration for ‘Sing’
diff --git a/testsuite/tests/dependent/should_fail/all.T b/testsuite/tests/dependent/should_fail/all.T
index 4eb426419d..e28b2df5cd 100644
--- a/testsuite/tests/dependent/should_fail/all.T
+++ b/testsuite/tests/dependent/should_fail/all.T
@@ -1,5 +1,5 @@
test('DepFail1', normal, compile_fail, [''])
-test('RAE_T32a', expect_broken(12919), compile_fail, [''])
+test('RAE_T32a', normal, compile_fail, [''])
test('TypeSkolEscape', normal, compile_fail, [''])
test('BadTelescope', normal, compile_fail, [''])
test('BadTelescope2', normal, compile_fail, [''])