summaryrefslogtreecommitdiff
path: root/compiler/coreSyn/CoreUtils.hs
diff options
context:
space:
mode:
authorningning <xnningxie@gmail.com>2018-09-15 10:16:47 -0400
committerRichard Eisenberg <rae@cs.brynmawr.edu>2018-09-15 10:28:41 -0400
commitea5ade34788f29f5902c5475e94fbac13110eea5 (patch)
tree3a17314dc67df885c3cdf681a6aec449ae808d8f /compiler/coreSyn/CoreUtils.hs
parentc23f057f1753634e2bc0612969470efea6443031 (diff)
downloadhaskell-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/coreSyn/CoreUtils.hs')
-rw-r--r--compiler/coreSyn/CoreUtils.hs21
1 files changed, 12 insertions, 9 deletions
diff --git a/compiler/coreSyn/CoreUtils.hs b/compiler/coreSyn/CoreUtils.hs
index 7635a6d66a..a1dae9875e 100644
--- a/compiler/coreSyn/CoreUtils.hs
+++ b/compiler/coreSyn/CoreUtils.hs
@@ -77,7 +77,7 @@ import Id
import IdInfo
import PrelNames( absentErrorIdKey )
import Type
-import TyCoRep( TyBinder(..) )
+import TyCoRep( TyCoBinder(..), TyBinder )
import Coercion
import TyCon
import Unique
@@ -1879,8 +1879,8 @@ exprIsTickedString_maybe _ = Nothing
These InstPat functions go here to avoid circularity between DataCon and Id
-}
-dataConRepInstPat :: [Unique] -> DataCon -> [Type] -> ([TyVar], [Id])
-dataConRepFSInstPat :: [FastString] -> [Unique] -> DataCon -> [Type] -> ([TyVar], [Id])
+dataConRepInstPat :: [Unique] -> DataCon -> [Type] -> ([TyCoVar], [Id])
+dataConRepFSInstPat :: [FastString] -> [Unique] -> DataCon -> [Type] -> ([TyCoVar], [Id])
dataConRepInstPat = dataConInstPat (repeat ((fsLit "ipv")))
dataConRepFSInstPat = dataConInstPat
@@ -1889,7 +1889,7 @@ dataConInstPat :: [FastString] -- A long enough list of FSs to use for
-> [Unique] -- An equally long list of uniques, at least one for each binder
-> DataCon
-> [Type] -- Types to instantiate the universally quantified tyvars
- -> ([TyVar], [Id]) -- Return instantiated variables
+ -> ([TyCoVar], [Id]) -- Return instantiated variables
-- dataConInstPat arg_fun fss us con inst_tys returns a tuple
-- (ex_tvs, arg_ids),
--
@@ -1922,7 +1922,7 @@ dataConInstPat fss uniqs con inst_tys
(ex_bndrs, arg_ids)
where
univ_tvs = dataConUnivTyVars con
- ex_tvs = dataConExTyVars con
+ ex_tvs = dataConExTyCoVars con
arg_tys = dataConRepArgTys con
arg_strs = dataConRepStrictness con -- 1-1 with arg_tys
n_ex = length ex_tvs
@@ -1938,13 +1938,16 @@ dataConInstPat fss uniqs con inst_tys
(full_subst, ex_bndrs) = mapAccumL mk_ex_var univ_subst
(zip3 ex_tvs ex_fss ex_uniqs)
- mk_ex_var :: TCvSubst -> (TyVar, FastString, Unique) -> (TCvSubst, TyVar)
- mk_ex_var subst (tv, fs, uniq) = (Type.extendTvSubstWithClone subst tv
+ mk_ex_var :: TCvSubst -> (TyCoVar, FastString, Unique) -> (TCvSubst, TyCoVar)
+ mk_ex_var subst (tv, fs, uniq) = (Type.extendTCvSubstWithClone subst tv
new_tv
, new_tv)
where
- new_tv = mkTyVar (mkSysTvName uniq fs) kind
- kind = Type.substTyUnchecked subst (tyVarKind tv)
+ new_tv | isTyVar tv
+ = mkTyVar (mkSysTvName uniq fs) kind
+ | otherwise
+ = mkCoVar (mkSystemVarName uniq fs) kind
+ kind = Type.substTyUnchecked subst (varType tv)
-- Make value vars, instantiating types
arg_ids = zipWith4 mk_id_var id_uniqs id_fss arg_tys arg_strs