diff options
| author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-12-30 14:05:49 +0000 |
|---|---|---|
| committer | Matthew Pickering <matthewtpickering@gmail.com> | 2021-12-30 16:27:49 +0000 |
| commit | 4fa2b0b394c76221563a6e173340db0b6f6df84a (patch) | |
| tree | ea0fd6a0eebb50a03d9ba4a86e1d8680a7e946d8 | |
| parent | 856c0f4a93946f219e36e5782bee7e61bf1989a4 (diff) | |
| download | haskell-4fa2b0b394c76221563a6e173340db0b6f6df84a.tar.gz | |
tweaks
| -rw-r--r-- | compiler/GHC/Tc/Deriv.hs | 1 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Errors.hs | 12 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Gen/Arrow.hs | 3 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Gen/HsType.hs | 26 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Gen/Rule.hs | 4 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Solver/Monad.hs | 1 | ||||
| -rw-r--r-- | compiler/GHC/Tc/TyCl.hs | 24 | ||||
| -rw-r--r-- | compiler/GHC/Tc/TyCl/Instance.hs | 14 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Types/Origin.hs | 6 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/Env.hs | 1 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/TcMType.hs | 10 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/TcType.hs | 2 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/Unify.hs | 4 | ||||
| -rw-r--r-- | compiler/GHC/Tc/Utils/Zonk.hs | 1 | ||||
| -rw-r--r-- | compiler/GHC/Types/Var.hs | 3 | ||||
| -rw-r--r-- | testsuite/tests/polykinds/T16221a.stderr | 4 |
16 files changed, 59 insertions, 57 deletions
diff --git a/compiler/GHC/Tc/Deriv.hs b/compiler/GHC/Tc/Deriv.hs index 10103fa16d..b03aaea65b 100644 --- a/compiler/GHC/Tc/Deriv.hs +++ b/compiler/GHC/Tc/Deriv.hs @@ -646,7 +646,6 @@ deriveStandalone (L loc (DerivDecl _ deriv_ty mb_lderiv_strat overlap_mode)) skol_info <- mkSkolemInfo (DerivSkol ty) return $ (tcExtendTyVarEnv skol_info tvs, tvs) Nothing -> return (\f -> f emptyTCvSubst [], []) - -- MP: Issue here because we don't yet have the Type to put in this hole ; (cls_tvs, deriv_ctxt, cls, inst_tys) <- extend_by $ \_subst _vars -> tcStandaloneDerivInstType ctxt deriv_ty diff --git a/compiler/GHC/Tc/Errors.hs b/compiler/GHC/Tc/Errors.hs index d202312fbc..9f79a9fc35 100644 --- a/compiler/GHC/Tc/Errors.hs +++ b/compiler/GHC/Tc/Errors.hs @@ -94,7 +94,6 @@ import Data.Ord ( comparing ) -- import Data.Semigroup ( Semigroup ) import qualified Data.Semigroup as Semigroup import Data.Bifunctor -import GHC.Utils.Trace {- @@ -230,7 +229,7 @@ report_unsolved type_errors expr_holes ; wanted <- zonkWC wanted -- Zonk to reveal all information - ; let tidy_env = tidyFreeTyCoVars emptyTidyEnv free_tvs; + ; let tidy_env = tidyFreeTyCoVars emptyTidyEnv free_tvs free_tvs = filterOut isCoVar $ tyCoVarsOfWCList wanted -- tyCoVarsOfWC returns free coercion *holes*, even though @@ -3172,15 +3171,20 @@ pprSkols ctxt tvs group_skolems :: UM.UniqMap SkolemInfo ([(TcTyVar, Int)]) group_skolems = bagToList <$> UM.listToUniqMap_C unionBags [(skolemSkolInfo tv, unitBag (tv, n)) | tv <- tvs | n <- [0..]] - skolem_list = sortBy (comparing (sort . map snd . snd . pprTraceIt "sort")) (UM.nonDetEltsUniqMap group_skolems) + skolem_list = sortBy (comparing (sort . map snd . snd)) (UM.nonDetEltsUniqMap group_skolems) + + no_msg = text "No skolem info - we could not find the origin of the following variables" <+> ppr tvs + $$ text "This should not happen, please report it as a bug following the instructions at:" + $$ text "https://gitlab.haskell.org/ghc/ghc/wikis/report-a-bug" pp_one (UnkSkol cs, tvs) = vcat [ hang (pprQuotedList tvs) 2 (is_or_are tvs "a" "(rigid, skolem)") , nest 2 (text "of unknown origin") - , prettyCallStackDoc cs , nest 2 (text "bound at" <+> ppr (foldr1 combineSrcSpans (map getSrcSpan tvs))) + , no_msg + , prettyCallStackDoc cs ] pp_one (RuntimeUnkSkol, tvs) = hang (pprQuotedList tvs) diff --git a/compiler/GHC/Tc/Gen/Arrow.hs b/compiler/GHC/Tc/Gen/Arrow.hs index c9c97fc476..b5a7c5a7b2 100644 --- a/compiler/GHC/Tc/Gen/Arrow.hs +++ b/compiler/GHC/Tc/Gen/Arrow.hs @@ -184,7 +184,8 @@ tc_cmd env (HsCmdIf x fun@(SyntaxExprRn {}) pred b1 b2) res_ty -- Rebindable syn -- For arrows, need ifThenElse :: forall r. T -> r -> r -> r -- because we're going to apply it to the environment, not -- the return value. - ; (_, [r_tv]) <- tcInstSkolTyVars unkSkol [alphaTyVar] + ; skol_info <- mkSkolemInfo ArrowReboundIfSkol + ; (_, [r_tv]) <- tcInstSkolTyVars skol_info [alphaTyVar] ; let r_ty = mkTyVarTy r_tv ; checkTc (not (r_tv `elemVarSet` tyCoVarsOfType pred_ty)) TcRnArrowIfThenElsePredDependsOnResultTy diff --git a/compiler/GHC/Tc/Gen/HsType.hs b/compiler/GHC/Tc/Gen/HsType.hs index 786fbd0f2a..96730dadbc 100644 --- a/compiler/GHC/Tc/Gen/HsType.hs +++ b/compiler/GHC/Tc/Gen/HsType.hs @@ -1977,7 +1977,6 @@ tcTyVar :: TcTyMode -> Name -> TcM (TcType, TcKind) tcTyVar mode name -- Could be a tyvar, a tycon, or a datacon = do { traceTc "lk1" (ppr name) ; thing <- tcLookup name --- ; pprTraceM "tcTyVar" (ppr name $$ ppr thing) ; case thing of ATyVar _ tv -> return (mkTyVarTy tv, tyVarKind tv) @@ -2551,9 +2550,9 @@ kcCheckDeclHeader_sig kisig name flav ; (vis_tcbs, concat -> explicit_tv_prs) <- mapAndUnzipM (zipped_to_tcb skol_info) zipped_binders ; skol_info <- mkSkolemInfo (TyConSkol flav name) - ; (tclvl, wanted, (implicit_tvs, (invis_binders, r_ki))) + ; (tclvl, wanted, (implicit_tvs, (invis_binders, skol_tvs, r_ki))) <- pushLevelAndSolveEqualitiesX "kcCheckDeclHeader_sig" $ -- #16687 - bindImplicitTKBndrs_Tv implicit_nms $ + bindImplicitTKBndrs_Tv implicit_nms $ tcExtendNameTyVarEnv explicit_tv_prs $ do { -- Check that inline kind annotations on binders are valid. -- For example: @@ -2593,12 +2592,14 @@ kcCheckDeclHeader_sig kisig name flav -- -- Here we unify Maybe k ~ Maybe j - ; whenIsJust m_res_ki $ \res_ki -> do - discardResult $ - tcExtendTyVarEnv skol_info (mapMaybe tyCoBinderVar_maybe invis_binders) $ \subst _vars -> -- See Note [discardResult in kcCheckDeclHeader_sig] + ; + tcExtendTyVarEnv skol_info (mapMaybe tyCoBinderVar_maybe invis_binders) $ \subst skol_tvs -> do + -- See Note [discardResult in kcCheckDeclHeader_sig] + whenIsJust m_res_ki $ \res_ki -> do + discardResult $ unifyKind Nothing (substTy subst r_ki) res_ki - ; return (invis_binders, r_ki) } + return (invis_binders, skol_tvs, r_ki) } -- Convert each invisible TyCoBinder to TyConBinder for tyConBinders. ; invis_tcbs <- mapM invis_to_tcb invis_binders @@ -2613,7 +2614,7 @@ kcCheckDeclHeader_sig kisig name flav tc = mkTcTyCon name tcbs r_ki all_tv_prs True flav -- Check that there are no unsolved equalities - ; reportUnsolvedEqualities skol_info [] tclvl wanted + ; reportUnsolvedEqualities skol_info skol_tvs tclvl wanted ; traceTc "kcCheckDeclHeader_sig done:" $ vcat [ text "tyConName = " <+> ppr (tyConName tc) @@ -3296,7 +3297,6 @@ bindExplicitTKBndrsX skol_mode@(SM { sm_parent = check_parent, sm_kind = ctxt_ki = do { kind <- tc_lhs_kind_sig tc_ki_mode (TyVarBndrKindCtxt name) lhs_kind ; newTyVarBndr skol_mode name kind } - newTyVarBndr :: SkolemMode -> Name -> Kind -> TcM TcTyVar newTyVarBndr (SM { sm_clone = clone, sm_tvtv = tvtv }) name kind = do { name <- case clone of @@ -3490,13 +3490,7 @@ bindTyClTyVars skol_info tycon_name thing_inside ; let scoped_prs = tcTyConScopedTyVars tycon res_kind = tyConResKind tycon binders = tyConBinders tycon - -- ; pprTraceM "bindTyClTyVars" (ppr scoped_prs $$ ppr binders) --- ; let scoped_prs' = map skolemise_pair scoped_prs - -- ; lcl_env <- tcl_env <$> getLclEnv --- ; th_body <- tcl_bndrs <$> getLclEnv --- ; let (_, binders') = mapAccumL skolemise_binders emptyTCvSubst binders - ; - tcExtendTyVarEnv skol_info (binderVars binders) $ \subst tc_vars -> + ; tcExtendTyVarEnv skol_info (binderVars binders) $ \subst tc_vars -> let scoped_prs' = map (second (expect_tv . substTyVar subst)) scoped_prs in tcExtendNameTyVarEnv scoped_prs' $ thing_inside tycon binders tc_vars res_kind } diff --git a/compiler/GHC/Tc/Gen/Rule.hs b/compiler/GHC/Tc/Gen/Rule.hs index 914e1cc653..30a0f4aa6b 100644 --- a/compiler/GHC/Tc/Gen/Rule.hs +++ b/compiler/GHC/Tc/Gen/Rule.hs @@ -157,8 +157,7 @@ tcRule (HsRule { rd_ext = ext , ppr qtkvs , ppr rule_ty , ppr ty_bndrs - , ppr ( - (qtkvs ++ tpl_ids)) + , ppr (qtkvs ++ tpl_ids) , vcat [ ppr id <+> dcolon <+> ppr (idType id) | id <- tpl_ids ] ]) @@ -195,7 +194,6 @@ generateRuleConstraints rule_name ty_bndrs tm_bndrs lhs rhs -- constraints, which we should not forget about. -- It may mention the skolem type variables bound by -- the RULE. c.f. #10072 --- ; pprTraceM "tv_bndrs" (ppr tv_bndrs) ; tcExtendNameTyVarEnv [(tyVarName tv, tv) | tv <- tv_bndrs] $ tcExtendIdEnv id_bndrs $ do { -- See Note [Solve order for RULES] diff --git a/compiler/GHC/Tc/Solver/Monad.hs b/compiler/GHC/Tc/Solver/Monad.hs index fbd799b42d..71512cd017 100644 --- a/compiler/GHC/Tc/Solver/Monad.hs +++ b/compiler/GHC/Tc/Solver/Monad.hs @@ -1212,7 +1212,6 @@ data TcSEnv --------------- newtype TcS a = TcS { unTcS :: TcSEnv -> TcM a } deriving (Functor) - -- | Smart constructor for 'TcS', as describe in Note [The one-shot state -- monad trick] in "GHC.Utils.Monad". mkTcS :: (TcSEnv -> TcM a) -> TcS a diff --git a/compiler/GHC/Tc/TyCl.hs b/compiler/GHC/Tc/TyCl.hs index 1519ccd04d..66b515cb55 100644 --- a/compiler/GHC/Tc/TyCl.hs +++ b/compiler/GHC/Tc/TyCl.hs @@ -773,7 +773,8 @@ generaliseTyClDecl inferred_tc_env (L _ decl) skolemise_tc_tycon tc_name = do { let tc = lookupNameEnv_NF inferred_tc_env tc_name -- This lookup should not fail - ; scoped_prs <- mapSndM zonkAndSkolemise (tcTyConScopedTyVars tc) + ; skol_info <- mkSkolemInfo (TyConSkol (tyConFlavour tc) tc_name ) + ; scoped_prs <- mapSndM (zonkAndSkolemise skol_info) (tcTyConScopedTyVars tc) ; return (tc, scoped_prs) } zonk_tc_tycon :: (TcTyCon, ScopedPairs) -> TcM (TcTyCon, ScopedPairs, TcKind) @@ -2910,6 +2911,7 @@ tcDataDefn err_ctxt roles_info tc_name do { gadt_syntax <- dataDeclChecks tc_name new_or_data ctxt cons -- see Note [Datatype return kinds] ; (extra_bndrs, final_res_kind) <- etaExpandAlgTyCon (binderVars tycon_binders) res_kind + ; tcExtendTyVarEnv skol_info (binderVars extra_bndrs) $ \_subst extra_tvs -> do { ; tcg_env <- getGblEnv ; let hsc_src = tcg_src tcg_env @@ -2941,10 +2943,11 @@ tcDataDefn err_ctxt roles_info tc_name ; tycon <- fixM $ \ rec_tycon -> do { let final_bndrs = tycon_binders `chkAppend` extra_bndrs + final_tvs = skol_tvs `chkAppend` extra_tvs roles = roles_info tc_name ; data_cons <- tcConDecls new_or_data DDataType - rec_tycon final_bndrs final_res_kind + rec_tycon final_bndrs final_tvs final_res_kind cons ; tc_rhs <- mk_tc_rhs hsc_src rec_tycon data_cons ; tc_rep_nm <- newTyConRepName tc_name @@ -2961,7 +2964,7 @@ tcDataDefn err_ctxt roles_info tc_name , di_clauses = derivs , di_ctxt = err_ctxt } ; traceTc "tcDataDefn" (ppr tc_name $$ ppr tycon_binders $$ ppr extra_bndrs) - ; return (tycon, [deriv_info]) } + ; return (tycon, [deriv_info]) } } where skol_info_anon = TyConSkol flav tc_name flav = newOrDataToFlavour new_or_data @@ -3377,11 +3380,12 @@ tcConDecls :: NewOrData -> DataDeclInfo -> KnotTied TyCon -- Representation TyCon -> [TyConBinder] -- Binders of representation TyCon + -> [TcTyVar] -- Skolemised binder vars (use these when typechecking things) -> TcKind -- Result kind -> [LConDecl GhcRn] -> TcM [DataCon] -tcConDecls new_or_data dd_info rep_tycon tmpl_bndrs res_kind +tcConDecls new_or_data dd_info rep_tycon tmpl_bndrs skol_tvs res_kind = concatMapM $ addLocMA $ - tcConDecl new_or_data dd_info rep_tycon tmpl_bndrs res_kind + tcConDecl new_or_data dd_info rep_tycon tmpl_bndrs skol_tvs res_kind (mkTyConTagMap rep_tycon) -- mkTyConTagMap: it's important that we pay for tag allocation here, -- once per TyCon. See Note [Constructor tag allocation], fixes #14657 @@ -3390,12 +3394,13 @@ tcConDecl :: NewOrData -> DataDeclInfo -> KnotTied TyCon -- Representation tycon. Knot-tied! -> [TyConBinder] -- Binders of representation TyCon + -> [TcTyVar] -- Skolemised binders -> TcKind -- Result kind -> NameEnv ConTag -> ConDecl GhcRn -> TcM [DataCon] -tcConDecl new_or_data dd_info rep_tycon tc_bndrs res_kind tag_map +tcConDecl new_or_data dd_info rep_tycon tc_bndrs skol_tvs res_kind tag_map (ConDeclH98 { con_name = lname@(L _ name) , con_ex_tvs = explicit_tkv_nms , con_mb_cxt = hs_ctxt @@ -3443,9 +3448,8 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs res_kind tag_map ; kvs <- kindGeneralizeAll skol_info fake_ty - -- ; let skol_tvs = tc_tvs ++ kvs ++ binderVars exp_tvbndrs - -- ; pprTraceM "skol_tvs" (ppr tc_tvs $$ ppr kvs $$ ppr (binderVars (exp_tvbndrs))) - ; reportUnsolvedEqualities skol_info [] tclvl wanted + ; let all_skol_tvs = skol_tvs ++ kvs ++ binderVars exp_tvbndrs + ; reportUnsolvedEqualities skol_info all_skol_tvs tclvl wanted -- The skol_info claims that all the variables are bound -- by the data constructor decl, whereas actually the -- univ_tvs are bound by the data type decl itself. It @@ -3486,7 +3490,7 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs res_kind tag_map ; return [dc] } -tcConDecl new_or_data dd_info rep_tycon tc_bndrs _res_kind tag_map +tcConDecl new_or_data dd_info rep_tycon tc_bndrs _skol_tvs _res_kind tag_map -- NB: don't use res_kind here, as it's ill-scoped. Instead, -- we get the res_kind by typechecking the result type. (ConDeclGADT { con_names = names diff --git a/compiler/GHC/Tc/TyCl/Instance.hs b/compiler/GHC/Tc/TyCl/Instance.hs index 73053eefa0..0a5f2c09ef 100644 --- a/compiler/GHC/Tc/TyCl/Instance.hs +++ b/compiler/GHC/Tc/TyCl/Instance.hs @@ -691,7 +691,7 @@ tcDataFamInstDecl mb_clsinfo tv_skol_env ; gadt_syntax <- dataDeclChecks fam_name new_or_data hs_ctxt hs_cons -- Do /not/ check that the number of patterns = tyConArity fam_tc -- See [Arity of data families] in GHC.Core.FamInstEnv - ; (qtvs, pats, _unzonked_res_kind, res_kind, stupid_theta) + ; (qtvs, pats, res_kind, stupid_theta) <- tcDataFamInstHeader mb_clsinfo fam_tc outer_bndrs fixity hs_ctxt hs_pats m_ksig new_or_data -- Eta-reduce the axiom if possible @@ -739,11 +739,11 @@ tcDataFamInstDecl mb_clsinfo tv_skol_env , text "eta_tcbs" <+> ppr eta_tcbs ] ; skol_info <- mkSkolemInfo FamInstSkol ; (rep_tc, axiom) <- fixM $ \ ~(rec_rep_tc, _) -> - do { data_cons <- tcExtendTyVarEnv skol_info qtvs $ \subst _tvs -> + do { data_cons <- tcExtendTyVarEnv skol_info qtvs $ \subst tvs -> -- For H98 decls, the tyvars scope -- over the data constructors tcConDecls new_or_data (DDataInstance orig_res_ty) - rec_rep_tc ty_binders (substTy subst final_res_kind) + rec_rep_tc ty_binders tvs (substTy subst final_res_kind) hs_cons ; rep_tc_name <- newFamInstTyConName lfam_name pats @@ -865,7 +865,7 @@ tcDataFamInstHeader -> LexicalFixity -> Maybe (LHsContext GhcRn) -> HsTyPats GhcRn -> Maybe (LHsKind GhcRn) -> NewOrData - -> TcM ([TyVar], [Type], TcKind, Kind, ThetaType) + -> TcM ([TyVar], [Type], Kind, ThetaType) -- The "header" of a data family instance is the part other than -- the data constructors themselves -- e.g. data instance D [a] :: * -> * where ... @@ -874,7 +874,7 @@ tcDataFamInstHeader mb_clsinfo fam_tc outer_bndrs fixity hs_ctxt hs_pats m_ksig new_or_data = do { traceTc "tcDataFamInstHeader {" (ppr fam_tc <+> ppr hs_pats) ; skol_info <- mkSkolemInfo FamInstSkol - ; (tclvl, wanted, (scoped_tvs, (stupid_theta, lhs_ty, unzonked_master_res_kind, instance_res_kind))) + ; (tclvl, wanted, (scoped_tvs, (stupid_theta, lhs_ty, master_res_kind, instance_res_kind))) <- pushLevelAndSolveEqualitiesX "tcDataFamInstHeader" $ bindOuterFamEqnTKBndrs skol_info outer_bndrs $ do { stupid_theta <- tcHsContext hs_ctxt @@ -923,7 +923,7 @@ tcDataFamInstHeader mb_clsinfo fam_tc outer_bndrs fixity ; (ze, qtvs) <- zonkTyBndrsX ze qtvs ; lhs_ty <- zonkTcTypeToTypeX ze lhs_ty ; stupid_theta <- zonkTcTypesToTypesX ze stupid_theta - ; master_res_kind <- zonkTcTypeToTypeX ze unzonked_master_res_kind + ; master_res_kind <- zonkTcTypeToTypeX ze master_res_kind ; instance_res_kind <- zonkTcTypeToTypeX ze instance_res_kind -- We check that res_kind is OK with checkDataKindSig in @@ -941,7 +941,7 @@ tcDataFamInstHeader mb_clsinfo fam_tc outer_bndrs fixity Just (_, pats) -> pure pats Nothing -> pprPanic "tcDataFamInstHeader" (ppr lhs_ty) - ; return (qtvs, pats, unzonked_master_res_kind, master_res_kind, stupid_theta) } + ; return (qtvs, pats, master_res_kind, stupid_theta) } where fam_name = tyConName fam_tc data_ctxt = DataKindCtxt fam_name diff --git a/compiler/GHC/Tc/Types/Origin.hs b/compiler/GHC/Tc/Types/Origin.hs index 9138830812..5e3bdc5a4e 100644 --- a/compiler/GHC/Tc/Types/Origin.hs +++ b/compiler/GHC/Tc/Types/Origin.hs @@ -57,7 +57,6 @@ import GHC.Data.FastString import GHC.Utils.Outputable import GHC.Utils.Panic -import GHC.Utils.Trace import GHC.Stack import GHC.Utils.Monad import GHC.Types.Unique @@ -263,6 +262,8 @@ data SkolemInfoAnon | RuntimeUnkSkol -- Runtime skolem from the GHCi debugger #14628 + | ArrowReboundIfSkol -- Bound by the expected type of the rebound arrow ifThenElse command. + | UnkSkol CallStack @@ -310,11 +311,12 @@ pprSkolInfo ReifySkol = text "the type being reified" pprSkolInfo (QuantCtxtSkol {}) = text "a quantified context" pprSkolInfo RuntimeUnkSkol = text "Unknown type from GHCi runtime" +pprSkolInfo ArrowReboundIfSkol = text "the expected type of a rebound if-then-else command" -- unkSkol -- For type variables the others are dealt with by pprSkolTvBinding. -- For Insts, these cases should not happen -pprSkolInfo (UnkSkol cs) = warnPprTrace True (text "pprSkolInfo: unkSkol") $ text "UnkSkol" $$ prettyCallStackDoc cs +pprSkolInfo (UnkSkol cs) = text "UnkSkol (please report this as a bug)" $$ prettyCallStackDoc cs pprSigSkolInfo :: UserTypeCtxt -> TcType -> SDoc diff --git a/compiler/GHC/Tc/Utils/Env.hs b/compiler/GHC/Tc/Utils/Env.hs index 611f44e03b..0ebe0c5e5d 100644 --- a/compiler/GHC/Tc/Utils/Env.hs +++ b/compiler/GHC/Tc/Utils/Env.hs @@ -539,6 +539,7 @@ tcExtendTyVarEnv skol_info tvs thing_inside = let (subst, tvs') = mapAccumL go emptyTCvSubst tvs in tcExtendNameTyVarEnv tvs' (thing_inside subst (map snd tvs')) where + -- Perhaps should use tcInstSkolTyVars here, that does a lot more though. go subst tv = let tv' = mkTcTyVar (tyVarName tv) (substTy subst (tyVarKind tv)) (vanillaSkolemTv skol_info) in (extendTvSubstWithClone subst tv tv', (tyVarName tv, tv')) diff --git a/compiler/GHC/Tc/Utils/TcMType.hs b/compiler/GHC/Tc/Utils/TcMType.hs index b6fc58d87c..ee99cafbda 100644 --- a/compiler/GHC/Tc/Utils/TcMType.hs +++ b/compiler/GHC/Tc/Utils/TcMType.hs @@ -930,7 +930,7 @@ readMetaTyVar :: TyVar -> TcM MetaDetails readMetaTyVar tyvar = assertPpr (isMetaTyVar tyvar) (ppr tyvar) $ readMutVar (metaTyVarRef tyvar) -isFilledMetaTyVar_maybe :: HasCallStack => TcTyVar -> TcM (Maybe Type) +isFilledMetaTyVar_maybe :: TcTyVar -> TcM (Maybe Type) isFilledMetaTyVar_maybe tv | isTcTyVar tv , MetaTv { mtv_ref = ref } <- tcTyVarDetails tv @@ -1754,19 +1754,19 @@ isQuantifiableTv outer_tclvl tcv | otherwise = False -zonkAndSkolemise :: TcTyCoVar -> TcM TcTyCoVar +zonkAndSkolemise :: SkolemInfo -> TcTyCoVar -> TcM TcTyCoVar -- A tyvar binder is never a unification variable (TauTv), -- rather it is always a skolem. It *might* be a TyVarTv. -- (Because non-CUSK type declarations use TyVarTvs.) -- Regardless, it may have a kind that has not yet been zonked, -- and may include kind unification variables. -zonkAndSkolemise tyvar +zonkAndSkolemise skol_info tyvar | isTyVarTyVar tyvar -- We want to preserve the binding location of the original TyVarTv. -- This is important for error messages. If we don't do this, then -- we get bad locations in, e.g., typecheck/should_fail/T2688 = do { zonked_tyvar <- zonkTcTyVarToTyVar tyvar - ; skolemiseQuantifiedTyVar unkSkol zonked_tyvar } + ; skolemiseQuantifiedTyVar skol_info zonked_tyvar } | otherwise = assertPpr (isImmutableTyVar tyvar || isCoVar tyvar) (pprTyVar tyvar) $ @@ -2496,7 +2496,7 @@ zonkTcTyVar tv = zonk_kind_and_return where zonk_kind_and_return = do { z_tv <- zonkTyCoVarKind tv - ; mkTyVarTy <$> pure z_tv + ; return (mkTyVarTy z_tv) } -- Variant that assumes that any result of zonking is still a TyVar. diff --git a/compiler/GHC/Tc/Utils/TcType.hs b/compiler/GHC/Tc/Utils/TcType.hs index c93c012467..569a7b8363 100644 --- a/compiler/GHC/Tc/Utils/TcType.hs +++ b/compiler/GHC/Tc/Utils/TcType.hs @@ -684,7 +684,7 @@ tcTyVarLevel :: TcTyVar -> TcLevel tcTyVarLevel tv = case tcTyVarDetails tv of MetaTv { mtv_tclvl = tv_lvl } -> tv_lvl - SkolemTv _ tv_lvl _ -> tv_lvl + SkolemTv _ tv_lvl _ -> tv_lvl RuntimeUnk -> topTcLevel diff --git a/compiler/GHC/Tc/Utils/Unify.hs b/compiler/GHC/Tc/Utils/Unify.hs index d75fef9ccb..9e822da9b6 100644 --- a/compiler/GHC/Tc/Utils/Unify.hs +++ b/compiler/GHC/Tc/Utils/Unify.hs @@ -957,7 +957,9 @@ emitResidualTvConstraint skol_info skol_tvs tclvl wanted buildTvImplication :: SkolemInfo -> [TcTyVar] -> TcLevel -> WantedConstraints -> TcM Implication buildTvImplication skol_info skol_tvs tclvl wanted - = do { ev_binds <- newNoTcEvBinds -- Used for equalities only, so all the constraints + = + assertPpr (all (isSkolemTyVar <||> isTyVarTyVar) skol_tvs) (ppr skol_tvs) $ + do { ev_binds <- newNoTcEvBinds -- Used for equalities only, so all the constraints -- are solved by filling in coercion holes, not -- by creating a value-level evidence binding ; implic <- newImplication diff --git a/compiler/GHC/Tc/Utils/Zonk.hs b/compiler/GHC/Tc/Utils/Zonk.hs index 52336fefaa..fec8d90d5d 100644 --- a/compiler/GHC/Tc/Utils/Zonk.hs +++ b/compiler/GHC/Tc/Utils/Zonk.hs @@ -3,7 +3,6 @@ {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -Wno-incomplete-record-updates #-} -{-# LANGUAGE LambdaCase #-} {- (c) The University of Glasgow 2006 diff --git a/compiler/GHC/Types/Var.hs b/compiler/GHC/Types/Var.hs index b2d397830a..24754741c0 100644 --- a/compiler/GHC/Types/Var.hs +++ b/compiler/GHC/Types/Var.hs @@ -113,7 +113,6 @@ import GHC.Utils.Panic.Plain import Data.Data - {- ************************************************************************ * * @@ -749,7 +748,6 @@ updateTyVarKindM update tv = do { k' <- update (tyVarKind tv) ; return $ tv {varType = k'} } - mkTyVar :: Name -> Kind -> TyVar mkTyVar name kind = TyVar { varName = name , realUnique = getKey (nameUnique name) @@ -768,6 +766,7 @@ mkTcTyVar name kind details tcTyVarDetails :: TyVar -> TcTyVarDetails -- See Note [TcTyVars and TyVars in the typechecker] in GHC.Tc.Utils.TcType tcTyVarDetails (TcTyVar { tc_tv_details = details }) = details +-- MP: This should never happen, but it does. Future work is to turn this into a panic. tcTyVarDetails (TyVar {}) = vanillaSkolemTvUnk --pprTrace "tcTyVarDetailsTyVar" (prettyCallStackDoc $ varOrigin v) vanillaSkolemTvUnk --pprTrace "tyVar" (text $ show (unsafePerformIO $ whereFrom tv)) $ vanillaSkolemTvUnk tcTyVarDetails var = pprPanic "tcTyVarDetails" (ppr var <+> dcolon <+> pprKind (tyVarKind var)) diff --git a/testsuite/tests/polykinds/T16221a.stderr b/testsuite/tests/polykinds/T16221a.stderr index 06fb5e0af1..0a8848853c 100644 --- a/testsuite/tests/polykinds/T16221a.stderr +++ b/testsuite/tests/polykinds/T16221a.stderr @@ -1,7 +1,7 @@ T16221a.hs:6:49: error: - • Expected kind ‘k’, but ‘b’ has kind ‘k1’ - ‘k1’ is a rigid type variable bound by + • Expected kind ‘k’, but ‘b’ has kind ‘k2’ + ‘k2’ is a rigid type variable bound by an explicit forall k (b :: k) at T16221a.hs:6:20 ‘k’ is a rigid type variable bound by |
