Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit 2a5fc0a

Browse files
RyanGlScottharpocrates
authored andcommitted
Reify oversaturated data family instances correctly (#1103)
This fixes #1103 by adapting the corresponding patch for GHC (see https://gitlab.haskell.org/ghc/ghc/issues/17296 and https://gitlab.haskell.org/ghc/ghc/merge_requests/1877).
1 parent cdf4445 commit 2a5fc0a

File tree

3 files changed

+603
-15
lines changed

3 files changed

+603
-15
lines changed

haddock-api/src/Haddock/Convert.hs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ synifyAxBranch tc (CoAxBranch { cab_tvs = tkvs, cab_lhs = args, cab_rhs = rhs })
150150
= let name = synifyName tc
151151
args_types_only = filterOutInvisibleTypes tc args
152152
typats = map (synifyType WithinType []) args_types_only
153-
annot_typats = zipWith3 annotHsType (mkIsPolyTvs fam_tvs)
154-
args_types_only typats
153+
annot_typats = zipWith3 annotHsType args_poly args_types_only typats
155154
hs_rhs = synifyType WithinType [] rhs
156155
in HsIB { hsib_ext = map tyVarName tkvs
157156
, hsib_body = FamEqn { feqn_ext = noExt
@@ -162,7 +161,7 @@ synifyAxBranch tc (CoAxBranch { cab_tvs = tkvs, cab_lhs = args, cab_rhs = rhs })
162161
, feqn_fixity = synifyFixity name
163162
, feqn_rhs = hs_rhs } }
164163
where
165-
fam_tvs = tyConVisibleTyVars tc
164+
args_poly = tyConArgsPolyKinded tc
166165

167166
synifyAxiom :: CoAxiom br -> Either ErrMsg (HsDecl GhcRn)
168167
synifyAxiom ax@(CoAxiom { co_ax_tc = tc })
@@ -472,17 +471,26 @@ annotHsType True ty hs_ty
472471
in noLoc (HsKindSig noExt hs_ty hs_ki)
473472
annotHsType _ _ hs_ty = hs_ty
474473

475-
-- | For every type variable in the input,
476-
-- report whether or not the tv is poly-kinded. This is used to eventually
477-
-- feed into 'annotHsType'.
478-
mkIsPolyTvs :: [TyVar] -> [Bool]
479-
mkIsPolyTvs = map is_poly_tv
474+
-- | For every argument type that a type constructor accepts,
475+
-- report whether or not the argument is poly-kinded. This is used to
476+
-- eventually feed into 'annotThType'.
477+
tyConArgsPolyKinded :: TyCon -> [Bool]
478+
tyConArgsPolyKinded tc =
479+
map (is_poly_ty . tyVarKind) tc_vis_tvs
480+
++ map (is_poly_ty . tyCoBinderType) tc_res_kind_vis_bndrs
481+
++ repeat True
480482
where
481-
is_poly_tv tv = not $
483+
is_poly_ty :: Type -> Bool
484+
is_poly_ty ty = not $
482485
isEmptyVarSet $
483486
filterVarSet isTyVar $
484-
tyCoVarsOfType $
485-
tyVarKind tv
487+
tyCoVarsOfType ty
488+
489+
tc_vis_tvs :: [TyVar]
490+
tc_vis_tvs = tyConVisibleTyVars tc
491+
492+
tc_res_kind_vis_bndrs :: [TyCoBinder]
493+
tc_res_kind_vis_bndrs = filter isVisibleBinder $ fst $ splitPiTys $ tyConResKind tc
486494

487495
--states of what to do with foralls:
488496
data SynifyTypeState
@@ -787,8 +795,8 @@ synifyInstHead (vs, preds, cls, types) = specializeInstHead $ InstHead
787795
cls_tycon = classTyCon cls
788796
ts = filterOutInvisibleTypes cls_tycon types
789797
ts' = map (synifyType WithinType vs) ts
790-
annot_ts = zipWith3 annotHsType is_poly_tvs ts ts'
791-
is_poly_tvs = mkIsPolyTvs (tyConVisibleTyVars cls_tycon)
798+
annot_ts = zipWith3 annotHsType args_poly ts ts'
799+
args_poly = tyConArgsPolyKinded cls_tycon
792800
synifyClsIdSig = synifyIdSig ShowRuntimeRep DeleteTopLevelQuantification vs
793801

794802
-- Convert a family instance, this could be a type family or data family
@@ -827,8 +835,8 @@ synifyFamInst fi opaque = do
827835
ts = filterOutInvisibleTypes fam_tc eta_expanded_lhs
828836
synifyTypes = map (synifyType WithinType [])
829837
ts' = synifyTypes ts
830-
annot_ts = zipWith3 annotHsType is_poly_tvs ts ts'
831-
is_poly_tvs = mkIsPolyTvs (tyConVisibleTyVars fam_tc)
838+
annot_ts = zipWith3 annotHsType args_poly ts ts'
839+
args_poly = tyConArgsPolyKinded fam_tc
832840

833841
{-
834842
Note [Invariant: Never expand type synonyms]

0 commit comments

Comments
 (0)