summaryrefslogtreecommitdiff
path: root/compiler/iface
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2019-04-30 11:28:41 -0400
committerÖmer Sinan Ağacan <omeragacan@gmail.com>2019-05-03 21:54:50 +0300
commitcc495d5777c01ef62129df15caacf87b0e430c6b (patch)
tree98367d77415752a0b21e0bcb9a5cacd233de32c5 /compiler/iface
parent87bc954ab65aaf08b4f59cf46bd2916acd69ea73 (diff)
downloadhaskell-cc495d5777c01ef62129df15caacf87b0e430c6b.tar.gz
Make equality constraints in kinds invisible
Issues #12102 and #15872 revealed something strange about the way GHC handles equality constraints in kinds: it treats them as _visible_ arguments! This causes a litany of strange effects, from strange error messages (https://gitlab.haskell.org/ghc/ghc/issues/12102#note_169035) to bizarre `Eq#`-related things leaking through to GHCi output, even without any special flags enabled. This patch is an attempt to contain some of this strangeness. In particular: * In `TcHsType.etaExpandAlgTyCon`, we propagate through the `AnonArgFlag`s of any `Anon` binders. Previously, we were always hard-coding them to `VisArg`, which meant that invisible binders (like those whose kinds were equality constraint) would mistakenly get flagged as visible. * In `ToIface.toIfaceAppArgsX`, we previously assumed that the argument to a `FunTy` always corresponding to a `Required` argument. We now dispatch on the `FunTy`'s `AnonArgFlag` and map `VisArg` to `Required` and `InvisArg` to `Inferred`. As a consequence, the iface pretty-printer correctly recognizes that equality coercions are inferred arguments, and as a result, only displays them in `-fprint-explicit-kinds` is enabled. * Speaking of iface pretty-printing, `Anon InvisArg` binders were previously being pretty-printed like `T (a :: b ~ c)`, as if they were required. This seemed inconsistent with other invisible arguments (that are printed like `T @{d}`), so I decided to switch this to `T @{a :: b ~ c}`. Along the way, I also cleaned up a minor inaccuracy in the users' guide section for constraints in kinds that was spotted in https://gitlab.haskell.org/ghc/ghc/issues/12102#note_136220. Fixes #12102 and #15872.
Diffstat (limited to 'compiler/iface')
-rw-r--r--compiler/iface/IfaceType.hs5
-rw-r--r--compiler/iface/ToIface.hs10
2 files changed, 11 insertions, 4 deletions
diff --git a/compiler/iface/IfaceType.hs b/compiler/iface/IfaceType.hs
index 4488aef025..298e14e463 100644
--- a/compiler/iface/IfaceType.hs
+++ b/compiler/iface/IfaceType.hs
@@ -719,8 +719,9 @@ pprIfaceTyConBinders = sep . map go
-- See Note [Pretty-printing invisible arguments]
case vis of
AnonTCB VisArg -> ppr_bndr True
- AnonTCB InvisArg -> ppr_bndr True -- Rare; just promoted GADT data constructors
- -- Should we print them differently?
+ AnonTCB InvisArg -> char '@' <> braces (ppr_bndr False)
+ -- The above case is rare. (See Note [AnonTCB InvisArg] in TyCon.)
+ -- Should we print these differently?
NamedTCB Required -> ppr_bndr True
NamedTCB Specified -> char '@' <> ppr_bndr True
NamedTCB Inferred -> char '@' <> braces (ppr_bndr False)
diff --git a/compiler/iface/ToIface.hs b/compiler/iface/ToIface.hs
index aa4e53cfb4..535c1080f2 100644
--- a/compiler/iface/ToIface.hs
+++ b/compiler/iface/ToIface.hs
@@ -309,8 +309,14 @@ toIfaceAppArgsX fr kind ty_args
t' = toIfaceTypeX fr t
ts' = go (extendTCvSubst env tv t) res ts
- go env (FunTy { ft_res = res }) (t:ts) -- No type-class args in tycon apps
- = IA_Arg (toIfaceTypeX fr t) Required (go env res ts)
+ go env (FunTy { ft_af = af, ft_res = res }) (t:ts)
+ = IA_Arg (toIfaceTypeX fr t) argf (go env res ts)
+ where
+ argf = case af of
+ VisArg -> Required
+ InvisArg -> Inferred
+ -- It's rare for a kind to have a constraint argument, but
+ -- it can happen. See Note [AnonTCB InvisArg] in TyCon.
go env ty ts@(t1:ts1)
| not (isEmptyTCvSubst env)