diff options
| author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-12-14 10:40:32 +0000 |
|---|---|---|
| committer | Matthew Pickering <matthewtpickering@gmail.com> | 2021-12-30 16:27:49 +0000 |
| commit | a92246df66a11e99b850f469ec0e9e5b749d7e7e (patch) | |
| tree | bfb9a0fcd7055d0584611bf440eacc888ea4f3ea | |
| parent | 3311f4b23060e421af9aa059d69330cb85b95eec (diff) | |
| download | haskell-a92246df66a11e99b850f469ec0e9e5b749d7e7e.tar.gz | |
Good improvements
| -rw-r--r-- | compiler/GHC/Core/TyCo/Tidy.hs | 2 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Errors.hs | 12 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Gen/HsType.hs | 150 | ||||
| -rw-r--r-- | compiler/GHC/Tc/TyCl.hs | 21 | ||||
| -rw-r--r-- | compiler/GHC/Tc/TyCl/Class.hs | 5 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Types/Origin.hs | 4 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/TcMType.hs | 12 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/TcMType.hs-boot | 5 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/TcType.hs | 9 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/TcType.hs-boot | 4 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/Zonk.hs | 4 | ||||
| -rw-r--r-- | compiler/GHC/Types/Var.hs | 15 |
12 files changed, 103 insertions, 140 deletions
diff --git a/compiler/GHC/Core/TyCo/Tidy.hs b/compiler/GHC/Core/TyCo/Tidy.hs index aa1fb87490..97d3adf8e0 100644 --- a/compiler/GHC/Core/TyCo/Tidy.hs +++ b/compiler/GHC/Core/TyCo/Tidy.hs @@ -27,7 +27,6 @@ import GHC.Types.Var.Env import GHC.Utils.Misc (strictMap) import Data.List (mapAccumL) -import {-# SOURCE #-} GHC.Tc.Utils.TcMType ( ) {- %************************************************************************ @@ -119,7 +118,6 @@ tidyTyCoVarOcc :: TidyEnv -> TyCoVar -> TyCoVar tidyTyCoVarOcc env@(_, subst) tv = case lookupVarEnv subst tv of Nothing -> updateVarType (tidyType env) tv --- updateTcTyVarSkolemInfo (tidySkolemInfo env) $ Just tv' -> tv' --------------- diff --git a/compiler/GHC/Tc/Errors.hs b/compiler/GHC/Tc/Errors.hs index 2f36562d29..d202312fbc 100644 --- a/compiler/GHC/Tc/Errors.hs +++ b/compiler/GHC/Tc/Errors.hs @@ -230,7 +230,7 @@ report_unsolved type_errors expr_holes ; wanted <- zonkWC wanted -- Zonk to reveal all information - ; let + ; let tidy_env = tidyFreeTyCoVars emptyTidyEnv free_tvs; free_tvs = filterOut isCoVar $ tyCoVarsOfWCList wanted -- tyCoVarsOfWC returns free coercion *holes*, even though @@ -239,8 +239,6 @@ report_unsolved type_errors expr_holes -- no sense. Really we should not return those holes at all; -- for now we just filter them out. - ; let tidy_env = tidyFreeTyCoVars emptyTidyEnv free_tvs; - ; traceTc "reportUnsolved (after zonking):" $ vcat [ text "Free tyvars:" <+> pprTyVars free_tvs , text "Tidy env:" <+> ppr tidy_env @@ -1305,7 +1303,7 @@ mkHoleError lcl_name_cache tidy_simples ctxt hole@(Hole { hole_occ = occ else return (ctxt, empty) - ; skol_msg <- pprSkols ctxt =<< mapM zonkTyVarSkolemInfo skol_tvs + ; skol_msg <- pprSkols ctxt skol_tvs ; let err = important (hole_msg skol_msg) `mappend` mk_relevant_bindings (binds_msg $$ constraints_msg) `mappend` valid_hole_fits sub_msg @@ -1936,7 +1934,7 @@ extraTyVarEqInfo ctxt tv1 ty2 Just (tv, _) -> extraTyVarInfo ctxt tv Nothing -> return empty -extraTyVarInfo :: HasCallStack => ReportErrCtxt -> TcTyVar -> TcM SDoc +extraTyVarInfo :: ReportErrCtxt -> TcTyVar -> TcM SDoc extraTyVarInfo ctxt tv = assertPpr (isTyVar tv) (ppr tv) $ case tcTyVarDetails tv of @@ -3164,11 +3162,9 @@ mkAmbigMsg prepend_msg ct = text "The" <+> what <+> text "variable" <> plural tkvs <+> pprQuotedList tkvs <+> isOrAre tkvs <+> text "ambiguous" -pprSkols :: HasCallStack => ReportErrCtxt -> [TcTyVar] -> TcM SDoc +pprSkols :: ReportErrCtxt -> [TcTyVar] -> TcM SDoc pprSkols ctxt tvs = do - pprTraceM "ty_vars" (ppr tvs) - pprTraceM "ty_vars" (ppr skolem_list) zonked_ty_vars <- mapM (firstM zonkSkolemInfo) skolem_list let tidy_ty_vars = map (bimap (getSkolemInfo . tidySkolemInfo (cec_tidy ctxt)) (map fst)) zonked_ty_vars return $ vcat (map pp_one tidy_ty_vars) diff --git a/compiler/GHC/Tc/Gen/HsType.hs b/compiler/GHC/Tc/Gen/HsType.hs index 2ca15d2e5b..ab193a33a1 100644 --- a/compiler/GHC/Tc/Gen/HsType.hs +++ b/compiler/GHC/Tc/Gen/HsType.hs @@ -129,7 +129,6 @@ import GHC.Data.Maybe import GHC.Data.Bag( unitBag ) import Data.List ( find ) import Control.Monad -import GHC.Stack {- ---------------------------- @@ -386,9 +385,7 @@ kcClassSigType :: [LocatedN Name] -> LHsSigType GhcRn -> TcM () kcClassSigType names sig_ty@(L _ (HsSig { sig_bndrs = hs_outer_bndrs, sig_body = hs_ty })) = addSigCtxt (funsSigCtxt names) sig_ty $ - --MP: I suspect this is wrong, like the other kind checking cases. - do { skol_info <- mkSkolemInfo ((SigTypeSkol (funsSigCtxt names))) - ; _ <- bindOuterSigTKBndrs_Tv skol_info hs_outer_bndrs $ + do { _ <- bindOuterSigTKBndrs_Tv hs_outer_bndrs $ tcLHsType hs_ty liftedTypeKind ; return () } @@ -2370,7 +2367,7 @@ kcCheckDeclHeader (SAKS sig) = kcCheckDeclHeader_sig sig kcCheckDeclHeader CUSK = kcCheckDeclHeader_cusk kcCheckDeclHeader_cusk - :: HasCallStack => Name -- ^ of the thing being checked + :: Name -- ^ of the thing being checked -> TyConFlavour -- ^ What sort of 'TyCon' is being checked -> LHsQTyVars GhcRn -- ^ Binders in the header -> TcM ContextKind -- ^ The result kind @@ -2447,7 +2444,7 @@ kcCheckDeclHeader_cusk name flav ; return tycon } where - skol_info_anon = TyConSkol callStack flav name + skol_info_anon = TyConSkol flav name ctxt_kind | tcFlavourIsOpen flav = TheKind liftedTypeKind | otherwise = AnyKind @@ -2467,12 +2464,11 @@ kcInferDeclHeader name flav -- No standalane kind signature and no CUSK. -- See note [Required, Specified, and Inferred for types] in GHC.Tc.TyCl = addTyConFlavCtxt name flav $ - do { skol_info <- mkSkolemInfo (TyConSkol callStack flav name) - ; (scoped_kvs, (tc_tvs, res_kind)) + do { (scoped_kvs, (tc_tvs, res_kind)) -- Why bindImplicitTKBndrs_Q_Tv which uses newTyVarTyVar? -- See Note [Inferring kinds for type declarations] in GHC.Tc.TyCl - <- bindImplicitTKBndrs_Q_Tv skol_info kv_ns $ - bindExplicitTKBndrs_Q_Tv skol_info ctxt_kind hs_tvs $ + <- bindImplicitTKBndrs_Q_Tv kv_ns $ + bindExplicitTKBndrs_Q_Tv ctxt_kind hs_tvs $ newExpectedKind =<< kc_res_ki -- Why "_Tv" not "_Skol"? See third wrinkle in -- Note [Inferring kinds for type declarations] in GHC.Tc.TyCl, @@ -2510,7 +2506,7 @@ kcInferDeclHeader name flav -- | Kind-check a declaration header against a standalone kind signature. -- See Note [Arity inference in kcCheckDeclHeader_sig] kcCheckDeclHeader_sig - :: HasCallStack => Kind -- ^ Standalone kind signature, fully zonked! (zonkTcTypeToType) + :: Kind -- ^ Standalone kind signature, fully zonked! (zonkTcTypeToType) -> Name -- ^ of the thing being checked -> TyConFlavour -- ^ What sort of 'TyCon' is being checked -> LHsQTyVars GhcRn -- ^ Binders in the header @@ -2550,11 +2546,11 @@ kcCheckDeclHeader_sig kisig name flav -- Convert each ZippedBinder to TyConBinder for tyConBinders -- and to [(Name, TcTyVar)] for tcTyConScopedTyVars ; (vis_tcbs, concat -> explicit_tv_prs) <- mapAndUnzipM zipped_to_tcb zipped_binders - ; skol_info <- mkSkolemInfo (TyConSkol callStack flav name) + ; skol_info <- mkSkolemInfo (TyConSkol flav name) ; (tclvl, wanted, (implicit_tvs, (invis_binders, r_ki))) <- pushLevelAndSolveEqualitiesX "kcCheckDeclHeader_sig" $ -- #16687 - bindImplicitTKBndrs_Tv skol_info implicit_nms $ + bindImplicitTKBndrs_Tv implicit_nms $ tcExtendNameTyVarEnv explicit_tv_prs $ do { -- Check that inline kind annotations on binders are valid. -- For example: @@ -3062,19 +3058,18 @@ tcTKTelescope mode tele thing_inside = case tele of -------------------------------------- bindOuterTKBndrsX :: OutputableBndrFlag flag 'Renamed - => SkolemInfo - -> SkolemMode + => SkolemMode -> HsOuterTyVarBndrs flag GhcRn -> TcM a -> TcM (HsOuterTyVarBndrs flag GhcTc, a) -bindOuterTKBndrsX skol_info skol_mode outer_bndrs thing_inside +bindOuterTKBndrsX skol_mode outer_bndrs thing_inside = case outer_bndrs of HsOuterImplicit{hso_ximplicit = imp_tvs} -> - do { (imp_tvs', thing) <- bindImplicitTKBndrsX skol_info skol_mode imp_tvs thing_inside + do { (imp_tvs', thing) <- bindImplicitTKBndrsX skol_mode imp_tvs thing_inside ; return ( HsOuterImplicit{hso_ximplicit = imp_tvs'} , thing) } HsOuterExplicit{hso_bndrs = exp_bndrs} -> - do { (exp_tvs', thing) <- bindExplicitTKBndrsX skol_info skol_mode exp_bndrs thing_inside + do { (exp_tvs', thing) <- bindExplicitTKBndrsX skol_mode exp_bndrs thing_inside ; return ( HsOuterExplicit { hso_xexplicit = exp_tvs' , hso_bndrs = exp_bndrs } , thing) } @@ -3098,32 +3093,29 @@ scopedSortOuter (HsOuterExplicit{hso_xexplicit = exp_tvs}) return exp_tvs --------------- -bindOuterSigTKBndrs_Tv :: SkolemInfo - -> HsOuterSigTyVarBndrs GhcRn +bindOuterSigTKBndrs_Tv :: HsOuterSigTyVarBndrs GhcRn -> TcM a -> TcM (HsOuterSigTyVarBndrs GhcTc, a) -bindOuterSigTKBndrs_Tv skolem_info - = bindOuterTKBndrsX skolem_info (smVanilla { sm_clone = True, sm_tvtv = True }) +bindOuterSigTKBndrs_Tv + = bindOuterTKBndrsX (smVanilla { sm_clone = True, sm_tvtv = SMDTyVarTv }) -bindOuterSigTKBndrs_Tv_M :: SkolemInfo - -> TcTyMode +bindOuterSigTKBndrs_Tv_M :: TcTyMode -> HsOuterSigTyVarBndrs GhcRn -> TcM a -> TcM (HsOuterSigTyVarBndrs GhcTc, a) -- Do not push level; do not make implication constraint; use Tvs -- Two major clients of this "bind-only" path are: -- Note [Using TyVarTvs for kind-checking GADTs] in GHC.Tc.TyCl -- Note [Checking partial type signatures] -bindOuterSigTKBndrs_Tv_M skol_info mode - = bindOuterTKBndrsX skol_info (smVanilla { sm_clone = True, sm_tvtv = True +bindOuterSigTKBndrs_Tv_M mode + = bindOuterTKBndrsX (smVanilla { sm_clone = True, sm_tvtv = SMDTyVarTv , sm_holes = mode_holes mode }) -bindOuterFamEqnTKBndrs_Q_Tv :: SkolemInfo - -> HsOuterFamEqnTyVarBndrs GhcRn +bindOuterFamEqnTKBndrs_Q_Tv :: HsOuterFamEqnTyVarBndrs GhcRn -> TcM a -> TcM ([TcTyVar], a) -bindOuterFamEqnTKBndrs_Q_Tv skol_info hs_bndrs thing_inside +bindOuterFamEqnTKBndrs_Q_Tv hs_bndrs thing_inside = liftFstM getOuterTyVars $ - bindOuterTKBndrsX skol_info (smVanilla { sm_clone = False, sm_parent = True - , sm_tvtv = True }) + bindOuterTKBndrsX (smVanilla { sm_clone = False, sm_parent = True + , sm_tvtv = SMDTyVarTv }) hs_bndrs thing_inside -- sm_clone=False: see Note [Cloning for type variable binders] @@ -3133,7 +3125,8 @@ bindOuterFamEqnTKBndrs :: SkolemInfo -> TcM ([TcTyVar], a) bindOuterFamEqnTKBndrs skol_info hs_bndrs thing_inside = liftFstM getOuterTyVars $ - bindOuterTKBndrsX skol_info (smVanilla { sm_clone = False, sm_parent = True }) + bindOuterTKBndrsX (smVanilla { sm_clone = False, sm_parent = True + , sm_tvtv = SMDSkolemTv skol_info }) hs_bndrs thing_inside -- sm_clone=False: see Note [Cloning for type variable binders] @@ -3142,7 +3135,7 @@ tcOuterTKBndrs :: OutputableBndrFlag flag 'Renamed => SkolemInfo -> HsOuterTyVarBndrs flag GhcRn -> TcM a -> TcM (HsOuterTyVarBndrs flag GhcTc, a) -tcOuterTKBndrs = tcOuterTKBndrsX (smVanilla { sm_clone = False }) +tcOuterTKBndrs skol_info = tcOuterTKBndrsX (smVanilla { sm_clone = False, sm_tvtv = SMDSkolemTv skol_info }) skol_info -- Do not clone the outer binders -- See Note [Cloning for type variable binder] under "must not" @@ -3183,9 +3176,10 @@ tcExplicitTKBndrsX :: OutputableBndrFlag flag 'Renamed -- so that it is subject to a telescope test. tcExplicitTKBndrsX skol_mode bndrs thing_inside = do { skol_info <- mkSkolemInfo (ForAllSkol (fsep (map ppr bndrs))) + ; let skol_mode' = skol_mode { sm_tvtv = SMDSkolemTv skol_info } ; (tclvl, wanted, (skol_tvs, res)) <- pushLevelAndCaptureConstraints $ - bindExplicitTKBndrsX skol_info skol_mode bndrs $ + bindExplicitTKBndrsX skol_mode' bndrs $ thing_inside -- Notice that we use ForAllSkol here, ignoring the enclosing @@ -3198,46 +3192,57 @@ tcExplicitTKBndrsX skol_mode bndrs thing_inside ---------------- -- | Skolemise the 'HsTyVarBndr's in an 'HsForAllTelescope' with the supplied -- 'TcTyMode'. -bindExplicitTKBndrs_Skol, bindExplicitTKBndrs_Tv +bindExplicitTKBndrs_Skol :: (OutputableBndrFlag flag 'Renamed) => SkolemInfo -> [LHsTyVarBndr flag GhcRn] -> TcM a -> TcM ([VarBndr TyVar flag], a) -bindExplicitTKBndrs_Skol skol_info = bindExplicitTKBndrsX skol_info (smVanilla { sm_clone = False }) -bindExplicitTKBndrs_Tv skol_info = bindExplicitTKBndrsX skol_info (smVanilla { sm_clone = True, sm_tvtv = True }) +bindExplicitTKBndrs_Tv + :: (OutputableBndrFlag flag 'Renamed) + => [LHsTyVarBndr flag GhcRn] + -> TcM a + -> TcM ([VarBndr TyVar flag], a) + +bindExplicitTKBndrs_Skol skol_info = bindExplicitTKBndrsX (smVanilla { sm_clone = False, sm_tvtv = SMDSkolemTv skol_info }) +bindExplicitTKBndrs_Tv = bindExplicitTKBndrsX (smVanilla { sm_clone = True, sm_tvtv = SMDTyVarTv }) -- sm_clone: see Note [Cloning for type variable binders] -bindExplicitTKBndrs_Q_Skol, bindExplicitTKBndrs_Q_Tv +bindExplicitTKBndrs_Q_Skol :: SkolemInfo -> ContextKind -> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TcTyVar], a) + +bindExplicitTKBndrs_Q_Tv + :: ContextKind + -> [LHsTyVarBndr () GhcRn] + -> TcM a + -> TcM ([TcTyVar], a) -- These do not clone: see Note [Cloning for type variable binders] bindExplicitTKBndrs_Q_Skol skol_info ctxt_kind hs_bndrs thing_inside = liftFstM binderVars $ - bindExplicitTKBndrsX skol_info (smVanilla { sm_clone = False, sm_parent = True - , sm_kind = ctxt_kind }) + bindExplicitTKBndrsX (smVanilla { sm_clone = False, sm_parent = True + , sm_kind = ctxt_kind, sm_tvtv = SMDSkolemTv skol_info }) hs_bndrs thing_inside -- sm_clone=False: see Note [Cloning for type variable binders] -bindExplicitTKBndrs_Q_Tv skol_info ctxt_kind hs_bndrs thing_inside +bindExplicitTKBndrs_Q_Tv ctxt_kind hs_bndrs thing_inside = liftFstM binderVars $ - bindExplicitTKBndrsX skol_info (smVanilla { sm_clone = False, sm_parent = True - , sm_tvtv = True, sm_kind = ctxt_kind }) + bindExplicitTKBndrsX (smVanilla { sm_clone = False, sm_parent = True + , sm_tvtv = SMDTyVarTv, sm_kind = ctxt_kind }) hs_bndrs thing_inside -- sm_clone=False: see Note [Cloning for type variable binders] bindExplicitTKBndrsX :: (OutputableBndrFlag flag 'Renamed) - => SkolemInfo - -> SkolemMode + => SkolemMode -> [LHsTyVarBndr flag GhcRn] -> TcM a -> TcM ([VarBndr TyVar flag], a) -- Returned [TcTyVar] are in 1-1 correspondence -- with the passed-in [LHsTyVarBndr] -bindExplicitTKBndrsX skol_info skol_mode@(SM { sm_parent = check_parent, sm_kind = ctxt_kind +bindExplicitTKBndrsX skol_mode@(SM { sm_parent = check_parent, sm_kind = ctxt_kind , sm_holes = hole_info }) hs_tvs thing_inside = do { traceTc "bindExplicitTKBndrs" (ppr hs_tvs) @@ -3267,7 +3272,7 @@ bindExplicitTKBndrsX skol_info skol_mode@(SM { sm_parent = check_parent, sm_kind = return tv | otherwise = do { kind <- newExpectedKind ctxt_kind - ; newTyVarBndr skol_info skol_mode name kind } + ; newTyVarBndr skol_mode name kind } tc_hs_bndr lcl_env (KindedTyVar _ _ (L _ name) lhs_kind) | check_parent @@ -3282,19 +3287,20 @@ bindExplicitTKBndrsX skol_info skol_mode@(SM { sm_parent = check_parent, sm_kind | otherwise = do { kind <- tc_lhs_kind_sig tc_ki_mode (TyVarBndrKindCtxt name) lhs_kind - ; newTyVarBndr skol_info skol_mode name kind } + ; newTyVarBndr skol_mode name kind } -newTyVarBndr :: SkolemInfo -> SkolemMode -> Name -> Kind -> TcM TcTyVar -newTyVarBndr skol_info (SM { sm_clone = clone, sm_tvtv = tvtv }) name kind +newTyVarBndr :: SkolemMode -> Name -> Kind -> TcM TcTyVar +newTyVarBndr (SM { sm_clone = clone, sm_tvtv = tvtv }) name kind = do { name <- case clone of True -> do { uniq <- newUnique ; return (setNameUnique name uniq) } False -> return name ; details <- case tvtv of - True -> newMetaDetails TyVarTv - False -> do { lvl <- getTcLevel - ; return (SkolemTv skol_info lvl False) } + SMDTyVarTv -> newMetaDetails TyVarTv + SMDSkolemTv skol_info -> + do { lvl <- getTcLevel + ; return (SkolemTv skol_info lvl False) } ; return (mkTcTyVar name kind details) } -------------------------------------- @@ -3318,7 +3324,7 @@ tcImplicitTKBndrsX skol_info skol_mode bndrs thing_inside | otherwise = do { (tclvl, wanted, (skol_tvs, res)) <- pushLevelAndCaptureConstraints $ - bindImplicitTKBndrsX skol_info skol_mode bndrs $ + bindImplicitTKBndrsX skol_mode bndrs $ thing_inside ; emitResidualTvConstraint skol_info skol_tvs tclvl wanted @@ -3326,22 +3332,22 @@ tcImplicitTKBndrsX skol_info skol_mode bndrs thing_inside ; return (skol_tvs, res) } ------------------ -bindImplicitTKBndrs_Skol, bindImplicitTKBndrs_Tv, - bindImplicitTKBndrs_Q_Skol, bindImplicitTKBndrs_Q_Tv - :: SkolemInfo -> [Name] -> TcM a -> TcM ([TcTyVar], a) -bindImplicitTKBndrs_Skol skol_info = bindImplicitTKBndrsX skol_info (smVanilla { sm_clone = True }) -bindImplicitTKBndrs_Tv skol_info = bindImplicitTKBndrsX skol_info (smVanilla { sm_clone = True, sm_tvtv = True }) -bindImplicitTKBndrs_Q_Skol skol_info = bindImplicitTKBndrsX skol_info (smVanilla { sm_clone = False, sm_parent = True }) -bindImplicitTKBndrs_Q_Tv skol_info = bindImplicitTKBndrsX skol_info (smVanilla { sm_clone = False, sm_parent = True, sm_tvtv = True }) +bindImplicitTKBndrs_Skol, + bindImplicitTKBndrs_Q_Skol :: SkolemInfo -> [Name] -> TcM a -> TcM ([TcTyVar], a) + +bindImplicitTKBndrs_Tv, bindImplicitTKBndrs_Q_Tv :: [Name] -> TcM a -> TcM ([TcTyVar], a) +bindImplicitTKBndrs_Skol skol_info = bindImplicitTKBndrsX (smVanilla { sm_clone = True, sm_tvtv = SMDSkolemTv skol_info }) +bindImplicitTKBndrs_Tv = bindImplicitTKBndrsX (smVanilla { sm_clone = True, sm_tvtv = SMDTyVarTv }) +bindImplicitTKBndrs_Q_Skol skol_info = bindImplicitTKBndrsX (smVanilla { sm_clone = False, sm_parent = True, sm_tvtv = SMDSkolemTv skol_info }) +bindImplicitTKBndrs_Q_Tv = bindImplicitTKBndrsX (smVanilla { sm_clone = False, sm_parent = True, sm_tvtv = SMDTyVarTv }) bindImplicitTKBndrsX - :: SkolemInfo - -> SkolemMode + :: SkolemMode -> [Name] -> TcM a -> TcM ([TcTyVar], a) -- Returned [TcTyVar] are in 1-1 correspondence -- with the passed in [Name] -bindImplicitTKBndrsX skol_info skol_mode@(SM { sm_parent = check_parent, sm_kind = ctxt_kind }) +bindImplicitTKBndrsX skol_mode@(SM { sm_parent = check_parent, sm_kind = ctxt_kind }) tv_names thing_inside = do { lcl_env <- getLclTypeEnv ; tkvs <- mapM (new_tv lcl_env) tv_names @@ -3356,7 +3362,7 @@ bindImplicitTKBndrsX skol_info skol_mode@(SM { sm_parent = check_parent, sm_kind = return tv | otherwise = do { kind <- newExpectedKind ctxt_kind - ; newTyVarBndr skol_info skol_mode name kind } + ; newTyVarBndr skol_mode name kind } -------------------------------------- -- SkolemMode @@ -3372,7 +3378,7 @@ data SkolemMode , sm_clone :: Bool -- True <=> fresh unique -- See Note [Cloning for type variable binders] - , sm_tvtv :: Bool -- True <=> use a TyVarTv, rather than SkolemTv + , sm_tvtv :: SkolemModeDetails -- True <=> use a TyVarTv, rather than SkolemTv -- Why? See Note [Inferring kinds for type declarations] -- in GHC.Tc.TyCl, and (in this module) -- Note [Checking partial type signatures] @@ -3382,10 +3388,15 @@ data SkolemMode , sm_holes :: HoleInfo -- What to do for wildcards in the kind } -smVanilla :: SkolemMode +data SkolemModeDetails + = SMDTyVarTv + | SMDSkolemTv SkolemInfo + + +smVanilla :: HasCallStack => SkolemMode smVanilla = SM { sm_clone = panic "sm_clone" -- We always override this , sm_parent = False - , sm_tvtv = False + , sm_tvtv = pprPanic "sm_tvtv" callStackDoc -- We always override this , sm_kind = AnyKind , sm_holes = Nothing } @@ -3940,12 +3951,11 @@ tcHsPartialSigType ctxt sig_ty , (hs_ctxt, hs_tau) <- splitLHsQualTy body_ty = addSigCtxt ctxt sig_ty $ do { mode <- mkHoleMode TypeLevel HM_Sig - ; skol_info <- mkSkolemInfo (SigTypeSkol ctxt) ; (outer_bndrs, (wcs, wcx, theta, tau)) <- solveEqualities "tcHsPartialSigType" $ -- See Note [Failure in local type signatures] bindNamedWildCardBinders sig_wcs $ \ wcs -> - bindOuterSigTKBndrs_Tv_M skol_info mode hs_outer_bndrs $ + bindOuterSigTKBndrs_Tv_M mode hs_outer_bndrs $ do { -- Instantiate the type-class context; but if there -- is an extra-constraints wildcard, just discard it here (theta, wcx) <- tcPartialContext mode hs_ctxt diff --git a/compiler/GHC/Tc/TyCl.hs b/compiler/GHC/Tc/TyCl.hs index 201d22d04f..5038f464c9 100644 --- a/compiler/GHC/Tc/TyCl.hs +++ b/compiler/GHC/Tc/TyCl.hs @@ -103,7 +103,6 @@ import Data.List (nubBy, partition) import Data.List.NonEmpty ( NonEmpty(..) ) import qualified Data.Set as Set import Data.Tuple( swap ) -import GHC.Stack {- ************************************************************************ @@ -1673,7 +1672,7 @@ kcConDecl new_or_data tc_res_kind (ConDeclH98 , con_mb_cxt = ex_ctxt, con_args = args }) = addErrCtxt (dataConCtxt [name]) $ discardResult $ - bindExplicitTKBndrs_Tv unkSkol ex_tvs $ + bindExplicitTKBndrs_Tv ex_tvs $ do { _ <- tcHsContext ex_ctxt ; kcConH98Args new_or_data tc_res_kind args -- We don't need to check the telescope here, @@ -1688,9 +1687,8 @@ kcConDecl new_or_data = -- See Note [kcConDecls: kind-checking data type decls] addErrCtxt (dataConCtxt names) $ discardResult $ - mkSkolemInfo (DataConSkol (unLoc (head names))) >>= \skol_info -> -- Not sure this is right, should just extend rather than skolemise but no test - bindOuterSigTKBndrs_Tv skol_info outer_bndrs $ + bindOuterSigTKBndrs_Tv outer_bndrs $ -- Why "_Tv"? See Note [Using TyVarTvs for kind-checking GADTs] do { _ <- tcHsContext cxt ; traceTc "kcConDecl:GADT {" (ppr names $$ ppr res_ty) @@ -2495,7 +2493,7 @@ tcClassDecl1 roles_info class_name hs_ctxt meths fundeps sigs ats at_defs ppr fds) ; return clas } where - skol_info_anon = TyConSkol callStack ClassFlavour class_name + skol_info_anon = TyConSkol ClassFlavour class_name tc_fundep :: GHC.Hs.FunDep GhcRn -> TcM ([Var],[Var]) tc_fundep (FunDep _ tvs1 tvs2) = do { tvs1' <- mapM (tcLookupTyVar . unLoc) tvs1 ; @@ -2719,7 +2717,7 @@ tcFamDecl1 parent (FamilyDecl { fdInfo = fam_info , fdResultSig = L _ sig , fdInjectivityAnn = inj }) | DataFamily <- fam_info - = mkSkolemInfo (TyConSkol callStack (DataFamilyFlavour Nothing) tc_name) >>= \skol_info -> + = mkSkolemInfo (TyConSkol (DataFamilyFlavour Nothing) tc_name) >>= \skol_info -> bindTyClTyVars skol_info tc_name $ \ _ binders res_kind -> do { traceTc "tcFamDecl1 data family:" (ppr tc_name) ; checkFamFlag tc_name @@ -2747,7 +2745,7 @@ tcFamDecl1 parent (FamilyDecl { fdInfo = fam_info | OpenTypeFamily <- fam_info = - mkSkolemInfo (TyConSkol callStack (OpenTypeFamilyFlavour Nothing) tc_name) >>= \skol_info -> + mkSkolemInfo (TyConSkol (OpenTypeFamilyFlavour Nothing) tc_name) >>= \skol_info -> bindTyClTyVars skol_info tc_name $ \ _ binders res_kind -> do { traceTc "tcFamDecl1 open type family:" (ppr tc_name) ; checkFamFlag tc_name @@ -2885,7 +2883,7 @@ tcTySynRhs roles_info tc_name hs_ty ; let roles = roles_info tc_name ; return (buildSynTyCon tc_name binders res_kind roles rhs_ty) } where - skol_info_anon = TyConSkol callStack TypeSynonymFlavour tc_name + skol_info_anon = TyConSkol TypeSynonymFlavour tc_name tcDataDefn :: SDoc -> RolesInfo -> Name -> HsDataDefn GhcRn -> TcM (TyCon, [DerivInfo]) @@ -2965,7 +2963,7 @@ tcDataDefn err_ctxt roles_info tc_name ; traceTc "tcDataDefn" (ppr tc_name $$ ppr tycon_binders $$ ppr extra_bndrs) ; return (tycon, [deriv_info]) } where - skol_info_anon = TyConSkol callStack flav tc_name + skol_info_anon = TyConSkol flav tc_name flav = newOrDataToFlavour new_or_data -- Abstract data types in hsig files can have arbitrary kinds, @@ -3013,8 +3011,7 @@ kcTyFamInstEqn tc_fam_tc ; checkTyFamInstEqn tc_fam_tc eqn_tc_name hs_pats ; discardResult $ - mkSkolemInfo FamInstSkol >>= \skol_info -> - bindOuterFamEqnTKBndrs_Q_Tv skol_info outer_bndrs $ + bindOuterFamEqnTKBndrs_Q_Tv outer_bndrs $ do { (_fam_app, res_kind) <- tcFamTyPats tc_fam_tc hs_pats ; tcCheckLHsType hs_rhs_ty (TheKind res_kind) } -- Why "_Tv" here? Consider (#14066) @@ -3444,7 +3441,7 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs res_kind tag_map -- the kvs below are those kind variables entirely unmentioned by the user -- and discovered only by generalization - ; kvs <- kindGeneralizeAll unkSkol fake_ty + ; kvs <- kindGeneralizeAll skol_info fake_ty ; let skol_tvs = tc_tvs ++ kvs ++ binderVars exp_tvbndrs ; reportUnsolvedEqualities skol_info skol_tvs tclvl wanted diff --git a/compiler/GHC/Tc/TyCl/Class.hs b/compiler/GHC/Tc/TyCl/Class.hs index ba199abe4e..cab4b8c1e5 100644 --- a/compiler/GHC/Tc/TyCl/Class.hs +++ b/compiler/GHC/Tc/TyCl/Class.hs @@ -72,7 +72,6 @@ import GHC.Utils.Misc import Control.Monad import Data.List ( mapAccumL, partition ) -import GHC.Stack {- Dictionary handling @@ -214,7 +213,7 @@ tcClassDecl2 class_scoped_tv_env -- And since ds is big, it doesn't get inlined, so we don't get good -- default methods. Better to make separate AbsBinds for each - ; skol_info <- mkSkolemInfo (TyConSkol callStack ClassFlavour (getName class_name)) + ; skol_info <- mkSkolemInfo (TyConSkol ClassFlavour (getName class_name)) ; let (tyvars, _, _, op_items) = classBigSig clas prag_fn = mkPragEnv sigs default_binds sig_fn = mkHsSigFun sigs @@ -338,7 +337,7 @@ tcDefMeth clas tyvars this_dict binds_in hs_sig_fn prag_fn | otherwise = pprPanic "tcDefMeth" (ppr sel_id) where - skol_info = TyConSkol callStack ClassFlavour (getName clas) + skol_info = TyConSkol ClassFlavour (getName clas) sel_name = idName sel_id no_prag_fn = emptyPragEnv -- No pragmas for local_meth_id; -- they are all for meth_id diff --git a/compiler/GHC/Tc/Types/Origin.hs b/compiler/GHC/Tc/Types/Origin.hs index 2d9cbc83d9..9138830812 100644 --- a/compiler/GHC/Tc/Types/Origin.hs +++ b/compiler/GHC/Tc/Types/Origin.hs @@ -251,7 +251,7 @@ data SkolemInfoAnon | UnifyForAllSkol -- We are unifying two for-all types TcType -- The instantiated type *inside* the forall - | TyConSkol CallStack TyConFlavour Name -- bound in a type declaration of the given flavour + | TyConSkol TyConFlavour Name -- bound in a type declaration of the given flavour | DataConSkol Name -- bound as an existential in a Haskell98 datacon decl or -- as any variable in a GADT datacon decl @@ -304,7 +304,7 @@ pprSkolInfo (InferSkol ids) = hang (text "the inferred type" <> plural ids <+> 2 (vcat [ ppr name <+> dcolon <+> ppr ty | (name,ty) <- ids ]) pprSkolInfo (UnifyForAllSkol ty) = text "the type" <+> ppr ty -pprSkolInfo (TyConSkol _cs flav name) = text "the" <+> ppr flav <+> text "declaration for" <+> quotes (ppr name) +pprSkolInfo (TyConSkol flav name) = text "the" <+> ppr flav <+> text "declaration for" <+> quotes (ppr name) pprSkolInfo (DataConSkol name)= text "the data constructor" <+> quotes (ppr name) pprSkolInfo ReifySkol = text "the type being reified" diff --git a/compiler/GHC/Tc/Utils/TcMType.hs b/compiler/GHC/Tc/Utils/TcMType.hs index b6a750764a..182e514427 100644 --- a/compiler/GHC/Tc/Utils/TcMType.hs +++ b/compiler/GHC/Tc/Utils/TcMType.hs @@ -78,7 +78,7 @@ module GHC.Tc.Utils.TcMType ( zonkTyCoVarKind, zonkTyCoVarKindBinder, zonkEvVar, zonkWC, zonkImplication, zonkSimples, zonkId, zonkCoVar, - zonkCt, zonkSkolemInfo, zonkTyVarSkolemInfo, + zonkCt, zonkSkolemInfo, --------------------------------- -- Promotion, defaulting, skolemisation @@ -2426,13 +2426,6 @@ zonkSkolemInfoAnon (InferSkol ntys) = do { ntys' <- mapM do_one ntys do_one (n, ty) = do { ty' <- zonkTcType ty; return (n, ty') } zonkSkolemInfoAnon skol_info = return skol_info -zonkTyVarSkolemInfo :: TyVar -> TcM TyVar -zonkTyVarSkolemInfo = - updateTcTyVarDetailsM (\case { SkolemTv sk_info lvl over -> do - sk_info' <- zonkSkolemInfo sk_info - return (SkolemTv sk_info' lvl over) - ; det -> return det }) - {- %************************************************************************ %* * @@ -2502,8 +2495,7 @@ zonkTcTyVar tv = zonk_kind_and_return where zonk_kind_and_return = do { z_tv <- zonkTyCoVarKind tv - -- ; pprTraceM "zonk_kind" (ppr tv $$ ppr z_tv) - ; mkTyVarTy <$> pure z_tv --updateTcTyVarDetailsM (updateSkolInfoM zonkSkolemInfo) z_tv + ; mkTyVarTy <$> pure z_tv } -- Variant that assumes that any result of zonking is still a TyVar. diff --git a/compiler/GHC/Tc/Utils/TcMType.hs-boot b/compiler/GHC/Tc/Utils/TcMType.hs-boot deleted file mode 100644 index 1ca06e9fa3..0000000000 --- a/compiler/GHC/Tc/Utils/TcMType.hs-boot +++ /dev/null @@ -1,5 +0,0 @@ -module GHC.Tc.Utils.TcMType where -import GHC.Types.Var.Env ( TidyEnv ) -import {-# SOURCE #-} GHC.Tc.Types.Origin ( SkolemInfo ) - -tidySkolemInfo :: TidyEnv -> SkolemInfo -> SkolemInfo diff --git a/compiler/GHC/Tc/Utils/TcType.hs b/compiler/GHC/Tc/Utils/TcType.hs index fe586b0d6e..c93c012467 100644 --- a/compiler/GHC/Tc/Utils/TcType.hs +++ b/compiler/GHC/Tc/Utils/TcType.hs @@ -39,7 +39,6 @@ module GHC.Tc.Utils.TcType ( -------------------------------- -- MetaDetails TcTyVarDetails(..), pprTcTyVarDetails, vanillaSkolemTv, vanillaSkolemTvUnk, superSkolemTv, - updateSkolInfo, updateSkolInfoM, MetaDetails(Flexi, Indirect), MetaInfo(..), skolemSkolInfo, isImmutableTyVar, isSkolemTyVar, isMetaTyVar, isMetaTyVarTy, isTyVarTy, tcIsTcTyVar, isTyVarTyVar, isOverlappableTyVar, isTyConableTyVar, @@ -236,7 +235,6 @@ import Data.List ( mapAccumL ) import Data.IORef import Data.List.NonEmpty( NonEmpty(..) ) import {-# SOURCE #-} GHC.Tc.Types.Origin ( unkSkol, SkolemInfo ) -import Data.Functor.Identity {- @@ -509,13 +507,6 @@ superSkolemTv sk = SkolemTv sk topTcLevel True -- Treat this as a completely vanillaSkolemTvUnk :: HasCallStack => TcTyVarDetails vanillaSkolemTvUnk = vanillaSkolemTv unkSkol -updateSkolInfo :: (SkolemInfo -> SkolemInfo) -> TcTyVarDetails -> TcTyVarDetails -updateSkolInfo f d = runIdentity (updateSkolInfoM (Identity . f) d) - -updateSkolInfoM :: Applicative m => (SkolemInfo -> m SkolemInfo) -> TcTyVarDetails -> m TcTyVarDetails -updateSkolInfoM f (SkolemTv v a b) = (\v' -> SkolemTv v' a b) <$> f v -updateSkolInfoM _ td = pure td - instance Outputable TcTyVarDetails where ppr = pprTcTyVarDetails diff --git a/compiler/GHC/Tc/Utils/TcType.hs-boot b/compiler/GHC/Tc/Utils/TcType.hs-boot index 6ac6ee902b..d89f7299c9 100644 --- a/compiler/GHC/Tc/Utils/TcType.hs-boot +++ b/compiler/GHC/Tc/Utils/TcType.hs-boot @@ -1,6 +1,6 @@ module GHC.Tc.Utils.TcType where import GHC.Utils.Outputable( SDoc ) -import GHC.Prelude ( Bool, Applicative ) +import GHC.Prelude ( Bool ) import {-# SOURCE #-} GHC.Types.Var ( TcTyVar ) import {-# SOURCE #-} GHC.Core.TyCo.Rep import {-# SOURCE #-} GHC.Tc.Types.Origin @@ -18,5 +18,3 @@ isTyConableTyVar :: TcTyVar -> Bool tcEqType :: HasDebugCallStack => Type -> Type -> Bool -updateSkolInfo :: (SkolemInfo -> SkolemInfo) -> TcTyVarDetails -> TcTyVarDetails -updateSkolInfoM :: Applicative m => (SkolemInfo -> m SkolemInfo) -> TcTyVarDetails -> m TcTyVarDetails diff --git a/compiler/GHC/Tc/Utils/Zonk.hs b/compiler/GHC/Tc/Utils/Zonk.hs index f5a9d2f0e9..52336fefaa 100644 --- a/compiler/GHC/Tc/Utils/Zonk.hs +++ b/compiler/GHC/Tc/Utils/Zonk.hs @@ -1776,7 +1776,6 @@ change. But in some cases it makes a HUGE difference: see test T9198 and #19668. So yes, it seems worth it. -} - zonkTyVarOcc :: ZonkEnv -> TyVar -> TcM TcType zonkTyVarOcc env@(ZonkEnv { ze_flexi = flexi , ze_tv_env = tv_env @@ -1796,7 +1795,6 @@ zonkTyVarOcc env@(ZonkEnv { ze_flexi = flexi = lookup_in_tv_env where - lookup_in_tv_env -- Look up in the env just as we do for Ids = case lookupVarEnv tv_env tv of Nothing -> mkTyVarTy <$> updateTyVarKindM (zonkTcTypeToTypeX env) tv @@ -1816,8 +1814,6 @@ zonkTyVarOcc env@(ZonkEnv { ze_flexi = flexi = do { updTcRef mtv_env_ref (\env -> extendVarEnv env tv ty) ; return ty } - - lookupTyVarOcc :: ZonkEnv -> TcTyVar -> Maybe TyVar lookupTyVarOcc (ZonkEnv { ze_tv_env = tv_env }) tv = lookupVarEnv tv_env tv diff --git a/compiler/GHC/Types/Var.hs b/compiler/GHC/Types/Var.hs index 1024784589..56ca1f159b 100644 --- a/compiler/GHC/Types/Var.hs +++ b/compiler/GHC/Types/Var.hs @@ -89,17 +89,16 @@ module GHC.Types.Var ( -- ** Modifying 'TyVar's setTyVarName, setTyVarUnique, setTyVarKind, updateTyVarKind, - updateTyVarKindM, updateTcTyVarDetailsM, + updateTyVarKindM, nonDetCmpVar - - ,updateTcTyVarSkolemInfo) where + ) where import GHC.Prelude import {-# SOURCE #-} GHC.Core.TyCo.Rep( Type, Kind, Mult ) import {-# SOURCE #-} GHC.Core.TyCo.Ppr( pprKind ) -import {-# SOURCE #-} GHC.Tc.Utils.TcType( TcTyVarDetails, pprTcTyVarDetails, vanillaSkolemTvUnk, updateSkolInfo ) +import {-# SOURCE #-} GHC.Tc.Utils.TcType( TcTyVarDetails, pprTcTyVarDetails, vanillaSkolemTvUnk ) import {-# SOURCE #-} GHC.Types.Id.Info( IdDetails, IdInfo, coVarDetails, isCoVarDetails, vanillaIdInfo, pprIdDetails ) import {-# SOURCE #-} GHC.Builtin.Types ( manyDataConTy ) @@ -114,7 +113,6 @@ import GHC.Utils.Panic.Plain import Data.Data -import {-# SOURCE #-} GHC.Tc.Types.Origin ( SkolemInfo ) {- ************************************************************************ @@ -751,13 +749,6 @@ updateTyVarKindM update tv = do { k' <- update (tyVarKind tv) ; return $ tv {varType = k'} } -updateTcTyVarSkolemInfo :: (SkolemInfo -> SkolemInfo) -> TyVar -> TyVar -updateTcTyVarSkolemInfo update (TcTyVar a b c details) = TcTyVar a b c (updateSkolInfo update details) -updateTcTyVarSkolemInfo _ ty_var = ty_var - -updateTcTyVarDetailsM :: Monad m => (TcTyVarDetails -> m TcTyVarDetails) -> TyVar -> m TyVar -updateTcTyVarDetailsM update (TcTyVar a b c details) = TcTyVar a b c <$> update details -updateTcTyVarDetailsM _ ty_var = return ty_var mkTyVar :: Name -> Kind -> TyVar mkTyVar name kind = TyVar { varName = name |
