diff --git a/compiler/iface/BuildTyCl.hs b/compiler/iface/BuildTyCl.hs index d13d38e6ffb4197fcd45f429534c19ed5c673657..1b4017abdc1ca4e9bae46d00d30cc5cac05f1fd6 100644 --- a/compiler/iface/BuildTyCl.hs +++ b/compiler/iface/BuildTyCl.hs @@ -184,7 +184,7 @@ buildPatSyn src_name declared_infix matcher@(matcher_id,_) builder -- compatible with the pattern synonym ASSERT2((and [ univ_tvs `equalLength` univ_tvs1 , ex_tvs `equalLength` ex_tvs1 - , pat_ty `eqType` substTyUnchecked subst pat_ty1 + , pat_ty `eqType` substTy subst pat_ty1 , prov_theta `eqTypes` substTys subst prov_theta1 , req_theta `eqTypes` substTys subst req_theta1 , arg_tys `eqTypes` substTys subst arg_tys1 diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs index b7c2178fc3087b99b0354e9632221b191a052f44..f0df2700441d5341ad0d7adfbb8d0d39f6506ff5 100644 --- a/compiler/main/InteractiveEval.hs +++ b/compiler/main/InteractiveEval.hs @@ -543,13 +543,13 @@ bindLocalsAtBreakpoint hsc_env apStack_fhv (Just BreakInfo{..}) = do let tv_subst = newTyVars us free_tvs filtered_ids = [ id | (id, Just _hv) <- zip ids mb_hValues ] (_,tidy_tys) = tidyOpenTypes emptyTidyEnv $ - map (substTyUnchecked tv_subst . idType) filtered_ids + map (substTy tv_subst . idType) filtered_ids new_ids <- zipWith3M mkNewId occs tidy_tys filtered_ids result_name <- newInteractiveBinder hsc_env (mkVarOccFS result_fs) span let result_id = Id.mkVanillaGlobal result_name - (substTyUnchecked tv_subst result_ty) + (substTy tv_subst result_ty) result_ok = isPointer result_id final_ids | result_ok = result_id : new_ids diff --git a/compiler/typecheck/TcFlatten.hs b/compiler/typecheck/TcFlatten.hs index 612f8a691bcb43c58398ad7b53160d3225fbdc3e..f87a302d5c37af8292b95c6cb67a5fbad01cb499 100644 --- a/compiler/typecheck/TcFlatten.hs +++ b/compiler/typecheck/TcFlatten.hs @@ -956,7 +956,7 @@ flatten_one (TyConApp tc tys) -- Expand type synonyms that mention type families -- on the RHS; see Note [Flattening synonyms] | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc tys - , let expanded_ty = mkAppTys (substTyUnchecked (mkTopTCvSubst tenv) rhs) tys' + , let expanded_ty = mkAppTys (substTy (mkTopTCvSubst tenv) rhs) tys' = do { mode <- getMode ; let used_tcs = tyConsOfType rhs ; case mode of diff --git a/compiler/typecheck/TcMType.hs b/compiler/typecheck/TcMType.hs index bb31005c01036d72273d74a71e85ad42830d740b..a160d4ebfe358de1d4bbb25dd62fe483fc8a5a0e 100644 --- a/compiler/typecheck/TcMType.hs +++ b/compiler/typecheck/TcMType.hs @@ -307,7 +307,7 @@ tcSuperSkolTyVars :: [TyVar] -> (TCvSubst, [TcTyVar]) -- Moreover, make them "super skolems"; see comments with superSkolemTv -- see Note [Kind substitution when instantiating] -- Precondition: tyvars should be ordered by scoping -tcSuperSkolTyVars = mapAccumL tcSuperSkolTyVar (mkTopTCvSubst []) +tcSuperSkolTyVars = mapAccumL tcSuperSkolTyVar emptyTCvSubst tcSuperSkolTyVar :: TCvSubst -> TyVar -> (TCvSubst, TcTyVar) tcSuperSkolTyVar subst tv diff --git a/compiler/typecheck/TcSplice.hs b/compiler/typecheck/TcSplice.hs index fe13226c608f8d5f7aa9a7bad984986ac135638c..ac7e1b707d5917ef5bd91f1f392a00bbeee5a555 100644 --- a/compiler/typecheck/TcSplice.hs +++ b/compiler/typecheck/TcSplice.hs @@ -99,7 +99,7 @@ import GHC.Serialized import ErrUtils import Util import Unique -import VarSet ( isEmptyVarSet, filterVarSet ) +import VarSet ( isEmptyVarSet, filterVarSet, mkVarSet, elemVarSet ) import Data.List ( find ) import Data.Maybe import FastString @@ -1395,8 +1395,8 @@ reifyDataCon isGadtDataCon tys dc name = reifyName dc -- Universal tvs present in eq_spec need to be filtered out, as -- they will not appear anywhere in the type. - subst = mkTopTCvSubst (map eqSpecPair g_eq_spec) - g_unsbst_univ_tvs = filter (`notElemTCvSubst` subst) g_univ_tvs + eq_spec_tvs = mkVarSet (map eqSpecTyVar g_eq_spec) + g_unsbst_univ_tvs = filterOut (`elemVarSet` eq_spec_tvs) g_univ_tvs ; r_arg_tys <- reifyTypes (if isGadtDataCon then g_arg_tys else arg_tys) diff --git a/compiler/types/FamInstEnv.hs b/compiler/types/FamInstEnv.hs index 1167ac254c548f9c095baa05f441f1fd94c79ee2..4b4cc5d2f6e81e5461309b4fd40bd7d43c9117b8 100644 --- a/compiler/types/FamInstEnv.hs +++ b/compiler/types/FamInstEnv.hs @@ -1237,7 +1237,7 @@ normalise_tc_app tc tys ; case expandSynTyCon_maybe tc ntys of { Just (tenv, rhs, ntys') -> do { (co2, ninst_rhs) - <- normalise_type (substTyUnchecked (mkTopTCvSubst tenv) rhs) + <- normalise_type (substTy (mkTopTCvSubst tenv) rhs) ; return $ if isReflCo co2 then (args_co, mkTyConApp tc ntys) diff --git a/compiler/types/TyCoRep.hs b/compiler/types/TyCoRep.hs index 2f034d036a2eb66947001e9921ef9752c80bc7b9..a2477250f0bb5177da22a12b89cd8a18b6349bbb 100644 --- a/compiler/types/TyCoRep.hs +++ b/compiler/types/TyCoRep.hs @@ -1686,12 +1686,15 @@ zipOpenTCvSubstBinders bndrs tys is = mkInScopeSet (tyCoVarsOfTypes tys) tenv = mkVarEnv [ (tv, ty) | (Named tv _, ty) <- zip bndrs tys ] --- | Called when doing top-level substitutions. Here we expect that the --- free vars of the range of the substitution will be empty. -mkTopTCvSubst :: [(TyCoVar, Type)] -> TCvSubst -mkTopTCvSubst prs = TCvSubst emptyInScopeSet tenv cenv - where (tenv, cenv) = foldl extend (emptyTvSubstEnv, emptyCvSubstEnv) prs - extend envs (v, ty) = extendSubstEnvs envs v ty +-- | Called when doing top-level substitutions. No CoVars, please! +mkTopTCvSubst :: [(TyVar, Type)] -> TCvSubst +mkTopTCvSubst prs = + ASSERT2( onlyTyVarsAndNoCoercionTy, text "prs" <+> ppr prs ) + mkOpenTCvSubst tenv emptyCvSubstEnv + where tenv = mkVarEnv prs + onlyTyVarsAndNoCoercionTy = + and [ isTyVar tv && not (isCoercionTy ty) + | (tv, ty) <- prs ] zipTyEnv :: [TyVar] -> [Type] -> TvSubstEnv zipTyEnv tyvars tys diff --git a/compiler/types/Type.hs b/compiler/types/Type.hs index 8b426f131a5492f1c2f9038f30baba1f00ce0e95..c6d51f35f67424b77df38f9133ed88563e06c302 100644 --- a/compiler/types/Type.hs +++ b/compiler/types/Type.hs @@ -294,7 +294,11 @@ coreView :: Type -> Maybe Type -- By being non-recursive and inlined, this case analysis gets efficiently -- joined onto the case analysis that the caller is already doing coreView (TyConApp tc tys) | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc tys - = Just (mkAppTys (substTyUnchecked (mkTopTCvSubst tenv) rhs) tys') + = Just (mkAppTys (substTy (mkTopTCvSubst tenv) rhs) tys') + -- The free vars of 'rhs' should all be bound by 'tenv', so it's + -- ok to use 'substTy' here. + -- See also Note [Generating the in-scope set for a substitution] + -- in TyCoRep. -- Its important to use mkAppTys, rather than (foldl AppTy), -- because the function part might well return a -- partially-applied type constructor; indeed, usually will!