diff options
author | ningning <xnningxie@gmail.com> | 2018-09-15 10:16:47 -0400 |
---|---|---|
committer | Richard Eisenberg <rae@cs.brynmawr.edu> | 2018-09-15 10:28:41 -0400 |
commit | ea5ade34788f29f5902c5475e94fbac13110eea5 (patch) | |
tree | 3a17314dc67df885c3cdf681a6aec449ae808d8f /compiler/iface/TcIface.hs | |
parent | c23f057f1753634e2bc0612969470efea6443031 (diff) | |
download | haskell-ea5ade34788f29f5902c5475e94fbac13110eea5.tar.gz |
Coercion Quantification
This patch corresponds to #15497.
According to https://ghc.haskell.org/trac/ghc/wiki/DependentHaskell/Phase2,
we would like to have coercion quantifications back. This will
allow us to migrate (~#) to be homogeneous, instead of its current
heterogeneous definition. This patch is (lots of) plumbing only. There
should be no user-visible effects.
An overview of changes:
- Both `ForAllTy` and `ForAllCo` can quantify over coercion variables,
but only in *Core*. All relevant functions are updated accordingly.
- Small changes that should be irrelevant to the main task:
1. removed dead code `mkTransAppCo` in Coercion
2. removed out-dated Note Computing a coercion kind and
roles in Coercion
3. Added `Eq4` in Note Respecting definitional equality in
TyCoRep, and updated `mkCastTy` accordingly.
4. Various updates and corrections of notes and typos.
- Haddock submodule needs to be changed too.
Acknowledgments:
This work was completed mostly during Ningning Xie's Google Summer
of Code, sponsored by Google. It was advised by Richard Eisenberg,
supported by NSF grant 1704041.
Test Plan: ./validate
Reviewers: goldfire, simonpj, bgamari, hvr, erikd, simonmar
Subscribers: RyanGlScott, monoidal, rwbarton, carter
GHC Trac Issues: #15497
Differential Revision: https://phabricator.haskell.org/D5054
Diffstat (limited to 'compiler/iface/TcIface.hs')
-rw-r--r-- | compiler/iface/TcIface.hs | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/compiler/iface/TcIface.hs b/compiler/iface/TcIface.hs index 0dc3fb5381..248f7d3c38 100644 --- a/compiler/iface/TcIface.hs +++ b/compiler/iface/TcIface.hs @@ -861,7 +861,7 @@ tc_ax_branch prev_branches , ifaxbLHS = lhs, ifaxbRHS = rhs , ifaxbRoles = roles, ifaxbIncomps = incomps }) = bindIfaceTyConBinders_AT - (map (\b -> TvBndr b (NamedTCB Inferred)) tv_bndrs) $ \ tvs -> + (map (\b -> Bndr (IfaceTvBndr b) (NamedTCB Inferred)) tv_bndrs) $ \ tvs -> -- The _AT variant is needed here; see Note [CoAxBranch type variables] in CoAxiom bindIfaceIds cv_bndrs $ \ cvs -> do { tc_lhs <- tcIfaceAppArgs lhs @@ -891,7 +891,7 @@ tcIfaceDataCons tycon_name tycon tc_tybinders if_cons tag_map = mkTyConTagMap tycon tc_con_decl (IfCon { ifConInfix = is_infix, - ifConExTvs = ex_bndrs, + ifConExTCvs = ex_bndrs, ifConUserTvBinders = user_bndrs, ifConName = dc_name, ifConCtxt = ctxt, ifConEqSpec = spec, @@ -900,7 +900,7 @@ tcIfaceDataCons tycon_name tycon tc_tybinders if_cons ifConSrcStricts = if_src_stricts}) = -- Universally-quantified tyvars are shared with -- parent TyCon, and are already in scope - bindIfaceTyVars ex_bndrs $ \ ex_tvs -> do + bindIfaceBndrs ex_bndrs $ \ ex_tvs -> do { traceIf (text "Start interface-file tc_con_decl" <+> ppr dc_name) -- By this point, we have bound every universal and existential @@ -909,8 +909,12 @@ tcIfaceDataCons tycon_name tycon tc_tybinders if_cons -- ifConUserTvBinders has a matching counterpart somewhere in the -- bound universals/existentials. As a result, calling tcIfaceTyVar -- below is always guaranteed to succeed. - ; user_tv_bndrs <- mapM (\(TvBndr (name, _) vis) -> - TvBndr <$> tcIfaceTyVar name <*> pure vis) + ; user_tv_bndrs <- mapM (\(Bndr bd vis) -> + case bd of + IfaceIdBndr (name, _) -> + Bndr <$> tcIfaceLclId name <*> pure vis + IfaceTvBndr (name, _) -> + Bndr <$> tcIfaceTyVar name <*> pure vis) user_bndrs -- Read the context and argument types, but lazily for two reasons @@ -936,7 +940,7 @@ tcIfaceDataCons tycon_name tycon tc_tybinders if_cons -- Remember, tycon is the representation tycon ; let orig_res_ty = mkFamilyTyConApp tycon - (substTyVars (mkTvSubstPrs (map eqSpecPair eq_spec)) + (substTyCoVars (mkTvSubstPrs (map eqSpecPair eq_spec)) (binderVars tc_tybinders)) ; prom_rep_name <- newTyConRepName dc_name @@ -1145,7 +1149,7 @@ tcIfaceType = go ; return (mkTyConApp tc' tks') } go (IfaceForAllTy bndr t) = bindIfaceForAllBndr bndr $ \ tv' vis -> - ForAllTy (TvBndr tv' vis) <$> go t + ForAllTy (Bndr tv' vis) <$> go t go (IfaceCastTy ty co) = CastTy <$> go ty <*> tcIfaceCo co go (IfaceCoercionTy co) = CoercionTy <$> tcIfaceCo co @@ -1211,7 +1215,7 @@ tcIfaceCo = go = TyConAppCo r <$> tcIfaceTyCon tc <*> mapM go cs go (IfaceAppCo c1 c2) = AppCo <$> go c1 <*> go c2 go (IfaceForAllCo tv k c) = do { k' <- go k - ; bindIfaceTyVar tv $ \ tv' -> + ; bindIfaceBndr tv $ \ tv' -> ForAllCo tv' k' <$> go c } go (IfaceCoVarCo n) = CoVarCo <$> go_var n go (IfaceAxiomInstCo n i cs) = AxiomInstCo <$> tcIfaceCoAxiom n <*> pure i <*> mapM go cs @@ -1745,23 +1749,18 @@ bindIfaceBndrs (b:bs) thing_inside thing_inside (b':bs') ----------------------- -bindIfaceForAllBndrs :: [IfaceForAllBndr] -> ([TyVarBinder] -> IfL a) -> IfL a +bindIfaceForAllBndrs :: [IfaceForAllBndr] -> ([TyCoVarBinder] -> IfL a) -> IfL a bindIfaceForAllBndrs [] thing_inside = thing_inside [] bindIfaceForAllBndrs (bndr:bndrs) thing_inside = bindIfaceForAllBndr bndr $ \tv vis -> bindIfaceForAllBndrs bndrs $ \bndrs' -> - thing_inside (mkTyVarBinder vis tv : bndrs') + thing_inside (mkTyCoVarBinder vis tv : bndrs') -bindIfaceForAllBndr :: IfaceForAllBndr -> (TyVar -> ArgFlag -> IfL a) -> IfL a -bindIfaceForAllBndr (TvBndr tv vis) thing_inside +bindIfaceForAllBndr :: IfaceForAllBndr -> (TyCoVar -> ArgFlag -> IfL a) -> IfL a +bindIfaceForAllBndr (Bndr (IfaceTvBndr tv) vis) thing_inside = bindIfaceTyVar tv $ \tv' -> thing_inside tv' vis - -bindIfaceTyVars :: [IfaceTvBndr] -> ([TyVar] -> IfL a) -> IfL a -bindIfaceTyVars [] thing_inside = thing_inside [] -bindIfaceTyVars (tv:tvs) thing_inside - = bindIfaceTyVar tv $ \tv' -> - bindIfaceTyVars tvs $ \tvs' -> - thing_inside (tv' : tvs') +bindIfaceForAllBndr (Bndr (IfaceIdBndr tv) vis) thing_inside + = bindIfaceId tv $ \tv' -> thing_inside tv' vis bindIfaceTyVar :: IfaceTvBndr -> (TyVar -> IfL a) -> IfL a bindIfaceTyVar (occ,kind) thing_inside @@ -1778,8 +1777,8 @@ bindIfaceTyConBinders :: [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a bindIfaceTyConBinders [] thing_inside = thing_inside [] bindIfaceTyConBinders (b:bs) thing_inside - = bindIfaceTyConBinderX bindIfaceTyVar b $ \ b' -> - bindIfaceTyConBinders bs $ \ bs' -> + = bindIfaceTyConBinderX bindIfaceBndr b $ \ b' -> + bindIfaceTyConBinders bs $ \ bs' -> thing_inside (b':bs') bindIfaceTyConBinders_AT :: [IfaceTyConBinder] @@ -1796,14 +1795,14 @@ bindIfaceTyConBinders_AT (b : bs) thing_inside thing_inside (b':bs') where bind_tv tv thing - = do { mb_tv <- lookupIfaceTyVar tv + = do { mb_tv <- lookupIfaceVar tv ; case mb_tv of Just b' -> thing b' - Nothing -> bindIfaceTyVar tv thing } + Nothing -> bindIfaceBndr tv thing } -bindIfaceTyConBinderX :: (IfaceTvBndr -> (TyVar -> IfL a) -> IfL a) +bindIfaceTyConBinderX :: (IfaceBndr -> (TyCoVar -> IfL a) -> IfL a) -> IfaceTyConBinder -> (TyConBinder -> IfL a) -> IfL a -bindIfaceTyConBinderX bind_tv (TvBndr tv vis) thing_inside +bindIfaceTyConBinderX bind_tv (Bndr tv vis) thing_inside = bind_tv tv $ \tv' -> - thing_inside (TvBndr tv' vis) + thing_inside (Bndr tv' vis) |