Adam Gundry pushed to branch wip/amg/castz at Glasgow Haskell Compiler / GHC
Commits:
-
d2fbba48
by Adam Gundry at 2026-06-05T22:32:14+02:00
-
f4032051
by Adam Gundry at 2026-06-05T22:32:23+02:00
29 changed files:
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Coercion.hs-boot
- compiler/GHC/Core/Coercion/Opt.hs
- compiler/GHC/Core/FamInstEnv.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Reduction.hs
- compiler/GHC/Core/TyCo/FVs.hs
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/TyCo/Subst.hs
- compiler/GHC/Core/TyCo/Tidy.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/Core/Type.hs-boot
- compiler/GHC/Core/Unify.hs
- compiler/GHC/CoreToIface.hs
- compiler/GHC/HsToCore.hs
- compiler/GHC/Iface/Rename.hs
- compiler/GHC/Iface/Syntax.hs
- compiler/GHC/Iface/Type.hs
- compiler/GHC/IfaceToCore.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Bind.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver/Equality.hs
- compiler/GHC/Tc/Solver/Rewrite.hs
- compiler/GHC/Tc/TyCl/Utils.hs
- compiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Tc/Utils/Unify.hs
Changes:
| ... | ... | @@ -64,8 +64,6 @@ module GHC.Core.Coercion ( |
| 64 | 64 | mkForAllCastCo,
|
| 65 | 65 | mkFunResCastCo,
|
| 66 | 66 | mkFunCastCoNoFTF,
|
| 67 | - mkGReflLeftCastCo,
|
|
| 68 | - mkGReflRightCastCo,
|
|
| 69 | 67 | applyForAllTy,
|
| 70 | 68 | decomposeFunCastCo,
|
| 71 | 69 | |
| ... | ... | @@ -399,7 +397,7 @@ mkSymMCo (MCo co) = MCo (mkSymCo co) |
| 399 | 397 | -- | Cast a type by an 'MCoercion'
|
| 400 | 398 | mkCastTyMCo :: Type -> MCoercion -> Type
|
| 401 | 399 | mkCastTyMCo ty MRefl = ty
|
| 402 | -mkCastTyMCo ty (MCo co) = ty `mkCastTy` CCoercion co
|
|
| 400 | +mkCastTyMCo ty (MCo co) = ty `mkCastTy` co
|
|
| 403 | 401 | |
| 404 | 402 | mkFunResMCo :: Id -> CastCoercion -> CastCoercion
|
| 405 | 403 | mkFunResMCo _ ReflCastCo = ReflCastCo
|
| ... | ... | @@ -414,17 +412,6 @@ mkGReflRightMCo :: Role -> Type -> MCoercionN -> Coercion |
| 414 | 412 | mkGReflRightMCo r ty MRefl = mkReflCo r ty
|
| 415 | 413 | mkGReflRightMCo r ty (MCo co) = mkGReflRightCo r ty co
|
| 416 | 414 | |
| 417 | -mkGReflLeftCastCo :: Role -> Type -> CastCoercion -> Coercion
|
|
| 418 | -mkGReflLeftCastCo r ty ReflCastCo = mkReflCo r ty
|
|
| 419 | -mkGReflLeftCastCo r ty (CCoercion co) = mkGReflLeftCo r ty co
|
|
| 420 | -mkGReflLeftCastCo _r _ty (ZCoercion _ki _cos) = error "AMG TODO mkGReflLeftCastCo"
|
|
| 421 | - |
|
| 422 | -mkGReflRightCastCo :: Role -> Type -> CastCoercion -> Coercion
|
|
| 423 | -mkGReflRightCastCo r ty ReflCastCo = mkReflCo r ty
|
|
| 424 | -mkGReflRightCastCo r ty (CCoercion co) = mkGReflRightCo r ty co
|
|
| 425 | -mkGReflRightCastCo _r _ty (ZCoercion _ki _cos) = error "AMG TODO mkGReflRightCastCo"
|
|
| 426 | - |
|
| 427 | - |
|
| 428 | 415 | -- | Like 'mkCoherenceRightCo', but with an 'MCoercion'
|
| 429 | 416 | mkCoherenceRightMCo :: Role -> Type -> MCoercionN -> Coercion -> Coercion
|
| 430 | 417 | mkCoherenceRightMCo _ _ MRefl co2 = co2
|
| ... | ... | @@ -539,7 +526,7 @@ decomposePiCos orig_co (Pair orig_k1 orig_k2) orig_args |
| 539 | 526 | -- res_co :: t1[ty |> arg_co / a] ~ t2[ty / b]
|
| 540 | 527 | = let arg_co = mkSelCo SelForAll (mkSymCo co)
|
| 541 | 528 | res_co = mkInstCo co (mkGReflLeftCo Nominal ty arg_co)
|
| 542 | - subst1' = extendTCvSubst subst1 a (ty `CastTy` CCoercion arg_co)
|
|
| 529 | + subst1' = extendTCvSubst subst1 a (ty `CastTy` arg_co)
|
|
| 543 | 530 | subst2' = extendTCvSubst subst2 b ty
|
| 544 | 531 | in
|
| 545 | 532 | go (arg_co : acc_arg_cos) (subst1', t1) res_co (subst2', t2) tys
|
| ... | ... | @@ -1810,10 +1797,10 @@ castCoercionKind1 :: Coercion -> Role -> Type -> Type |
| 1810 | 1797 | castCoercionKind1 g r t1 t2 h
|
| 1811 | 1798 | = case g of
|
| 1812 | 1799 | Refl {} -> assert (r == Nominal) $ -- Refl is always Nominal
|
| 1813 | - mkNomReflCo (mkCastTy t2 (CCoercion h))
|
|
| 1800 | + mkNomReflCo (mkCastTy t2 h)
|
|
| 1814 | 1801 | GRefl _ _ mco -> case mco of
|
| 1815 | - MRefl -> mkReflCo r (mkCastTy t2 (CCoercion h))
|
|
| 1816 | - MCo kind_co -> mkGReflMCo r (mkCastTy t1 (CCoercion h))
|
|
| 1802 | + MRefl -> mkReflCo r (mkCastTy t2 h)
|
|
| 1803 | + MCo kind_co -> mkGReflMCo r (mkCastTy t1 h)
|
|
| 1817 | 1804 | (mkSymCo h `mkTransCo` kind_co `mkTransCo` h)
|
| 1818 | 1805 | _ -> castCoercionKind2 g r t1 t2 h h
|
| 1819 | 1806 | |
| ... | ... | @@ -2306,10 +2293,8 @@ ty_co_subst !lc role ty |
| 2306 | 2293 | else pprPanic "ty_co_subst: covar is not almost devoid" (ppr t)
|
| 2307 | 2294 | go r ty@(LitTy {}) = assert (r == Nominal) $
|
| 2308 | 2295 | mkNomReflCo ty
|
| 2309 | - go r (CastTy ty cco) = castCoercionKind (go r ty) (substLeftCo lc co)
|
|
| 2296 | + go r (CastTy ty co) = castCoercionKind (go r ty) (substLeftCo lc co)
|
|
| 2310 | 2297 | (substRightCo lc co)
|
| 2311 | - where
|
|
| 2312 | - co = castCoToCo (typeKind ty) cco
|
|
| 2313 | 2298 | go r (CoercionTy co) = mkProofIrrelCo r kco (substLeftCo lc co)
|
| 2314 | 2299 | (substRightCo lc co)
|
| 2315 | 2300 | where kco = go Nominal (coercionType co)
|
| ... | ... | @@ -2632,7 +2617,7 @@ coercion_lr_kind which orig_co |
| 2632 | 2617 | where
|
| 2633 | 2618 | go (Refl ty) = ty
|
| 2634 | 2619 | go (GRefl _ ty MRefl) = ty
|
| 2635 | - go (GRefl _ ty (MCo co1)) = pickLR which (ty, mkCastTy ty (CCoercion co1))
|
|
| 2620 | + go (GRefl _ ty (MCo co1)) = pickLR which (ty, mkCastTy ty co1)
|
|
| 2636 | 2621 | go (TyConAppCo _ tc cos) = mkTyConApp tc (map go cos)
|
| 2637 | 2622 | go (AppCo co1 co2) = mkAppTy (go co1) (go co2)
|
| 2638 | 2623 | go (CoVarCo cv) = go_covar cv
|
| ... | ... | @@ -2725,7 +2710,7 @@ coercion_lr_kind which orig_co |
| 2725 | 2710 | k2 = coercionRKind k_co
|
| 2726 | 2711 | tv2 = setTyVarKind tv1 (substTy subst k2)
|
| 2727 | 2712 | subst' = extendTvSubst (extendSubstInScope subst tv2) tv1 $
|
| 2728 | - TyVarTy tv2 `mkCastTy` CCoercion (mkSymCo k_co)
|
|
| 2713 | + TyVarTy tv2 `mkCastTy` mkSymCo k_co
|
|
| 2729 | 2714 | |
| 2730 | 2715 | go_forall_right subst (ForAllCo { fco_tcv = cv1, fco_visR = visR
|
| 2731 | 2716 | , fco_kind = k_mco, fco_body = co })
|
| ... | ... | @@ -2830,15 +2815,13 @@ buildCoercion orig_ty1 orig_ty2 = go orig_ty1 orig_ty2 |
| 2830 | 2815 | go ty1 ty2 | Just ty1' <- coreView ty1 = go ty1' ty2
|
| 2831 | 2816 | | Just ty2' <- coreView ty2 = go ty1 ty2'
|
| 2832 | 2817 | |
| 2833 | - go (CastTy ty1 cco) ty2
|
|
| 2834 | - = let co = castCoToCo (typeKind ty1) cco
|
|
| 2835 | - co' = go ty1 ty2
|
|
| 2818 | + go (CastTy ty1 co) ty2
|
|
| 2819 | + = let co' = go ty1 ty2
|
|
| 2836 | 2820 | r = coercionRole co'
|
| 2837 | 2821 | in mkCoherenceLeftCo r ty1 co co'
|
| 2838 | 2822 | |
| 2839 | - go ty1 (CastTy ty2 cco)
|
|
| 2840 | - = let co = castCoToCo (typeKind ty2) cco
|
|
| 2841 | - co' = go ty1 ty2
|
|
| 2823 | + go ty1 (CastTy ty2 co)
|
|
| 2824 | + = let co' = go ty1 ty2
|
|
| 2842 | 2825 | r = coercionRole co'
|
| 2843 | 2826 | in mkCoherenceRightCo r ty2 co co'
|
| 2844 | 2827 | |
| ... | ... | @@ -2875,7 +2858,7 @@ buildCoercion orig_ty1 orig_ty2 = go orig_ty1 orig_ty2 |
| 2875 | 2858 | where kind_co = go (tyVarKind tv1) (tyVarKind tv2)
|
| 2876 | 2859 | in_scope = mkInScopeSet $ tyCoVarsOfType ty2 `unionVarSet` tyCoVarsOfCo kind_co
|
| 2877 | 2860 | ty2' = substTyWithInScope in_scope [tv2]
|
| 2878 | - [mkTyVarTy tv1 `mkCastTy` CCoercion kind_co]
|
|
| 2861 | + [mkTyVarTy tv1 `mkCastTy` kind_co]
|
|
| 2879 | 2862 | ty2
|
| 2880 | 2863 | |
| 2881 | 2864 | go (ForAllTy (Bndr cv1 flag1) ty1) (ForAllTy (Bndr cv2 flag2) ty2)
|
| ... | ... | @@ -2989,7 +2972,7 @@ eqCastCoercionX env ty1 co1 ty2 co2 = eqTypeX env ty1 ty2 |
| 2989 | 2972 | |
| 2990 | 2973 | -- | Convert a 'CastCoercion' back into a 'Coercion', using a 'UnivCo' if we
|
| 2991 | 2974 | -- have discarded the original 'Coercion'.
|
| 2992 | -castCoToCo :: Type -> CastCoercion -> Coercion
|
|
| 2975 | +castCoToCo :: Type -> CastCoercion -> CoercionR
|
|
| 2993 | 2976 | castCoToCo _ (CCoercion co) = co
|
| 2994 | 2977 | castCoToCo lhs_ty (ZCoercion rhs_ty cos) = mkUnivCo ZCoercionProv (map CoVarCo (nonDetEltsUniqSet cos)) Representational lhs_ty rhs_ty
|
| 2995 | 2978 | castCoToCo lhs_ty ReflCastCo = mkRepReflCo lhs_ty
|
| ... | ... | @@ -55,9 +55,3 @@ coercionType :: Coercion -> Type |
| 55 | 55 | topNormaliseNewType_maybe :: Type -> Maybe (Coercion, Type)
|
| 56 | 56 | -- used to look through newtypes to the right of
|
| 57 | 57 | -- function arrows, in 'GHC.Core.Type.getRuntimeArgTys' |
| 58 | - |
|
| 59 | -castCoToCo :: Type -> CastCoercion -> Coercion
|
|
| 60 | -isReflexiveCastCo :: Type -> CastCoercion -> Bool
|
|
| 61 | -mkTransCastCo :: HasDebugCallStack => CastCoercion -> CastCoercion -> CastCoercion
|
|
| 62 | -seqCastCoercion :: CastCoercion -> ()
|
|
| 63 | -castCoercionRKind :: HasDebugCallStack => Type -> CastCoercion -> Type |
| ... | ... | @@ -884,7 +884,7 @@ opt_trans_rule is co1 co2 |
| 884 | 884 | (opt_trans is' r1 r2')
|
| 885 | 885 | where
|
| 886 | 886 | is' = is `extendInScopeSet` tv1
|
| 887 | - r2' = substCoWithInScope is' [tv2] [mkCastTyCo (TyVarTy tv1) kco1] r2
|
|
| 887 | + r2' = substCoWithInScope is' [tv2] [mkCastTy (TyVarTy tv1) kco1] r2
|
|
| 888 | 888 | |
| 889 | 889 | -- Push transitivity inside forall
|
| 890 | 890 | -- forall over coercions.
|
| ... | ... | @@ -1481,7 +1481,7 @@ optForAllCoBndr env sym tcv k_mco |
| 1481 | 1481 | -- override the substitution for the original variable to the
|
| 1482 | 1482 | -- re-kinded one, suitably casted
|
| 1483 | 1483 | tv2 = tv1 `setTyVarKind` coercionLKind k_co'
|
| 1484 | - subst2 = (extendTvSubst subst1 tcv (mkTyVarTy tv2 `CastTy` CCoercion k_co'))
|
|
| 1484 | + subst2 = (extendTvSubst subst1 tcv (mkTyVarTy tv2 `CastTy` k_co'))
|
|
| 1485 | 1485 | `extendSubstInScope` tv2
|
| 1486 | 1486 | |
| 1487 | 1487 | _ -> (subst1, tv1)
|
| ... | ... | @@ -1485,10 +1485,9 @@ normalise_type ty |
| 1485 | 1485 | ; redn <- withLC lc' $ normalise_type ty
|
| 1486 | 1486 | ; return $ mkForAllRedn vis tv' k_redn redn }
|
| 1487 | 1487 | go (TyVarTy tv) = normalise_tyvar tv
|
| 1488 | - go (CastTy ty cco)
|
|
| 1488 | + go (CastTy ty co)
|
|
| 1489 | 1489 | = do { redn <- go ty
|
| 1490 | 1490 | ; lc <- getLC
|
| 1491 | - ; let co = castCoToCo (typeKind ty) cco
|
|
| 1492 | 1491 | ; let co' = substRightCo lc co
|
| 1493 | 1492 | ; return $ mkCastRedn2 Nominal ty co redn co'
|
| 1494 | 1493 | -- ^^^^^^^^^^^ uses castCoercionKind2
|
| ... | ... | @@ -1990,10 +1990,9 @@ lintType ty@(ForAllTy {}) |
| 1990 | 1990 | = do { lintType body_ty
|
| 1991 | 1991 | ; lintForAllBody tcvs body_ty }
|
| 1992 | 1992 | |
| 1993 | -lintType (CastTy ty cco)
|
|
| 1993 | +lintType (CastTy ty co)
|
|
| 1994 | 1994 | = do { lintType ty
|
| 1995 | 1995 | ; ty_kind <- substTyM (typeKind ty)
|
| 1996 | - ; let co = castCoToCo (typeKind ty) cco -- TODO: maybe show the actual cco in mkCastTyErr/mkCastErr?
|
|
| 1997 | 1996 | ; co_lk <- lintStarCoercion co
|
| 1998 | 1997 | ; ensureEqTys ty_kind co_lk (mkCastTyErr ty co ty_kind co_lk) }
|
| 1999 | 1998 |
| ... | ... | @@ -2925,7 +2925,7 @@ pushCoTyArg co ty |
| 2925 | 2925 | |
| 2926 | 2926 | | isForAllTy_ty tyL
|
| 2927 | 2927 | = assertPpr (isForAllTy_ty tyR) (ppr co $$ ppr ty) $
|
| 2928 | - Just (ty `mkCastTyCo` co1, coercionLKind co2, CCoercion co2)
|
|
| 2928 | + Just (ty `mkCastTy` co1, coercionLKind co2, CCoercion co2)
|
|
| 2929 | 2929 | |
| 2930 | 2930 | | otherwise
|
| 2931 | 2931 | = Nothing
|
| ... | ... | @@ -227,7 +227,7 @@ mkGReflRightRedn :: Role -> Type -> CoercionN -> Reduction |
| 227 | 227 | mkGReflRightRedn role ty co
|
| 228 | 228 | = mkReduction
|
| 229 | 229 | (mkGReflRightCo role ty co)
|
| 230 | - (mkCastTyCo ty co)
|
|
| 230 | + (mkCastTy ty co)
|
|
| 231 | 231 | {-# INLINE mkGReflRightRedn #-}
|
| 232 | 232 | |
| 233 | 233 | -- | Create a 'Reduction' from a kind cast, in which
|
| ... | ... | @@ -236,11 +236,11 @@ mkGReflRightRedn role ty co |
| 236 | 236 | -- Given @ty :: k1@, @mco :: k1 ~ k2@,
|
| 237 | 237 | -- produces the 'Reduction' @ty ~res_co~> (ty |> mco)@
|
| 238 | 238 | -- at the given 'Role'.
|
| 239 | -mkGReflRightMRedn :: Role -> Type -> CastCoercion -> Reduction
|
|
| 239 | +mkGReflRightMRedn :: Role -> Type -> MCoercionN -> Reduction
|
|
| 240 | 240 | mkGReflRightMRedn role ty mco
|
| 241 | 241 | = mkReduction
|
| 242 | - (mkGReflRightCastCo role ty mco)
|
|
| 243 | - (mkCastTy ty mco)
|
|
| 242 | + (mkGReflRightMCo role ty mco)
|
|
| 243 | + (mkCastTyMCo ty mco)
|
|
| 244 | 244 | {-# INLINE mkGReflRightMRedn #-}
|
| 245 | 245 | |
| 246 | 246 | -- | Create a 'Reduction' from a kind cast, in which
|
| ... | ... | @@ -262,10 +262,10 @@ mkGReflLeftRedn role ty co |
| 262 | 262 | -- Given @ty :: k1@, @mco :: k1 ~ k2@,
|
| 263 | 263 | -- produces the 'Reduction' @(ty |> mco) ~res_co~> ty@
|
| 264 | 264 | -- at the given 'Role'.
|
| 265 | -mkGReflLeftMRedn :: Role -> Type -> CastCoercion -> Reduction
|
|
| 265 | +mkGReflLeftMRedn :: Role -> Type -> MCoercionN -> Reduction
|
|
| 266 | 266 | mkGReflLeftMRedn role ty mco
|
| 267 | 267 | = mkReduction
|
| 268 | - (mkGReflLeftCastCo role ty mco)
|
|
| 268 | + (mkGReflLeftMCo role ty mco)
|
|
| 269 | 269 | ty
|
| 270 | 270 | {-# INLINE mkGReflLeftMRedn #-}
|
| 271 | 271 | |
| ... | ... | @@ -279,7 +279,7 @@ mkCoherenceRightRedn :: Role -> Reduction -> CoercionN -> Reduction |
| 279 | 279 | mkCoherenceRightRedn r (Reduction co1 ty2) kco
|
| 280 | 280 | = mkReduction
|
| 281 | 281 | (mkCoherenceRightCo r ty2 kco co1)
|
| 282 | - (mkCastTyCo ty2 kco)
|
|
| 282 | + (mkCastTy ty2 kco)
|
|
| 283 | 283 | {-# INLINE mkCoherenceRightRedn #-}
|
| 284 | 284 | |
| 285 | 285 | -- | Apply a cast to the result of a 'Reduction', using an 'MCoercionN'.
|
| ... | ... | @@ -314,7 +314,7 @@ mkCastRedn1 r ty cast_co (Reduction co xi) |
| 314 | 314 | -- return_co :: (ty |> cast_co) ~r (ty' |> cast_co)
|
| 315 | 315 | = mkReduction
|
| 316 | 316 | (castCoercionKind1 co r ty xi cast_co)
|
| 317 | - (mkCastTyCo xi cast_co)
|
|
| 317 | + (mkCastTy xi cast_co)
|
|
| 318 | 318 | {-# INLINE mkCastRedn1 #-}
|
| 319 | 319 | |
| 320 | 320 | -- | Apply casts on both sides of a 'Reduction' (of the given 'Role').
|
| ... | ... | @@ -333,7 +333,7 @@ mkCastRedn2 :: Role |
| 333 | 333 | mkCastRedn2 r ty cast_co (Reduction nco nty) cast_co'
|
| 334 | 334 | = mkReduction
|
| 335 | 335 | (castCoercionKind2 nco r ty nty cast_co cast_co')
|
| 336 | - (mkCastTyCo nty cast_co')
|
|
| 336 | + (mkCastTy nty cast_co')
|
|
| 337 | 337 | {-# INLINE mkCastRedn2 #-}
|
| 338 | 338 | |
| 339 | 339 | -- | Apply one 'Reduction' to another.
|
| ... | ... | @@ -76,7 +76,6 @@ import GHC.Utils.EndoOS |
| 76 | 76 | |
| 77 | 77 | import GHC.Data.Pair
|
| 78 | 78 | |
| 79 | -import Data.Maybe
|
|
| 80 | 79 | import Data.Semigroup
|
| 81 | 80 | |
| 82 | 81 | {-
|
| ... | ... | @@ -668,7 +667,7 @@ tyCoFVsOfType (LitTy {}) f bound_vars acc = emptyFV f bound_vars acc |
| 668 | 667 | tyCoFVsOfType (AppTy fun arg) f bound_vars acc = (tyCoFVsOfType fun `unionFV` tyCoFVsOfType arg) f bound_vars acc
|
| 669 | 668 | tyCoFVsOfType (FunTy _ w arg res) f bound_vars acc = (tyCoFVsOfType w `unionFV` tyCoFVsOfType arg `unionFV` tyCoFVsOfType res) f bound_vars acc
|
| 670 | 669 | tyCoFVsOfType (ForAllTy bndr ty) f bound_vars acc = tyCoFVsBndr bndr (tyCoFVsOfType ty) f bound_vars acc
|
| 671 | -tyCoFVsOfType (CastTy ty co) f bound_vars acc = (tyCoFVsOfType ty `unionFV` tyCoFVsOfCastCoercion co) f bound_vars acc
|
|
| 670 | +tyCoFVsOfType (CastTy ty co) f bound_vars acc = (tyCoFVsOfType ty `unionFV` tyCoFVsOfCo co) f bound_vars acc
|
|
| 672 | 671 | tyCoFVsOfType (CoercionTy co) f bound_vars acc = tyCoFVsOfCo co f bound_vars acc
|
| 673 | 672 | |
| 674 | 673 | tyCoFVsBndr :: ForAllTyBinder -> FV -> FV
|
| ... | ... | @@ -766,11 +765,6 @@ almost_devoid_co_var_of_mco :: MCoercion -> CoVar -> Bool |
| 766 | 765 | almost_devoid_co_var_of_mco MRefl _ = True
|
| 767 | 766 | almost_devoid_co_var_of_mco (MCo co) cv = almost_devoid_co_var_of_co co cv
|
| 768 | 767 | |
| 769 | -almost_devoid_co_var_of_cast_co :: CastCoercion -> CoVar -> Bool
|
|
| 770 | -almost_devoid_co_var_of_cast_co ReflCastCo _ = True
|
|
| 771 | -almost_devoid_co_var_of_cast_co (CCoercion co) cv = almost_devoid_co_var_of_co co cv
|
|
| 772 | -almost_devoid_co_var_of_cast_co (ZCoercion ty cos) cv = almost_devoid_co_var_of_type ty cv && not (elemVarSet cv cos)
|
|
| 773 | - |
|
| 774 | 768 | almost_devoid_co_var_of_co :: Coercion -> CoVar -> Bool
|
| 775 | 769 | almost_devoid_co_var_of_co (Refl {}) _ = True -- covar is allowed in Refl and
|
| 776 | 770 | almost_devoid_co_var_of_co (GRefl {}) _ = True -- GRefl, so we don't look into
|
| ... | ... | @@ -835,7 +829,7 @@ almost_devoid_co_var_of_type (ForAllTy (Bndr v _) ty) cv |
| 835 | 829 | && (v == cv || almost_devoid_co_var_of_type ty cv)
|
| 836 | 830 | almost_devoid_co_var_of_type (CastTy ty co) cv
|
| 837 | 831 | = almost_devoid_co_var_of_type ty cv
|
| 838 | - && almost_devoid_co_var_of_cast_co co cv
|
|
| 832 | + && almost_devoid_co_var_of_co co cv
|
|
| 839 | 833 | almost_devoid_co_var_of_type (CoercionTy co) cv
|
| 840 | 834 | = almost_devoid_co_var_of_co co cv
|
| 841 | 835 | |
| ... | ... | @@ -872,7 +866,7 @@ visVarsOfType orig_ty = Pair invis_vars vis_vars |
| 872 | 866 | = ((`delVarSet` tv) <$> go ty) `mappend`
|
| 873 | 867 | (invisible (tyCoVarsOfType $ varType tv))
|
| 874 | 868 | go (LitTy {}) = mempty
|
| 875 | - go (CastTy ty co) = go ty `mappend` invisible (tyCoVarsOfCastCo co)
|
|
| 869 | + go (CastTy ty co) = go ty `mappend` invisible (tyCoVarsOfCo co)
|
|
| 876 | 870 | go (CoercionTy co) = invisible $ tyCoVarsOfCo co
|
| 877 | 871 | |
| 878 | 872 | invisible vs = Pair vs emptyVarSet
|
| ... | ... | @@ -1011,7 +1005,7 @@ invisibleVarsOfType = go |
| 1011 | 1005 | where (invisibles, visibles) = partitionInvisibleTypes tc tys
|
| 1012 | 1006 | go (ForAllTy tvb ty) = tyCoFVsBndr tvb $ go ty
|
| 1013 | 1007 | go LitTy{} = emptyFV
|
| 1014 | - go (CastTy ty co) = tyCoFVsOfCastCoercion co `unionFV` go ty
|
|
| 1008 | + go (CastTy ty co) = tyCoFVsOfCo co `unionFV` go ty
|
|
| 1015 | 1009 | go (CoercionTy co) = tyCoFVsOfCo co
|
| 1016 | 1010 | |
| 1017 | 1011 | -- | Like 'invisibleVarsOfType', but for many types.
|
| ... | ... | @@ -1102,7 +1096,7 @@ tyConsOfType ty |
| 1102 | 1096 | go a `unionUniqSets` go b
|
| 1103 | 1097 | `unionUniqSets` go_tc (funTyFlagTyCon af)
|
| 1104 | 1098 | go (ForAllTy (Bndr tv _) ty) = go ty `unionUniqSets` go (varType tv)
|
| 1105 | - go (CastTy ty co) = go ty `unionUniqSets` go_cast_co co
|
|
| 1099 | + go (CastTy ty co) = go ty `unionUniqSets` go_co co
|
|
| 1106 | 1100 | go (CoercionTy co) = go_co co
|
| 1107 | 1101 | |
| 1108 | 1102 | go_co (Refl ty) = go ty
|
| ... | ... | @@ -1129,10 +1123,6 @@ tyConsOfType ty |
| 1129 | 1123 | go_mco MRefl = emptyUniqSet
|
| 1130 | 1124 | go_mco (MCo co) = go_co co
|
| 1131 | 1125 | |
| 1132 | - go_cast_co ReflCastCo = emptyUniqSet
|
|
| 1133 | - go_cast_co (CCoercion co) = go_co co
|
|
| 1134 | - go_cast_co (ZCoercion ty _cos) = go ty
|
|
| 1135 | - |
|
| 1136 | 1126 | go_cos cos = foldr (unionUniqSets . go_co) emptyUniqSet cos
|
| 1137 | 1127 | |
| 1138 | 1128 | go_tc tc = unitUniqSet tc
|
| ... | ... | @@ -1266,7 +1256,7 @@ occCheckExpand vs_to_avoid ty |
| 1266 | 1256 | -- Failing that, try to expand a synonym
|
| 1267 | 1257 | |
| 1268 | 1258 | go cxt (CastTy ty co) = do { ty' <- go cxt ty
|
| 1269 | - ; co' <- go_cast_co cxt co
|
|
| 1259 | + ; co' <- go_co cxt co
|
|
| 1270 | 1260 | ; return (CastTy ty' co') }
|
| 1271 | 1261 | go cxt (CoercionTy co) = do { co' <- go_co cxt co
|
| 1272 | 1262 | ; return (CoercionTy co') }
|
| ... | ... | @@ -1283,14 +1273,6 @@ occCheckExpand vs_to_avoid ty |
| 1283 | 1273 | go_mco _ MRefl = return MRefl
|
| 1284 | 1274 | go_mco ctx (MCo co) = MCo <$> go_co ctx co
|
| 1285 | 1275 | |
| 1286 | - go_cast_co _ ReflCastCo = return ReflCastCo
|
|
| 1287 | - go_cast_co ctx (CCoercion co) = CCoercion <$> go_co ctx co
|
|
| 1288 | - go_cast_co ctx (ZCoercion ty cos) = ZCoercion <$> go ctx ty <*> go_covars ctx cos
|
|
| 1289 | - |
|
| 1290 | - go_covars (as, env) cos
|
|
| 1291 | - | anyVarSet (bad_var_occ as) cos = Nothing
|
|
| 1292 | - | otherwise = return $ mapVarSet (\cv -> fromMaybe cv (lookupVarEnv env cv)) cos
|
|
| 1293 | - |
|
| 1294 | 1276 | ------------------
|
| 1295 | 1277 | go_co cxt (Refl ty) = do { ty' <- go cxt ty
|
| 1296 | 1278 | ; return (Refl ty') }
|
| ... | ... | @@ -186,7 +186,7 @@ data Type |
| 186 | 186 | |
| 187 | 187 | | CastTy
|
| 188 | 188 | Type
|
| 189 | - CastCoercion -- ^ A kind cast. The coercion is always nominal.
|
|
| 189 | + KindCoercion -- ^ A kind cast. The coercion is always nominal.
|
|
| 190 | 190 | -- INVARIANT: The cast is never reflexive \(EQ2)
|
| 191 | 191 | -- INVARIANT: The Type is not a CastTy (use TransCo instead) \(EQ3)
|
| 192 | 192 | -- INVARIANT: The Type is not a ForAllTy over a tyvar \(EQ4)
|
| ... | ... | @@ -2055,7 +2055,7 @@ foldTyCo (TyCoFolder { tcf_view = view |
| 2055 | 2055 | go_ty env (TyVarTy tv) = tyvar env tv
|
| 2056 | 2056 | go_ty env (AppTy t1 t2) = go_ty env t1 `mappend` go_ty env t2
|
| 2057 | 2057 | go_ty _ (LitTy {}) = mempty
|
| 2058 | - go_ty env (CastTy ty co) = go_ty env ty `mappend` go_cast_co env co
|
|
| 2058 | + go_ty env (CastTy ty co) = go_ty env ty `mappend` go_co env co
|
|
| 2059 | 2059 | go_ty env (CoercionTy co) = go_co env co
|
| 2060 | 2060 | go_ty env (FunTy _ w arg res) = go_ty env w `mappend` go_ty env arg `mappend` go_ty env res
|
| 2061 | 2061 | go_ty env (TyConApp _ tys) = go_tys env tys
|
| ... | ... | @@ -2071,10 +2071,6 @@ foldTyCo (TyCoFolder { tcf_view = view |
| 2071 | 2071 | go_cos _ [] = mempty
|
| 2072 | 2072 | go_cos env (c:cs) = go_co env c `mappend` go_cos env cs
|
| 2073 | 2073 | |
| 2074 | - go_cast_co _ ReflCastCo = mempty
|
|
| 2075 | - go_cast_co env (CCoercion co) = go_co env co
|
|
| 2076 | - go_cast_co env (ZCoercion ty cos) = go_ty env ty `mappend` nonDetStrictFoldVarSet (mappend . covar env) mempty cos
|
|
| 2077 | - |
|
| 2078 | 2074 | go_co env (Refl ty) = go_ty env ty
|
| 2079 | 2075 | go_co env (GRefl _ ty MRefl) = go_ty env ty
|
| 2080 | 2076 | go_co env (GRefl _ ty (MCo co)) = go_ty env ty `mappend` go_co env co
|
| ... | ... | @@ -2138,7 +2134,7 @@ typeSize (AppTy t1 t2) = typeSize t1 + typeSize t2 |
| 2138 | 2134 | typeSize (FunTy _ _ t1 t2) = typeSize t1 + typeSize t2
|
| 2139 | 2135 | typeSize (ForAllTy (Bndr tv _) t) = typeSize (varType tv) + typeSize t
|
| 2140 | 2136 | typeSize (TyConApp _ ts) = 1 + typesSize ts
|
| 2141 | -typeSize (CastTy ty co) = typeSize ty + castCoercionSize co
|
|
| 2137 | +typeSize (CastTy ty co) = typeSize ty + coercionSize co
|
|
| 2142 | 2138 | typeSize (CoercionTy co) = coercionSize co
|
| 2143 | 2139 | |
| 2144 | 2140 | typesSize :: [Type] -> Int
|
| ... | ... | @@ -797,7 +797,7 @@ subst_ty subst ty |
| 797 | 797 | !(subst',tv') = substVarBndrUnchecked subst tv
|
| 798 | 798 | -- Unchecked because subst_ty is used from substTyUnchecked
|
| 799 | 799 | go (LitTy n) = LitTy $! n
|
| 800 | - go (CastTy ty co) = (mkCastTy $! (go ty)) $! (subst_cast_co subst co)
|
|
| 800 | + go (CastTy ty co) = (mkCastTy $! (go ty)) $! (subst_co subst co)
|
|
| 801 | 801 | go (CoercionTy co) = CoercionTy $! (subst_co subst co)
|
| 802 | 802 | |
| 803 | 803 | substTyVar :: Subst -> TyVar -> Type
|
| ... | ... | @@ -835,14 +835,9 @@ lookupTyVar (Subst _ _ tenv _) tv |
| 835 | 835 | lookupVarEnv tenv tv
|
| 836 | 836 | |
| 837 | 837 | substCastCo :: HasDebugCallStack => Subst -> CastCoercion -> CastCoercion
|
| 838 | -substCastCo subst co
|
|
| 839 | - | isEmptyTCvSubst subst = co
|
|
| 840 | - | otherwise = {- checkValidSubst subst [] [co] $ -} subst_cast_co subst co -- TODO
|
|
| 841 | - |
|
| 842 | -subst_cast_co :: HasDebugCallStack => Subst -> CastCoercion -> CastCoercion
|
|
| 843 | -subst_cast_co subst (CCoercion co) = CCoercion $! subst_co subst co
|
|
| 844 | -subst_cast_co subst (ZCoercion ty cos) = (ZCoercion $! subst_ty subst ty) $! substCoVarSet subst cos
|
|
| 845 | -subst_cast_co _ ReflCastCo = ReflCastCo
|
|
| 838 | +substCastCo subst (CCoercion co) = CCoercion (substCo subst co)
|
|
| 839 | +substCastCo subst (ZCoercion ty cos) = ZCoercion (substTy subst ty) (substCoVarSet subst cos)
|
|
| 840 | +substCastCo _ ReflCastCo = ReflCastCo
|
|
| 846 | 841 | |
| 847 | 842 | substCoVarSet :: HasDebugCallStack => Subst -> CoVarSet -> CoVarSet
|
| 848 | 843 | substCoVarSet subst = nonDetStrictFoldVarSet (unionVarSet . shallowCoVarsOfCo . substCoVar subst) emptyVarSet -- TODO better impl; determinism?
|
| ... | ... | @@ -235,7 +235,7 @@ tidyType env (TyVarTy tv) = TyVarTy $! tidyTyCoVarOcc env tv |
| 235 | 235 | tidyType _ t@(TyConApp _ []) = t -- Preserve sharing if possible
|
| 236 | 236 | tidyType env (TyConApp tycon tys) = TyConApp tycon $! tidyTypes env tys
|
| 237 | 237 | tidyType env (AppTy fun arg) = (AppTy $! (tidyType env fun)) $! (tidyType env arg)
|
| 238 | -tidyType env (CastTy ty co) = (CastTy $! tidyType env ty) $! (tidyCastCo env co)
|
|
| 238 | +tidyType env (CastTy ty co) = (CastTy $! tidyType env ty) $! (tidyCo env co)
|
|
| 239 | 239 | tidyType env (CoercionTy co) = CoercionTy $! (tidyCo env co)
|
| 240 | 240 | tidyType env ty@(FunTy _ w arg res) = let { !w' = tidyType env w
|
| 241 | 241 | ; !arg' = tidyType env arg
|
| ... | ... | @@ -73,7 +73,6 @@ module GHC.Core.Type ( |
| 73 | 73 | getLevity, levityType_maybe,
|
| 74 | 74 | |
| 75 | 75 | mkCastTy, mkCoercionTy, splitCastTy_maybe,
|
| 76 | - mkCastTyCo,
|
|
| 77 | 76 | |
| 78 | 77 | ErrorMsgType, pprUserTypeErrorTy,
|
| 79 | 78 | |
| ... | ... | @@ -237,7 +236,6 @@ import GHC.Core.TyCo.FVs |
| 237 | 236 | import GHC.Types.Var
|
| 238 | 237 | import GHC.Types.Var.Env
|
| 239 | 238 | import GHC.Types.Var.Set
|
| 240 | -import GHC.Types.Unique.Set
|
|
| 241 | 239 | |
| 242 | 240 | import GHC.Core.TyCon
|
| 243 | 241 | import GHC.Builtin.Types.Prim
|
| ... | ... | @@ -260,12 +258,9 @@ import {-# SOURCE #-} GHC.Core.Coercion |
| 260 | 258 | , mkSymCo, mkTransCo, mkSelCo, mkLRCo, mkInstCo
|
| 261 | 259 | , mkKindCo, mkSubCo, mkFunCo, funRole
|
| 262 | 260 | , decomposePiCos, coercionKind
|
| 263 | - , coercionType
|
|
| 264 | - , isReflexiveCastCo, seqCo
|
|
| 261 | + , coercionRKind, coercionType
|
|
| 262 | + , isReflexiveCo, seqCo
|
|
| 265 | 263 | , topNormaliseNewType_maybe
|
| 266 | - , mkTransCastCo
|
|
| 267 | - , seqCastCoercion, castCoercionRKind
|
|
| 268 | - , castCoToCo
|
|
| 269 | 264 | )
|
| 270 | 265 | import {-# SOURCE #-} GHC.Tc.Utils.TcType ( isConcreteTyVar )
|
| 271 | 266 | |
| ... | ... | @@ -519,16 +514,12 @@ expandTypeSynonyms ty |
| 519 | 514 | go subst (ForAllTy (Bndr tv vis) t)
|
| 520 | 515 | = let (subst', tv') = substVarBndrUsing go subst tv in
|
| 521 | 516 | ForAllTy (Bndr tv' vis) (go subst' t)
|
| 522 | - go subst (CastTy ty co) = mkCastTy (go subst ty) (go_cast_co subst co)
|
|
| 517 | + go subst (CastTy ty co) = mkCastTy (go subst ty) (go_co subst co)
|
|
| 523 | 518 | go subst (CoercionTy co) = mkCoercionTy (go_co subst co)
|
| 524 | 519 | |
| 525 | 520 | go_mco _ MRefl = MRefl
|
| 526 | 521 | go_mco subst (MCo co) = MCo (go_co subst co)
|
| 527 | 522 | |
| 528 | - go_cast_co _ ReflCastCo = ReflCastCo
|
|
| 529 | - go_cast_co subst (CCoercion co) = CCoercion (go_co subst co)
|
|
| 530 | - go_cast_co subst (ZCoercion ty cos) = ZCoercion (go subst ty) (substCoVarSet subst cos)
|
|
| 531 | - |
|
| 532 | 523 | go_co subst (Refl ty)
|
| 533 | 524 | = mkNomReflCo (go subst ty)
|
| 534 | 525 | go_co subst (GRefl r ty mco)
|
| ... | ... | @@ -914,7 +905,7 @@ mapTyCoX (TyCoMapper { tcm_tyvar = tyvar |
| 914 | 905 | go_ty !env (TyVarTy tv) = tyvar env tv
|
| 915 | 906 | go_ty !env (AppTy t1 t2) = mkAppTy <$> go_ty env t1 <*> go_ty env t2
|
| 916 | 907 | go_ty !_ ty@(LitTy {}) = return ty
|
| 917 | - go_ty !env (CastTy ty co) = mkCastTy <$> go_ty env ty <*> go_cast_co env co
|
|
| 908 | + go_ty !env (CastTy ty co) = mkCastTy <$> go_ty env ty <*> go_co env co
|
|
| 918 | 909 | go_ty !env (CoercionTy co) = CoercionTy <$> go_co env co
|
| 919 | 910 | |
| 920 | 911 | go_ty !env ty@(FunTy _ w arg res)
|
| ... | ... | @@ -945,10 +936,6 @@ mapTyCoX (TyCoMapper { tcm_tyvar = tyvar |
| 945 | 936 | go_mco !_ MRefl = return MRefl
|
| 946 | 937 | go_mco !env (MCo co) = MCo <$> (go_co env co)
|
| 947 | 938 | |
| 948 | - go_cast_co !_ ReflCastCo = return ReflCastCo
|
|
| 949 | - go_cast_co !env (CCoercion co) = CCoercion <$> (go_co env co)
|
|
| 950 | - go_cast_co !env (ZCoercion ty cos) = ZCoercion <$> go_ty env ty <*> (coVarsOfCos <$> mapM (covar env) (nonDetEltsUniqSet cos)) -- TODO
|
|
| 951 | - |
|
| 952 | 939 | go_co :: env -> Coercion -> m Coercion
|
| 953 | 940 | go_co !env (Refl ty) = Refl <$> go_ty env ty
|
| 954 | 941 | go_co !env (GRefl r ty mco) = mkGReflCo r <$> go_ty env ty <*> go_mco env mco
|
| ... | ... | @@ -1033,10 +1020,10 @@ isTyVarTy ty = isJust (getTyVar_maybe ty) |
| 1033 | 1020 | |
| 1034 | 1021 | -- | If the type is a tyvar, possibly under a cast, returns it, along
|
| 1035 | 1022 | -- with the coercion. Thus, the co is :: kind tv ~N kind ty
|
| 1036 | -getCastedTyVar_maybe :: Type -> Maybe (TyVar, CastCoercion)
|
|
| 1023 | +getCastedTyVar_maybe :: Type -> Maybe (TyVar, CoercionN)
|
|
| 1037 | 1024 | getCastedTyVar_maybe ty = case coreFullView ty of
|
| 1038 | 1025 | CastTy (TyVarTy tv) co -> Just (tv, co)
|
| 1039 | - TyVarTy tv -> Just (tv, ReflCastCo)
|
|
| 1026 | + TyVarTy tv -> Just (tv, mkReflCo Nominal (tyVarKind tv))
|
|
| 1040 | 1027 | _ -> Nothing
|
| 1041 | 1028 | |
| 1042 | 1029 | |
| ... | ... | @@ -1076,10 +1063,9 @@ type checker (e.g. when matching type-function equations). |
| 1076 | 1063 | -- | Applies a type to another, as in e.g. @k a@
|
| 1077 | 1064 | mkAppTy :: Type -> Type -> Type
|
| 1078 | 1065 | -- See Note [Respecting definitional equality], invariant (EQ1).
|
| 1079 | -mkAppTy (CastTy fun_ty cco) arg_ty
|
|
| 1080 | - | let co = castCoToCo (typeKind fun_ty) cco -- TOOD: can we get rid of this?
|
|
| 1081 | - , ([arg_co], res_co) <- decomposePiCos co (coercionKind co) [arg_ty]
|
|
| 1082 | - = (fun_ty `mkAppTy` (arg_ty `mkCastTy` CCoercion arg_co)) `mkCastTy` CCoercion res_co
|
|
| 1066 | +mkAppTy (CastTy fun_ty co) arg_ty
|
|
| 1067 | + | ([arg_co], res_co) <- decomposePiCos co (coercionKind co) [arg_ty]
|
|
| 1068 | + = (fun_ty `mkAppTy` (arg_ty `mkCastTy` arg_co)) `mkCastTy` res_co
|
|
| 1083 | 1069 | |
| 1084 | 1070 | mkAppTy (TyConApp tc tys) ty2 = mkTyConApp tc (tys ++ [ty2])
|
| 1085 | 1071 | mkAppTy ty1 ty2 = AppTy ty1 ty2
|
| ... | ... | @@ -1098,16 +1084,15 @@ mkAppTy ty1 ty2 = AppTy ty1 ty2 |
| 1098 | 1084 | |
| 1099 | 1085 | mkAppTys :: Type -> [Type] -> Type
|
| 1100 | 1086 | mkAppTys ty1 [] = ty1
|
| 1101 | -mkAppTys (CastTy fun_ty cco) arg_tys -- much more efficient then nested mkAppTy
|
|
| 1087 | +mkAppTys (CastTy fun_ty co) arg_tys -- much more efficient then nested mkAppTy
|
|
| 1102 | 1088 | -- Why do this? See (EQ1) of
|
| 1103 | 1089 | -- Note [Respecting definitional equality]
|
| 1104 | 1090 | -- in GHC.Core.TyCo.Rep
|
| 1105 | - = foldl' AppTy ((mkAppTys fun_ty casted_arg_tys) `mkCastTy` CCoercion res_co) leftovers
|
|
| 1091 | + = foldl' AppTy ((mkAppTys fun_ty casted_arg_tys) `mkCastTy` res_co) leftovers
|
|
| 1106 | 1092 | where
|
| 1107 | - co = castCoToCo (typeKind fun_ty) cco
|
|
| 1108 | 1093 | (arg_cos, res_co) = decomposePiCos co (coercionKind co) arg_tys
|
| 1109 | 1094 | (args_to_cast, leftovers) = splitAtList arg_cos arg_tys
|
| 1110 | - casted_arg_tys = zipWith (\ ty co -> mkCastTy ty (CCoercion co)) args_to_cast arg_cos
|
|
| 1095 | + casted_arg_tys = zipWith mkCastTy args_to_cast arg_cos
|
|
| 1111 | 1096 | mkAppTys (TyConApp tc tys1) tys2 = mkTyConApp tc (tys1 ++ tys2)
|
| 1112 | 1097 | mkAppTys ty1 tys2 = foldl' AppTy ty1 tys2
|
| 1113 | 1098 | |
| ... | ... | @@ -1662,19 +1647,16 @@ newTyConInstRhs tycon tys |
| 1662 | 1647 | * *
|
| 1663 | 1648 | ********************************************************************* -}
|
| 1664 | 1649 | |
| 1665 | -splitCastTy_maybe :: Type -> Maybe (Type, CastCoercion)
|
|
| 1650 | +splitCastTy_maybe :: Type -> Maybe (Type, Coercion)
|
|
| 1666 | 1651 | splitCastTy_maybe ty
|
| 1667 | 1652 | | CastTy ty' co <- coreFullView ty = Just (ty', co)
|
| 1668 | 1653 | | otherwise = Nothing
|
| 1669 | 1654 | |
| 1670 | -mkCastTyCo :: Type -> Coercion -> Type
|
|
| 1671 | -mkCastTyCo ty co = mkCastTy ty (CCoercion co)
|
|
| 1672 | - |
|
| 1673 | 1655 | -- | Make a 'CastTy'. The Coercion must be nominal. Checks the
|
| 1674 | 1656 | -- Coercion for reflexivity, dropping it if it's reflexive.
|
| 1675 | 1657 | -- See @Note [Respecting definitional equality]@ in "GHC.Core.TyCo.Rep"
|
| 1676 | -mkCastTy :: Type -> CastCoercion -> Type
|
|
| 1677 | -mkCastTy orig_ty co | isReflexiveCastCo (typeKind orig_ty) co = orig_ty -- (EQ2) from the Note
|
|
| 1658 | +mkCastTy :: Type -> Coercion -> Type
|
|
| 1659 | +mkCastTy orig_ty co | isReflexiveCo co = orig_ty -- (EQ2) from the Note
|
|
| 1678 | 1660 | -- NB: Do the slow check here. This is important to keep the splitXXX
|
| 1679 | 1661 | -- functions working properly. Otherwise, we may end up with something
|
| 1680 | 1662 | -- like (((->) |> something_reflexive_but_not_obviously_so) biz baz)
|
| ... | ... | @@ -1684,7 +1666,7 @@ mkCastTy orig_ty co = mk_cast_ty orig_ty co |
| 1684 | 1666 | |
| 1685 | 1667 | -- | Like 'mkCastTy', but avoids checking the coercion for reflexivity,
|
| 1686 | 1668 | -- as that can be expensive.
|
| 1687 | -mk_cast_ty :: Type -> CastCoercion -> Type
|
|
| 1669 | +mk_cast_ty :: Type -> Coercion -> Type
|
|
| 1688 | 1670 | mk_cast_ty orig_ty co = go orig_ty
|
| 1689 | 1671 | where
|
| 1690 | 1672 | go :: Type -> Type
|
| ... | ... | @@ -1693,14 +1675,14 @@ mk_cast_ty orig_ty co = go orig_ty |
| 1693 | 1675 | |
| 1694 | 1676 | go (CastTy ty co1)
|
| 1695 | 1677 | -- (EQ3) from the Note
|
| 1696 | - = mkCastTy ty (co1 `mkTransCastCo` co)
|
|
| 1678 | + = mkCastTy ty (co1 `mkTransCo` co)
|
|
| 1697 | 1679 | -- call mkCastTy again for the reflexivity check
|
| 1698 | 1680 | |
| 1699 | 1681 | go (ForAllTy (Bndr tv vis) inner_ty)
|
| 1700 | 1682 | -- (EQ4) from the Note
|
| 1701 | 1683 | -- See Note [Weird typing rule for ForAllTy] in GHC.Core.TyCo.Rep.
|
| 1702 | 1684 | | isTyVar tv
|
| 1703 | - , let fvs = tyCoVarsOfCastCo co
|
|
| 1685 | + , let fvs = tyCoVarsOfCo co
|
|
| 1704 | 1686 | = -- have to make sure that pushing the co in doesn't capture the bound var!
|
| 1705 | 1687 | if tv `elemVarSet` fvs
|
| 1706 | 1688 | then let empty_subst = mkEmptySubst (mkInScopeSet fvs)
|
| ... | ... | @@ -2564,7 +2546,7 @@ seqType (AppTy t1 t2) = seqType t1 `seq` seqType t2 |
| 2564 | 2546 | seqType (FunTy _ w t1 t2) = seqType w `seq` seqType t1 `seq` seqType t2
|
| 2565 | 2547 | seqType (TyConApp tc tys) = tc `seq` seqTypes tys
|
| 2566 | 2548 | seqType (ForAllTy (Bndr tv _) ty) = seqType (varType tv) `seq` seqType ty
|
| 2567 | -seqType (CastTy ty co) = seqType ty `seq` seqCastCoercion co
|
|
| 2549 | +seqType (CastTy ty co) = seqType ty `seq` seqCo co
|
|
| 2568 | 2550 | seqType (CoercionTy co) = seqCo co
|
| 2569 | 2551 | |
| 2570 | 2552 | seqTypes :: [Type] -> ()
|
| ... | ... | @@ -2658,7 +2640,7 @@ typeKind (TyConApp tc tys) = piResultTys (tyConKind tc) tys |
| 2658 | 2640 | typeKind (LitTy l) = typeLiteralKind l
|
| 2659 | 2641 | typeKind (FunTy { ft_af = af }) = liftedTypeOrConstraintKind (funTyFlagResultTypeOrConstraint af)
|
| 2660 | 2642 | typeKind (TyVarTy tyvar) = tyVarKind tyvar
|
| 2661 | -typeKind (CastTy ty co) = castCoercionRKind (typeKind ty) co
|
|
| 2643 | +typeKind (CastTy _ty co) = coercionRKind co
|
|
| 2662 | 2644 | typeKind (CoercionTy co) = coercionType co
|
| 2663 | 2645 | |
| 2664 | 2646 | typeKind (AppTy fun arg)
|
| ... | ... | @@ -4,7 +4,7 @@ module GHC.Core.Type where |
| 4 | 4 | |
| 5 | 5 | import GHC.Prelude
|
| 6 | 6 | import {-# SOURCE #-} GHC.Core.TyCon
|
| 7 | -import {-# SOURCE #-} GHC.Core.TyCo.Rep( Type, CastCoercion )
|
|
| 7 | +import {-# SOURCE #-} GHC.Core.TyCo.Rep( Type, Coercion )
|
|
| 8 | 8 | import GHC.Utils.Misc
|
| 9 | 9 | import GHC.Types.Var( FunTyFlag, TyVar )
|
| 10 | 10 | import GHC.Types.Basic( TypeOrConstraint )
|
| ... | ... | @@ -16,7 +16,7 @@ chooseFunTyFlag :: HasDebugCallStack => Type -> Type -> FunTyFlag |
| 16 | 16 | typeKind :: HasDebugCallStack => Type -> Type
|
| 17 | 17 | isCoercionTy :: Type -> Bool
|
| 18 | 18 | mkAppTy :: Type -> Type -> Type
|
| 19 | -mkCastTy :: Type -> CastCoercion -> Type
|
|
| 19 | +mkCastTy :: Type -> Coercion -> Type
|
|
| 20 | 20 | mkTyConApp :: TyCon -> [Type] -> Type
|
| 21 | 21 | getLevity :: HasDebugCallStack => Type -> Type
|
| 22 | 22 | getTyVar_maybe :: Type -> Maybe TyVar
|
| ... | ... | @@ -1582,13 +1582,12 @@ type AmIUnifying = Bool -- True <=> Unifying |
| 1582 | 1582 | -- False <=> Matching
|
| 1583 | 1583 | |
| 1584 | 1584 | type InType = Type -- Before applying the RnEnv2
|
| 1585 | -type OutCastCoercion = CastCoercion -- After applying the RnEnv2
|
|
| 1586 | - |
|
| 1585 | +type OutCoercion = Coercion -- After applying the RnEnv2
|
|
| 1587 | 1586 | |
| 1588 | 1587 | |
| 1589 | 1588 | unify_ty :: UMEnv
|
| 1590 | 1589 | -> InType -> InType -- Types to be unified
|
| 1591 | - -> OutCastCoercion -- A nominal coercion between their kinds
|
|
| 1590 | + -> OutCoercion -- A nominal coercion between their kinds
|
|
| 1592 | 1591 | -- OutCoercion: the RnEnv has already been applied
|
| 1593 | 1592 | -- When matching, the coercion is in "target space",
|
| 1594 | 1593 | -- not "template space"
|
| ... | ... | @@ -1610,28 +1609,28 @@ unify_ty env ty1 ty2 kco |
| 1610 | 1609 | | Just ty2' <- coreView ty2 = unify_ty env ty1 ty2' kco
|
| 1611 | 1610 | |
| 1612 | 1611 | unify_ty env (CastTy ty1 co1) ty2 kco
|
| 1613 | - | mentionsForAllBoundTyVarsL env (tyCoVarsOfCastCo co1)
|
|
| 1612 | + | mentionsForAllBoundTyVarsL env (tyCoVarsOfCo co1)
|
|
| 1614 | 1613 | -- See (KCU1) in Note [Kind coercions in Unify]
|
| 1615 | 1614 | = maybeApart MARCast -- See (KCU2)
|
| 1616 | 1615 | |
| 1617 | 1616 | | um_unif env
|
| 1618 | - = unify_ty env ty1 ty2 (co1 `mkTransCastCo` kco)
|
|
| 1617 | + = unify_ty env ty1 ty2 (co1 `mkTransCo` kco)
|
|
| 1619 | 1618 | |
| 1620 | 1619 | | otherwise -- We are matching, not unifying
|
| 1621 | 1620 | = do { subst <- getSubst env
|
| 1622 | - ; let co' = substCastCo subst co1
|
|
| 1621 | + ; let co' = substCo subst co1
|
|
| 1623 | 1622 | -- We match left-to-right, so the free template vars of the
|
| 1624 | 1623 | -- coercion should already have been matched.
|
| 1625 | 1624 | -- See Note [Matching in the presence of casts (1)]
|
| 1626 | 1625 | -- NB: co1 does not mention forall-bound vars, so no need to rename
|
| 1627 | - ; unify_ty env ty1 ty2 (co' `mkTransCastCo` kco) }
|
|
| 1626 | + ; unify_ty env ty1 ty2 (co' `mkTransCo` kco) }
|
|
| 1628 | 1627 | |
| 1629 | 1628 | unify_ty env ty1 (CastTy ty2 co2) kco
|
| 1630 | - | mentionsForAllBoundTyVarsR env (tyCoVarsOfCastCo co2)
|
|
| 1629 | + | mentionsForAllBoundTyVarsR env (tyCoVarsOfCo co2)
|
|
| 1631 | 1630 | -- See (KCU1) in Note [Kind coercions in Unify]
|
| 1632 | 1631 | = maybeApart MARCast -- See (KCU2)
|
| 1633 | 1632 | | otherwise
|
| 1634 | - = unify_ty env ty1 ty2 (kco `mkTransCastCo` mkSymCastCo (typeKind ty2) co2)
|
|
| 1633 | + = unify_ty env ty1 ty2 (kco `mkTransCo` mkSymCo co2)
|
|
| 1635 | 1634 | -- NB: co2 does not mention forall-bound variables
|
| 1636 | 1635 | |
| 1637 | 1636 | -- Applications need a bit of care!
|
| ... | ... | @@ -1648,7 +1647,7 @@ unify_ty _ (LitTy x) (LitTy y) _kco | x == y = return () |
| 1648 | 1647 | |
| 1649 | 1648 | unify_ty env (ForAllTy (Bndr tv1 _) ty1) (ForAllTy (Bndr tv2 _) ty2) kco
|
| 1650 | 1649 | -- ToDo: See Note [Unifying coercion-foralls]
|
| 1651 | - = do { unify_ty env (varType tv1) (varType tv2) ReflCastCo
|
|
| 1650 | + = do { unify_ty env (varType tv1) (varType tv2) (mkNomReflCo liftedTypeKind)
|
|
| 1652 | 1651 | ; let env' = umRnBndr2 env tv1 tv2
|
| 1653 | 1652 | ; unify_ty env' ty1 ty2 kco }
|
| 1654 | 1653 | |
| ... | ... | @@ -1659,7 +1658,7 @@ unify_ty env (CoercionTy co1) (CoercionTy co2) kco |
| 1659 | 1658 | CoVarCo cv
|
| 1660 | 1659 | | not (um_unif env)
|
| 1661 | 1660 | , not (cv `elemVarEnv` c_subst) -- Not forall-bound
|
| 1662 | - , let (_mult_co, co_l, co_r) = decomposeFunCo (castCoToCo (typeKind (CoercionTy co1)) kco)
|
|
| 1661 | + , let (_mult_co, co_l, co_r) = decomposeFunCo kco
|
|
| 1663 | 1662 | -- Because the coercion is used in a type, it should be safe to
|
| 1664 | 1663 | -- ignore the multiplicity coercion, _mult_co
|
| 1665 | 1664 | -- cv :: t1 ~ t2
|
| ... | ... | @@ -1679,7 +1678,7 @@ unify_ty env (TyVarTy tv1) ty2 kco |
| 1679 | 1678 | |
| 1680 | 1679 | unify_ty env ty1 (TyVarTy tv2) kco
|
| 1681 | 1680 | | um_unif env -- If unifying, can swap args; but not when matching
|
| 1682 | - = uVarOrFam (umSwapRn env) (TyVarLHS tv2) ty1 (mkSymCastCo (typeKind ty1) kco)
|
|
| 1681 | + = uVarOrFam (umSwapRn env) (TyVarLHS tv2) ty1 (mkSymCo kco)
|
|
| 1683 | 1682 | |
| 1684 | 1683 | -- Deal with TyConApps
|
| 1685 | 1684 | unify_ty env ty1 ty2 kco
|
| ... | ... | @@ -1690,7 +1689,7 @@ unify_ty env ty1 ty2 kco |
| 1690 | 1689 | |
| 1691 | 1690 | | um_unif env
|
| 1692 | 1691 | , Just (tc,tys) <- mb_sat_fam_app2
|
| 1693 | - = uVarOrFam (umSwapRn env) (TyFamLHS tc tys) ty1 (mkSymCastCo (typeKind ty1) kco)
|
|
| 1692 | + = uVarOrFam (umSwapRn env) (TyFamLHS tc tys) ty1 (mkSymCo kco)
|
|
| 1694 | 1693 | |
| 1695 | 1694 | -- Handle oversaturated type families. Suppose we have
|
| 1696 | 1695 | -- (F a b) ~ (c d) where F has arity 1
|
| ... | ... | @@ -1761,8 +1760,8 @@ unify_ty_app env ty1 ty1args ty2 ty2args |
| 1761 | 1760 | = do { let ki1 = typeKind ty1
|
| 1762 | 1761 | ki2 = typeKind ty2
|
| 1763 | 1762 | -- See Note [Kind coercions in Unify]
|
| 1764 | - ; unify_ty env ki1 ki2 ReflCastCo
|
|
| 1765 | - ; unify_ty env ty1 ty2 ReflCastCo -- TODO: simplify following comment?
|
|
| 1763 | + ; unify_ty env ki1 ki2 (mkNomReflCo liftedTypeKind)
|
|
| 1764 | + ; unify_ty env ty1 ty2 (mkNomReflCo ki2)
|
|
| 1766 | 1765 | -- Very important: 'ki2' not 'ki1'
|
| 1767 | 1766 | -- See Note [Matching in the presence of casts (2)]
|
| 1768 | 1767 | ; unify_tys env ty1args ty2args }
|
| ... | ... | @@ -1776,7 +1775,7 @@ unify_tys env orig_xs orig_ys |
| 1776 | 1775 | go [] [] = return ()
|
| 1777 | 1776 | go (x:xs) (y:ys)
|
| 1778 | 1777 | -- See Note [Kind coercions in Unify]
|
| 1779 | - = do { unify_ty env x y ReflCastCo -- TODO: simplify following comment?
|
|
| 1778 | + = do { unify_ty env x y (mkNomReflCo $ typeKind y)
|
|
| 1780 | 1779 | -- Very important: 'y' not 'x'
|
| 1781 | 1780 | -- See Note [Matching in the presence of casts (2)]
|
| 1782 | 1781 | ; go xs ys }
|
| ... | ... | @@ -1785,7 +1784,7 @@ unify_tys env orig_xs orig_ys |
| 1785 | 1784 | -- See Note [Polykinded tycon applications]
|
| 1786 | 1785 | |
| 1787 | 1786 | ---------------------------------
|
| 1788 | -uVarOrFam :: UMEnv -> CanEqLHS -> InType -> OutCastCoercion -> UM ()
|
|
| 1787 | +uVarOrFam :: UMEnv -> CanEqLHS -> InType -> OutCoercion -> UM ()
|
|
| 1789 | 1788 | -- Invariants: (a) If ty1 is a TyFamLHS, then ty2 is NOT a TyVarTy
|
| 1790 | 1789 | -- (b) both args have had coreView already applied
|
| 1791 | 1790 | -- Why saturated? See (ATF4) in Note [Apartness and type families]
|
| ... | ... | @@ -1812,7 +1811,7 @@ uVarOrFam env ty1 ty2 kco |
| 1812 | 1811 | -----------------------------
|
| 1813 | 1812 | -- LHS is a type variable
|
| 1814 | 1813 | -- The sequence of tests is very similar to go_tv
|
| 1815 | - go :: SwapFlag -> UMState -> CanEqLHS -> InType -> OutCastCoercion -> UM ()
|
|
| 1814 | + go :: SwapFlag -> UMState -> CanEqLHS -> InType -> OutCoercion -> UM ()
|
|
| 1816 | 1815 | go swapped substs lhs@(TyVarLHS tv1) ty2 kco
|
| 1817 | 1816 | | Just ty1' <- lookupVarEnv (um_tv_env substs) tv1'
|
| 1818 | 1817 | = -- We already have a substitution for tv1
|
| ... | ... | @@ -1857,7 +1856,7 @@ uVarOrFam env ty1 ty2 kco |
| 1857 | 1856 | | um_unif env
|
| 1858 | 1857 | , NotSwapped <- swapped -- If we have swapped already, don't do so again
|
| 1859 | 1858 | , Just lhs2 <- canEqLHS_maybe ty2
|
| 1860 | - = go IsSwapped substs lhs2 (mkTyVarTy tv1) (mkSymCastCo (varType tv1) kco)
|
|
| 1859 | + = go IsSwapped substs lhs2 (mkTyVarTy tv1) (mkSymCo kco)
|
|
| 1861 | 1860 | |
| 1862 | 1861 | | occurs_check = maybeApart MARInfinite -- Occurs check
|
| 1863 | 1862 | | otherwise = surelyApart
|
| ... | ... | @@ -1865,7 +1864,7 @@ uVarOrFam env ty1 ty2 kco |
| 1865 | 1864 | where
|
| 1866 | 1865 | tv1' = umRnOccL env tv1
|
| 1867 | 1866 | ty2_fvs = tyCoVarsOfType ty2
|
| 1868 | - rhs = ty2 `mkCastTy` mkSymCastCo (varType tv1') kco
|
|
| 1867 | + rhs = ty2 `mkCastTy` mkSymCo kco
|
|
| 1869 | 1868 | tv1_is_bindable | not (tv1' `elemVarSet` foralld_tvs)
|
| 1870 | 1869 | -- tv1' is not forall-bound, but tv1 can still differ
|
| 1871 | 1870 | -- from tv1; see Note [Cloning the template binders]
|
| ... | ... | @@ -1929,14 +1928,13 @@ uVarOrFam env ty1 ty2 kco |
| 1929 | 1928 | | um_unif env
|
| 1930 | 1929 | , NotSwapped <- swapped
|
| 1931 | 1930 | , Just lhs2 <- canEqLHS_maybe ty2
|
| 1932 | - , let ty1' = mkTyConApp tc1 tys1
|
|
| 1933 | - = go IsSwapped substs lhs2 ty1' (mkSymCastCo (typeKind ty1') kco)
|
|
| 1931 | + = go IsSwapped substs lhs2 (mkTyConApp tc1 tys1) (mkSymCo kco)
|
|
| 1934 | 1932 | |
| 1935 | 1933 | | otherwise -- See (ATF5) in Note [Apartness and type families]
|
| 1936 | 1934 | = surelyApart
|
| 1937 | 1935 | |
| 1938 | 1936 | where
|
| 1939 | - rhs = ty2 `mkCastTy` mkSymCastCo (typeKind (mkTyConApp tc1 tys1)) kco
|
|
| 1937 | + rhs = ty2 `mkCastTy` mkSymCo kco
|
|
| 1940 | 1938 | |
| 1941 | 1939 | -----------------------------
|
| 1942 | 1940 | -- go_fam_fam: LHS and RHS are both saturated type-family applications,
|
| ... | ... | @@ -1973,7 +1971,7 @@ uVarOrFam env ty1 ty2 kco |
| 1973 | 1971 | | otherwise
|
| 1974 | 1972 | = return ()
|
| 1975 | 1973 | |
| 1976 | - rhs1 = mkTyConApp tc tys2 `mkCastTy` mkSymCastCo (typeKind (mkTyConApp tc tys1)) kco -- TODO: correct?
|
|
| 1974 | + rhs1 = mkTyConApp tc tys2 `mkCastTy` mkSymCo kco
|
|
| 1977 | 1975 | rhs2 = mkTyConApp tc tys1 `mkCastTy` kco
|
| 1978 | 1976 | |
| 1979 | 1977 | |
| ... | ... | @@ -2337,10 +2335,9 @@ ty_co_match menv subst ty co lkco rkco |
| 2337 | 2335 | noneSet f = allVarSet (not . f)
|
| 2338 | 2336 | |
| 2339 | 2337 | ty_co_match menv subst ty co lkco rkco
|
| 2340 | - | CastTy ty' cco' <- ty
|
|
| 2338 | + | CastTy ty' co' <- ty
|
|
| 2341 | 2339 | -- See Note [Matching in the presence of casts (1)]
|
| 2342 | 2340 | = let empty_subst = mkEmptySubst (rnInScopeSet (me_env menv))
|
| 2343 | - co' = castCoToCo (typeKind ty') cco'
|
|
| 2344 | 2341 | substed_co_l = substCo (liftEnvSubstLeft empty_subst subst) co'
|
| 2345 | 2342 | substed_co_r = substCo (liftEnvSubstRight empty_subst subst) co'
|
| 2346 | 2343 | in
|
| ... | ... | @@ -2451,7 +2448,7 @@ ty_co_match menv subst ty co1 lkco rkco |
| 2451 | 2448 | -- But transitive coercions are not helpful. Therefore we deal
|
| 2452 | 2449 | -- with it here: we do recursion on the smaller reflexive coercion,
|
| 2453 | 2450 | -- while propagating the correct kind coercions.
|
| 2454 | - = let kco' = mkSymCo (castCoToCo (typeKind t) co)
|
|
| 2451 | + = let kco' = mkSymCo co
|
|
| 2455 | 2452 | in ty_co_match menv subst ty (mkReflCo r t) (lkco `mkTransCo` kco')
|
| 2456 | 2453 | (rkco `mkTransCo` kco')
|
| 2457 | 2454 |
| ... | ... | @@ -192,7 +192,7 @@ toIfaceTypeX fr (ForAllTy b t) = IfaceForAllTy (toIfaceForAllBndrX fr b) |
| 192 | 192 | (toIfaceTypeX (fr `delVarSet` binderVar b) t)
|
| 193 | 193 | toIfaceTypeX fr (FunTy { ft_arg = t1, ft_mult = w, ft_res = t2, ft_af = af })
|
| 194 | 194 | = IfaceFunTy af (toIfaceTypeX fr w) (toIfaceTypeX fr t1) (toIfaceTypeX fr t2)
|
| 195 | -toIfaceTypeX fr (CastTy ty co) = IfaceCastTy (toIfaceTypeX fr ty) (toIfaceCastCoercionX fr co)
|
|
| 195 | +toIfaceTypeX fr (CastTy ty co) = IfaceCastTy (toIfaceTypeX fr ty) (toIfaceCoercionX fr co)
|
|
| 196 | 196 | toIfaceTypeX fr (CoercionTy co) = IfaceCoercionTy (toIfaceCoercionX fr co)
|
| 197 | 197 | |
| 198 | 198 | toIfaceTypeX fr (TyConApp tc tys)
|
| ... | ... | @@ -271,12 +271,9 @@ toIfaceTyLit (CharTyLit x) = IfaceCharTyLit x |
| 271 | 271 | |
| 272 | 272 | ----------------
|
| 273 | 273 | toIfaceCastCoercion :: CastCoercion -> IfaceCastCoercion
|
| 274 | -toIfaceCastCoercion = toIfaceCastCoercionX emptyVarSet
|
|
| 275 | - |
|
| 276 | -toIfaceCastCoercionX :: VarSet -> CastCoercion -> IfaceCastCoercion
|
|
| 277 | -toIfaceCastCoercionX fr (CCoercion co) = IfaceCCoercion (toIfaceCoercionX fr co)
|
|
| 278 | -toIfaceCastCoercionX fr (ZCoercion ty cos) = IfaceZCoercion (toIfaceTypeX fr ty) (map (toIfaceCoercionX fr . CoVarCo) (nonDetEltsUniqSet cos)) -- TODO determinism
|
|
| 279 | -toIfaceCastCoercionX _ ReflCastCo = IfaceReflCastCo
|
|
| 274 | +toIfaceCastCoercion (CCoercion co) = IfaceCCoercion (toIfaceCoercion co)
|
|
| 275 | +toIfaceCastCoercion (ZCoercion ty cos) = IfaceZCoercion (toIfaceType ty) (map (toIfaceCoercion . CoVarCo) (nonDetEltsUniqSet cos)) -- TODO determinism
|
|
| 276 | +toIfaceCastCoercion ReflCastCo = IfaceReflCastCo
|
|
| 280 | 277 | |
| 281 | 278 | toIfaceCoercion :: Coercion -> IfaceCoercion
|
| 282 | 279 | toIfaceCoercion = toIfaceCoercionX emptyVarSet
|
| ... | ... | @@ -748,7 +748,7 @@ mkUnsafeCoercePrimPair _old_id old_expr |
| 748 | 748 | runtimeRep1Ty
|
| 749 | 749 | runtimeRep2Ty
|
| 750 | 750 | (scrut2, scrut2_ty, ab_cv_ty) = unsafe_equality (mkTYPEapp runtimeRep2Ty)
|
| 751 | - (openAlphaTy `mkCastTyCo` alpha_co)
|
|
| 751 | + (openAlphaTy `mkCastTy` alpha_co)
|
|
| 752 | 752 | openBetaTy
|
| 753 | 753 | |
| 754 | 754 | -- alpha_co :: TYPE r1 ~# TYPE r2
|
| ... | ... | @@ -947,7 +947,7 @@ rnIfaceType (IfaceForAllTy tv t) |
| 947 | 947 | rnIfaceType (IfaceCoercionTy co)
|
| 948 | 948 | = IfaceCoercionTy <$> rnIfaceCo co
|
| 949 | 949 | rnIfaceType (IfaceCastTy ty co)
|
| 950 | - = IfaceCastTy <$> rnIfaceType ty <*> rnIfaceCastCo co
|
|
| 950 | + = IfaceCastTy <$> rnIfaceType ty <*> rnIfaceCo co
|
|
| 951 | 951 | |
| 952 | 952 | rnIfaceScaledType :: Rename (IfaceMult, IfaceType)
|
| 953 | 953 | rnIfaceScaledType (m, t) = (,) <$> rnIfaceType m <*> rnIfaceType t
|
| ... | ... | @@ -2067,7 +2067,7 @@ freeNamesIfType (IfaceTupleTy _ _ ts) = freeNamesIfAppArgs ts |
| 2067 | 2067 | freeNamesIfType (IfaceLitTy _) = emptyNameSet
|
| 2068 | 2068 | freeNamesIfType (IfaceForAllTy tv t) = freeNamesIfVarBndr tv &&& freeNamesIfType t
|
| 2069 | 2069 | freeNamesIfType (IfaceFunTy _ w s t) = freeNamesIfType s &&& freeNamesIfType t &&& freeNamesIfType w
|
| 2070 | -freeNamesIfType (IfaceCastTy t c) = freeNamesIfType t &&& freeNamesIfCastCoercion c
|
|
| 2070 | +freeNamesIfType (IfaceCastTy t c) = freeNamesIfType t &&& freeNamesIfCoercion c
|
|
| 2071 | 2071 | freeNamesIfType (IfaceCoercionTy c) = freeNamesIfCoercion c
|
| 2072 | 2072 | |
| 2073 | 2073 | freeNamesIfMCoercion :: IfaceMCoercion -> NameSet
|
| ... | ... | @@ -190,7 +190,7 @@ data IfaceType |
| 190 | 190 | | IfaceForAllTy IfaceForAllBndr IfaceType
|
| 191 | 191 | | IfaceTyConApp IfaceTyCon IfaceAppArgs -- Not necessarily saturated
|
| 192 | 192 | -- Includes newtypes, synonyms, tuples
|
| 193 | - | IfaceCastTy IfaceType IfaceCastCoercion
|
|
| 193 | + | IfaceCastTy IfaceType IfaceCoercion
|
|
| 194 | 194 | | IfaceCoercionTy IfaceCoercion
|
| 195 | 195 | |
| 196 | 196 | | IfaceTupleTy -- Saturated tuples (unsaturated ones use IfaceTyConApp)
|
| ... | ... | @@ -776,16 +776,12 @@ substIfaceType env ty |
| 776 | 776 | go (IfaceTyConApp tc tys) = IfaceTyConApp tc (substIfaceAppArgs env tys)
|
| 777 | 777 | go (IfaceTupleTy s i tys) = IfaceTupleTy s i (substIfaceAppArgs env tys)
|
| 778 | 778 | go (IfaceForAllTy {}) = pprPanic "substIfaceType" (ppr ty)
|
| 779 | - go (IfaceCastTy ty co) = IfaceCastTy (go ty) (go_cast_co co)
|
|
| 779 | + go (IfaceCastTy ty co) = IfaceCastTy (go ty) (go_co co)
|
|
| 780 | 780 | go (IfaceCoercionTy co) = IfaceCoercionTy (go_co co)
|
| 781 | 781 | |
| 782 | 782 | go_mco IfaceMRefl = IfaceMRefl
|
| 783 | 783 | go_mco (IfaceMCo co) = IfaceMCo $ go_co co
|
| 784 | 784 | |
| 785 | - go_cast_co IfaceReflCastCo = IfaceReflCastCo
|
|
| 786 | - go_cast_co (IfaceCCoercion co) = IfaceCCoercion (go_co co)
|
|
| 787 | - go_cast_co (IfaceZCoercion ty cos) = IfaceZCoercion (go ty) (map go_co cos)
|
|
| 788 | - |
|
| 789 | 785 | go_co (IfaceReflCo ty) = IfaceReflCo (go ty)
|
| 790 | 786 | go_co (IfaceGReflCo r ty mco) = IfaceGReflCo r (go ty) (go_mco mco)
|
| 791 | 787 | go_co (IfaceFunCo r w c1 c2) = IfaceFunCo r (go_co w) (go_co c1) (go_co c2)
|
| ... | ... | @@ -2195,9 +2191,6 @@ pprPromotionQuoteI IsPromoted = char '\'' |
| 2195 | 2191 | instance Outputable IfaceCoercion where
|
| 2196 | 2192 | ppr = pprIfaceCoercion
|
| 2197 | 2193 | |
| 2198 | -instance Outputable IfaceCastCoercion where
|
|
| 2199 | - ppr = pprIfaceCastCoercion
|
|
| 2200 | - |
|
| 2201 | 2194 | instance Binary IfaceTyCon where
|
| 2202 | 2195 | put_ bh (IfaceTyCon n i) = put_ bh n >> put_ bh i
|
| 2203 | 2196 |
| ... | ... | @@ -1527,7 +1527,7 @@ tcIfaceType = go |
| 1527 | 1527 | go (IfaceForAllTy bndr t)
|
| 1528 | 1528 | = bindIfaceForAllBndr bndr $ \ tv' vis ->
|
| 1529 | 1529 | ForAllTy (Bndr tv' vis) <$> go t
|
| 1530 | - go (IfaceCastTy ty co) = CastTy <$> go ty <*> tcIfaceCastCoercion co
|
|
| 1530 | + go (IfaceCastTy ty co) = CastTy <$> go ty <*> tcIfaceCo co
|
|
| 1531 | 1531 | go (IfaceCoercionTy co) = CoercionTy <$> tcIfaceCo co
|
| 1532 | 1532 | |
| 1533 | 1533 | tcIfaceTupleTy :: TupleSort -> PromotionFlag -> IfaceAppArgs -> IfL Type
|
| ... | ... | @@ -813,7 +813,7 @@ tcInstFun do_ql inst_final (tc_fun, fun_ctxt) fun_sigma rn_args |
| 813 | 813 | -- NB: kappa is uninstantiated ('go' already checked that)
|
| 814 | 814 | ; kind_co <- unifyKind Nothing liftedTypeKind (tyVarKind kappa)
|
| 815 | 815 | -- unifyKind: see (UQL3) in Note [QuickLook unification]
|
| 816 | - ; liftZonkM (writeMetaTyVar kappa (mkCastTyCo fun_ty' kind_co))
|
|
| 816 | + ; liftZonkM (writeMetaTyVar kappa (mkCastTy fun_ty' kind_co))
|
|
| 817 | 817 | |
| 818 | 818 | ; let co_wrap = mkWpCastN (mkGReflLeftCo Nominal fun_ty' kind_co)
|
| 819 | 819 | acc' = addArgWrap co_wrap acc
|
| ... | ... | @@ -2225,7 +2225,7 @@ qlUnify ty1 ty2 |
| 2225 | 2225 | do { co <- unifyKind (Just (TypeThing ty2)) ty2_kind kappa_kind
|
| 2226 | 2226 | -- unifyKind: see (UQL2) in Note [QuickLook unification]
|
| 2227 | 2227 | -- and (MIV2) in Note [Monomorphise instantiation variables]
|
| 2228 | - ; let ty2' = mkCastTyCo ty2 co
|
|
| 2228 | + ; let ty2' = mkCastTy ty2 co
|
|
| 2229 | 2229 | ; traceTc "qlUnify:update" $
|
| 2230 | 2230 | ppr kappa <+> text ":=" <+> ppr ty2
|
| 2231 | 2231 | ; liftZonkM $ writeMetaTyVar kappa ty2' }
|
| ... | ... | @@ -58,7 +58,7 @@ import GHC.Core.Reduction ( Reduction(..) ) |
| 58 | 58 | import GHC.Core.Multiplicity
|
| 59 | 59 | import GHC.Core.FamInstEnv( normaliseType )
|
| 60 | 60 | import GHC.Core.Class ( Class )
|
| 61 | -import GHC.Core.Coercion( mkSymCastCo )
|
|
| 61 | +import GHC.Core.Coercion( mkSymCo )
|
|
| 62 | 62 | import GHC.Core.Type (mkStrLitTy, mkCastTy)
|
| 63 | 63 | import GHC.Core.TyCo.Ppr( pprTyVars )
|
| 64 | 64 | import GHC.Core.TyCo.Tidy( tidyOpenTypeX )
|
| ... | ... | @@ -1093,7 +1093,7 @@ chooseInferredQuantifiers residual inferred_theta tau_tvs qtvs |
| 1093 | 1093 | -- So, to make the kinds work out, we reverse the cast here.
|
| 1094 | 1094 | Just (wc_var, wc_co) -> liftZonkM $
|
| 1095 | 1095 | writeMetaTyVar wc_var (mkConstraintTupleTy diff_theta
|
| 1096 | - `mkCastTy` mkSymCastCo (varType wc_var) wc_co)
|
|
| 1096 | + `mkCastTy` mkSymCo wc_co)
|
|
| 1097 | 1097 | Nothing -> pprPanic "chooseInferredQuantifiers 1" (ppr wc_var_ty)
|
| 1098 | 1098 | |
| 1099 | 1099 | ; traceTc "completeTheta" $
|
| ... | ... | @@ -1696,7 +1696,7 @@ tcInferTyApps_nosat mode orig_hs_ty fun orig_hs_args |
| 1696 | 1696 | do { let arrows_needed = n_initial_val_args all_args
|
| 1697 | 1697 | ; co <- matchExpectedFunKind (HsTypeRnThing $ unLoc hs_ty) arrows_needed substed_fun_ki
|
| 1698 | 1698 | |
| 1699 | - ; fun' <- liftZonkM $ zonkTcType (fun `mkCastTyCo` co)
|
|
| 1699 | + ; fun' <- liftZonkM $ zonkTcType (fun `mkCastTy` co)
|
|
| 1700 | 1700 | -- This zonk is essential, to expose the fruits
|
| 1701 | 1701 | -- of matchExpectedFunKind to the 'go' loop
|
| 1702 | 1702 | |
| ... | ... | @@ -1963,7 +1963,7 @@ checkExpectedKind hs_ty ty act_kind exp_kind |
| 1963 | 1963 | ; traceTc "checkExpectedKind" (vcat [ ppr act_kind
|
| 1964 | 1964 | , ppr exp_kind
|
| 1965 | 1965 | , ppr co_k ])
|
| 1966 | - ; return (res_ty `mkCastTyCo` co_k) } }
|
|
| 1966 | + ; return (res_ty `mkCastTy` co_k) } }
|
|
| 1967 | 1967 | where
|
| 1968 | 1968 | -- We need to make sure that both kinds have the same number of implicit
|
| 1969 | 1969 | -- foralls and constraints out front. If the actual kind has more, instantiate
|
| ... | ... | @@ -1986,7 +1986,7 @@ checkExpKind _rn_ty ty ki (Infer cell) = do |
| 1986 | 1986 | -- NB: do not instantiate.
|
| 1987 | 1987 | -- See Note [Do not always instantiate eagerly in types]
|
| 1988 | 1988 | co <- fillInferResultNoInst ki cell
|
| 1989 | - pure (ty `mkCastTyCo` co)
|
|
| 1989 | + pure (ty `mkCastTy` co)
|
|
| 1990 | 1990 | |
| 1991 | 1991 | ---------------------------
|
| 1992 | 1992 |
| ... | ... | @@ -359,11 +359,11 @@ can_eq_nc _rewritten rdr_env envs ev eq_rel ty1 ps_ty1 ty2 ps_ty2 |
| 359 | 359 | can_eq_nc rewritten rdr_env envs ev eq_rel (CastTy ty1 co1) _ ty2 ps_ty2
|
| 360 | 360 | | isNothing (canEqLHS_maybe ty2)
|
| 361 | 361 | = -- See (EIK3) in Note [Equalities with heterogeneous kinds]
|
| 362 | - canEqCast rewritten rdr_env envs ev eq_rel NotSwapped ty1 (castCoToCo (typeKind ty1) co1) ty2 ps_ty2
|
|
| 362 | + canEqCast rewritten rdr_env envs ev eq_rel NotSwapped ty1 co1 ty2 ps_ty2
|
|
| 363 | 363 | can_eq_nc rewritten rdr_env envs ev eq_rel ty1 ps_ty1 (CastTy ty2 co2) _
|
| 364 | 364 | | isNothing (canEqLHS_maybe ty1)
|
| 365 | 365 | = -- See (EIK3) in Note [Equalities with heterogeneous kinds]
|
| 366 | - canEqCast rewritten rdr_env envs ev eq_rel IsSwapped ty2 (castCoToCo (typeKind ty2) co2) ty1 ps_ty1
|
|
| 366 | + canEqCast rewritten rdr_env envs ev eq_rel IsSwapped ty2 co2 ty1 ps_ty1
|
|
| 367 | 367 | |
| 368 | 368 | ----------------------
|
| 369 | 369 | -- Otherwise try to decompose
|
| ... | ... | @@ -522,7 +522,7 @@ can_eq_nc_forall ev eq_rel s1 s2 |
| 522 | 522 | (substTy subst2 (tyVarKind tv2))
|
| 523 | 523 | |
| 524 | 524 | ; let subst2' = extendTvSubstAndInScope subst2 tv2
|
| 525 | - (mkCastTyCo (mkTyVarTy skol_tv) kind_co)
|
|
| 525 | + (mkCastTy (mkTyVarTy skol_tv) kind_co)
|
|
| 526 | 526 | -- skol_tv is already in the in-scope set, but the
|
| 527 | 527 | -- free vars of kind_co are not; hence "...AndInScope"
|
| 528 | 528 | ; co <- go uenv skol_tvs subst2' bndrs1 bndrs2
|
| ... | ... | @@ -1741,7 +1741,7 @@ canEqCanLHSHetero ev eq_rel swapped lhs1 ps_xi1 ki1 xi2 ps_xi2 ki2 |
| 1741 | 1741 | -- kind_co :: ki2 ~N ki1
|
| 1742 | 1742 | lhs_redn = mkReflRedn role ps_xi1
|
| 1743 | 1743 | rhs_redn = mkGReflRightRedn role xi2 kind_co
|
| 1744 | - new_xi2 = mkCastTyCo ps_xi2 kind_co
|
|
| 1744 | + new_xi2 = mkCastTy ps_xi2 kind_co
|
|
| 1745 | 1745 | |
| 1746 | 1746 | canEqCanLHSHomo :: CtEvidence -- lhs ~ rhs
|
| 1747 | 1747 | -- or, if swapped: rhs ~ lhs
|
| ... | ... | @@ -1753,14 +1753,14 @@ canEqCanLHSHomo :: CtEvidence -- lhs ~ rhs |
| 1753 | 1753 | canEqCanLHSHomo ev eq_rel swapped lhs1 ps_xi1 xi2 ps_xi2
|
| 1754 | 1754 | | (xi2', mco) <- split_cast_ty xi2
|
| 1755 | 1755 | , Just lhs2 <- canEqLHS_maybe xi2'
|
| 1756 | - = canEqCanLHS2 ev eq_rel swapped lhs1 ps_xi1 lhs2 (ps_xi2 `mkCastTy` mkSymCastCo (typeKind xi2') mco) mco
|
|
| 1756 | + = canEqCanLHS2 ev eq_rel swapped lhs1 ps_xi1 lhs2 (ps_xi2 `mkCastTyMCo` mkSymMCo mco) mco
|
|
| 1757 | 1757 | |
| 1758 | 1758 | | otherwise
|
| 1759 | 1759 | = canEqCanLHSFinish ev eq_rel swapped lhs1 ps_xi2
|
| 1760 | 1760 | |
| 1761 | 1761 | where
|
| 1762 | - split_cast_ty (CastTy ty co) = (ty, co)
|
|
| 1763 | - split_cast_ty other = (other, ReflCastCo)
|
|
| 1762 | + split_cast_ty (CastTy ty co) = (ty, MCo co)
|
|
| 1763 | + split_cast_ty other = (other, MRefl)
|
|
| 1764 | 1764 | |
| 1765 | 1765 | -- This function deals with the case that both LHS and RHS are potential
|
| 1766 | 1766 | -- CanEqLHSs.
|
| ... | ... | @@ -1771,7 +1771,7 @@ canEqCanLHS2 :: CtEvidence -- lhs ~ (rhs |> mco) |
| 1771 | 1771 | -> TcType -- pretty lhs
|
| 1772 | 1772 | -> CanEqLHS -- rhs
|
| 1773 | 1773 | -> TcType -- pretty rhs
|
| 1774 | - -> CastCoercion -- :: kind(rhs) ~N kind(lhs)
|
|
| 1774 | + -> MCoercion -- :: kind(rhs) ~N kind(lhs)
|
|
| 1775 | 1775 | -> TcS (StopOrContinue (Either IrredCt EqCt))
|
| 1776 | 1776 | canEqCanLHS2 ev eq_rel swapped lhs1 ps_xi1 lhs2 ps_xi2 mco
|
| 1777 | 1777 | | lhs1 `eqCanEqLHS` lhs2
|
| ... | ... | @@ -1823,13 +1823,13 @@ canEqCanLHS2 ev eq_rel swapped lhs1 ps_xi1 lhs2 ps_xi2 mco |
| 1823 | 1823 | then finish_with_swapping
|
| 1824 | 1824 | else finish_without_swapping }
|
| 1825 | 1825 | where
|
| 1826 | - sym_mco = mkSymCastCo (canEqLHSKind lhs2) mco
|
|
| 1826 | + sym_mco = mkSymMCo mco
|
|
| 1827 | 1827 | role = eqRelRole eq_rel
|
| 1828 | 1828 | lhs1_ty = canEqLHSType lhs1
|
| 1829 | 1829 | lhs2_ty = canEqLHSType lhs2
|
| 1830 | 1830 | |
| 1831 | 1831 | finish_without_swapping
|
| 1832 | - = canEqCanLHSFinish ev eq_rel swapped lhs1 (ps_xi2 `mkCastTy` mco)
|
|
| 1832 | + = canEqCanLHSFinish ev eq_rel swapped lhs1 (ps_xi2 `mkCastTyMCo` mco)
|
|
| 1833 | 1833 | |
| 1834 | 1834 | -- Swapping. We have ev : lhs1 ~ lhs2 |> co
|
| 1835 | 1835 | -- We swap to new_ev : lhs2 ~ lhs1 |> sym co
|
| ... | ... | @@ -1840,7 +1840,7 @@ canEqCanLHS2 ev eq_rel swapped lhs1 ps_xi1 lhs2 ps_xi2 mco |
| 1840 | 1840 | = do { let lhs1_redn = mkGReflRightMRedn role lhs1_ty sym_mco
|
| 1841 | 1841 | lhs2_redn = mkGReflLeftMRedn role lhs2_ty mco
|
| 1842 | 1842 | ; new_ev <-rewriteEqEvidence ev swapped lhs1_redn lhs2_redn emptyCoHoleSet
|
| 1843 | - ; canEqCanLHSFinish new_ev eq_rel IsSwapped lhs2 (ps_xi1 `mkCastTy` sym_mco) }
|
|
| 1843 | + ; canEqCanLHSFinish new_ev eq_rel IsSwapped lhs2 (ps_xi1 `mkCastTyMCo` sym_mco) }
|
|
| 1844 | 1844 | |
| 1845 | 1845 | put_tyvar_on_lhs = isWanted ev && eq_rel == NomEq
|
| 1846 | 1846 | -- See Note [Orienting TyVarLHS/TyFamLHS]
|
| ... | ... | @@ -561,9 +561,8 @@ rewrite_one ty@(ForAllTy {}) |
| 561 | 561 | ; redn <- rewrite_one rho
|
| 562 | 562 | ; return $ mkHomoForAllRedn bndrs redn }
|
| 563 | 563 | |
| 564 | -rewrite_one (CastTy ty cco)
|
|
| 564 | +rewrite_one (CastTy ty g)
|
|
| 565 | 565 | = do { redn <- rewrite_one ty
|
| 566 | - ; let g = castCoToCo (typeKind ty) cco
|
|
| 567 | 566 | ; g' <- rewrite_co g
|
| 568 | 567 | ; role <- getRole
|
| 569 | 568 | ; return $ mkCastRedn1 role ty g' redn }
|
| ... | ... | @@ -37,7 +37,7 @@ import GHC.Builtin.Uniques ( mkBuiltinUnique ) |
| 37 | 37 | |
| 38 | 38 | import GHC.Hs
|
| 39 | 39 | |
| 40 | -import GHC.Core.TyCo.Rep( Type(..), Coercion(..), MCoercion(..), CastCoercion(..) )
|
|
| 40 | +import GHC.Core.TyCo.Rep( Type(..), Coercion(..), MCoercion(..) )
|
|
| 41 | 41 | import GHC.Core.Multiplicity
|
| 42 | 42 | import GHC.Core.Predicate
|
| 43 | 43 | import GHC.Core.Make( rEC_SEL_ERROR_ID )
|
| ... | ... | @@ -101,7 +101,7 @@ synonymTyConsOfType ty |
| 101 | 101 | go (AppTy a b) = go a `plusNameEnv` go b
|
| 102 | 102 | go (FunTy _ w a b) = go w `plusNameEnv` go a `plusNameEnv` go b
|
| 103 | 103 | go (ForAllTy _ ty) = go ty
|
| 104 | - go (CastTy ty co) = go ty `plusNameEnv` go_cast_co co
|
|
| 104 | + go (CastTy ty co) = go ty `plusNameEnv` go_co co
|
|
| 105 | 105 | go (CoercionTy co) = go_co co
|
| 106 | 106 | |
| 107 | 107 | -- Note [TyCon cycles through coercions?!]
|
| ... | ... | @@ -128,10 +128,6 @@ synonymTyConsOfType ty |
| 128 | 128 | go_mco MRefl = emptyNameEnv
|
| 129 | 129 | go_mco (MCo co) = go_co co
|
| 130 | 130 | |
| 131 | - go_cast_co ReflCastCo = emptyNameEnv
|
|
| 132 | - go_cast_co (CCoercion co) = go_co co
|
|
| 133 | - go_cast_co (ZCoercion ty _) = go ty
|
|
| 134 | - |
|
| 135 | 131 | go_co (Refl ty) = go ty
|
| 136 | 132 | go_co (GRefl _ ty mco) = go ty `plusNameEnv` go_mco mco
|
| 137 | 133 | go_co (TyConAppCo _ tc cs) = go_tc tc `plusNameEnv` go_co_s cs
|
| ... | ... | @@ -331,7 +331,7 @@ instTyVarsWith orig tvs tys |
| 331 | 331 | = go (extendTvSubstAndInScope subst tv ty) tvs tys
|
| 332 | 332 | | otherwise
|
| 333 | 333 | = do { co <- emitWantedEq orig KindLevel Nominal ty_kind tv_kind
|
| 334 | - ; go (extendTvSubstAndInScope subst tv (ty `mkCastTyCo` co)) tvs tys }
|
|
| 334 | + ; go (extendTvSubstAndInScope subst tv (ty `mkCastTy` co)) tvs tys }
|
|
| 335 | 335 | where
|
| 336 | 336 | tv_kind = substTy subst (tyVarKind tv)
|
| 337 | 337 | ty_kind = typeKind ty
|
| ... | ... | @@ -1435,7 +1435,7 @@ collect_cand_qtvs orig_ty is_dep cur_lvl bound dvs ty |
| 1435 | 1435 | go dv (FunTy _ w arg res) = foldlM go dv [w, arg, res]
|
| 1436 | 1436 | go dv (LitTy {}) = return dv
|
| 1437 | 1437 | go dv (CastTy ty co) = do { dv1 <- go dv ty
|
| 1438 | - ; collect_cand_qtvs_cast_co orig_ty cur_lvl bound dv1 co }
|
|
| 1438 | + ; collect_cand_qtvs_co orig_ty cur_lvl bound dv1 co }
|
|
| 1439 | 1439 | go dv (CoercionTy co) = collect_cand_qtvs_co orig_ty cur_lvl bound dv co
|
| 1440 | 1440 | |
| 1441 | 1441 | go dv (TyVarTy tv)
|
| ... | ... | @@ -1516,18 +1516,6 @@ collect_cand_qtvs orig_ty is_dep cur_lvl bound dvs ty |
| 1516 | 1516 | -- See Note [Recurring into kinds for candidateQTyVars]
|
| 1517 | 1517 | ; collect_cand_qtvs orig_ty True cur_lvl bound dv' tv_kind } }
|
| 1518 | 1518 | |
| 1519 | -collect_cand_qtvs_cast_co :: TcType -- original type at top of recursion; for errors
|
|
| 1520 | - -> TcLevel
|
|
| 1521 | - -> VarSet -- bound variables
|
|
| 1522 | - -> CandidatesQTvs -> CastCoercion
|
|
| 1523 | - -> TcM CandidatesQTvs
|
|
| 1524 | -collect_cand_qtvs_cast_co orig_ty cur_lvl bound dv cco = case cco of
|
|
| 1525 | - ReflCastCo -> return dv
|
|
| 1526 | - CCoercion co -> collect_cand_qtvs_co orig_ty cur_lvl bound dv co
|
|
| 1527 | - ZCoercion ty cos -> do { dv1 <- collect_cand_qtvs orig_ty True cur_lvl bound dv ty
|
|
| 1528 | - ; foldM (\dv cv -> collect_cand_qtvs_co orig_ty cur_lvl bound dv (CoVarCo cv)) dv1 (nonDetEltsUniqSet cos) -- TODO
|
|
| 1529 | - }
|
|
| 1530 | - |
|
| 1531 | 1519 | collect_cand_qtvs_co :: TcType -- original type at top of recursion; for errors
|
| 1532 | 1520 | -> TcLevel
|
| 1533 | 1521 | -> VarSet -- bound variables
|
| ... | ... | @@ -2696,11 +2696,11 @@ uType env@(UE { u_role = role }) orig_ty1 orig_ty2 |
| 2696 | 2696 | -- didn't do it this way, and then the unification above was deferred.
|
| 2697 | 2697 | go (CastTy t1 co1) t2
|
| 2698 | 2698 | = do { co_tys <- uType env t1 t2
|
| 2699 | - ; return (mkCoherenceLeftCo role t1 (castCoToCo (typeKind t1) co1) co_tys) }
|
|
| 2699 | + ; return (mkCoherenceLeftCo role t1 co1 co_tys) }
|
|
| 2700 | 2700 | |
| 2701 | 2701 | go t1 (CastTy t2 co2)
|
| 2702 | 2702 | = do { co_tys <- uType env t1 t2
|
| 2703 | - ; return (mkCoherenceRightCo role t2 (castCoToCo (typeKind t2) co2) co_tys) }
|
|
| 2703 | + ; return (mkCoherenceRightCo role t2 co2 co_tys) }
|
|
| 2704 | 2704 | |
| 2705 | 2705 | -- Variables; go for uUnfilledVar
|
| 2706 | 2706 | -- Note that we pass in *original* (before synonym expansion),
|
| ... | ... | @@ -3484,7 +3484,7 @@ simpleUnifyCheck caller given_eq_lvl lhs_tv rhs |
| 3484 | 3484 | where
|
| 3485 | 3485 | lhs_info = metaTyVarInfo lhs_tv
|
| 3486 | 3486 | |
| 3487 | - !(occ_in_ty, occ_in_co, occ_in_cast_co) = mkOccFolders (tyVarName lhs_tv)
|
|
| 3487 | + !(occ_in_ty, occ_in_co) = mkOccFolders (tyVarName lhs_tv)
|
|
| 3488 | 3488 | |
| 3489 | 3489 | lhs_tv_lvl = tcTyVarLevel lhs_tv
|
| 3490 | 3490 | lhs_tv_is_concrete = isConcreteTyVar lhs_tv
|
| ... | ... | @@ -3525,17 +3525,17 @@ simpleUnifyCheck caller given_eq_lvl lhs_tv rhs |
| 3525 | 3525 | | otherwise = False
|
| 3526 | 3526 | |
| 3527 | 3527 | rhs_is_ok (AppTy t1 t2) = rhs_is_ok t1 && rhs_is_ok t2
|
| 3528 | - rhs_is_ok (CastTy ty co) = not (occ_in_cast_co co) && rhs_is_ok ty
|
|
| 3528 | + rhs_is_ok (CastTy ty co) = not (occ_in_co co) && rhs_is_ok ty
|
|
| 3529 | 3529 | rhs_is_ok (CoercionTy co) = not (occ_in_co co)
|
| 3530 | 3530 | rhs_is_ok (LitTy {}) = True
|
| 3531 | 3531 | |
| 3532 | 3532 | |
| 3533 | -mkOccFolders :: Name -> (TcType -> Bool, TcCoercion -> Bool, TcCastCoercion -> Bool)
|
|
| 3533 | +mkOccFolders :: Name -> (TcType -> Bool, TcCoercion -> Bool)
|
|
| 3534 | 3534 | -- These functions return True
|
| 3535 | 3535 | -- * if lhs_tv occurs (incl deeply, in the kind of variable)
|
| 3536 | 3536 | -- * if there is a coercion hole
|
| 3537 | 3537 | -- No expansion of type synonyms
|
| 3538 | -mkOccFolders lhs_tv = (getAny . check_ty, getAny . check_co, getAny . check_cast_co)
|
|
| 3538 | +mkOccFolders lhs_tv = (getAny . check_ty, getAny . check_co)
|
|
| 3539 | 3539 | where
|
| 3540 | 3540 | !(check_ty, _, check_co, _) = foldTyCo occ_folder emptyVarSet
|
| 3541 | 3541 | occ_folder = TyCoFolder { tcf_view = noView -- Don't expand synonyms
|
| ... | ... | @@ -3549,11 +3549,6 @@ mkOccFolders lhs_tv = (getAny . check_ty, getAny . check_co, getAny . check_cast |
| 3549 | 3549 | do_bndr is tcv _faf = extendVarSet is tcv
|
| 3550 | 3550 | do_hole _is _hole = DM.Any True -- Reject coercion holes
|
| 3551 | 3551 | |
| 3552 | - check_cast_co ReflCastCo = Any False
|
|
| 3553 | - check_cast_co (CCoercion co) = check_co co
|
|
| 3554 | - check_cast_co (ZCoercion _ty _cos) = error "AMG TODO check_cast_co"
|
|
| 3555 | - |
|
| 3556 | - |
|
| 3557 | 3552 | {- *********************************************************************
|
| 3558 | 3553 | * *
|
| 3559 | 3554 | Equality invariant checking
|
| ... | ... | @@ -4149,7 +4144,7 @@ check_ty_eq_rhs flags ty |
| 4149 | 4144 | ; return (mkAppRedn <$> fun_res <*> arg_res) }
|
| 4150 | 4145 | |
| 4151 | 4146 | CastTy ty co -> do { ty_res <- check_ty_eq_rhs flags ty
|
| 4152 | - ; co_res <- checkCo flags (castCoToCo (typeKind ty) co)
|
|
| 4147 | + ; co_res <- checkCo flags co
|
|
| 4153 | 4148 | ; return (mkCastRedn1 Nominal ty <$> co_res <*> ty_res) }
|
| 4154 | 4149 | |
| 4155 | 4150 | CoercionTy co -> do { co_res <- checkCo flags co
|
| ... | ... | @@ -4545,7 +4540,7 @@ simpleOccursCheck (OC_Check lhs_tv occ_prob) occ_tv |
| 4545 | 4540 | | otherwise
|
| 4546 | 4541 | = TyVarCheck_Success
|
| 4547 | 4542 | where
|
| 4548 | - (check_kind, _, _) = mkOccFolders lhs_tv
|
|
| 4543 | + (check_kind, _) = mkOccFolders lhs_tv
|
|
| 4549 | 4544 | |
| 4550 | 4545 | -------------------------
|
| 4551 | 4546 | tyVarLevelCheck :: LevelCheck m -> TcTyVar -> TyVarCheckResult m
|