diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2019-06-05 08:23:03 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2019-06-13 19:04:40 -0400 |
commit | 0f0a387a0fc739f0f3043ed40635497dc0390fbf (patch) | |
tree | e3252d97341bf90d586e5226bc27398926ed8816 | |
parent | 5ce63d52fed05371edb34b4f330c33bc85a45127 (diff) | |
download | haskell-0f0a387a0fc739f0f3043ed40635497dc0390fbf.tar.gz |
Fix two places that failed the substitution invariant
The substition invariant relies on keeping the in-scope
set in sync, and we weren't always doing so, which means that
a DEBUG compiler crashes sometimes with an assertion failure
This patch fixes a couple more cases. Still not validate
clean (with -DEEBUG) but closer!
-rw-r--r-- | compiler/typecheck/Inst.hs | 9 | ||||
-rw-r--r-- | compiler/typecheck/TcCanonical.hs | 2 |
2 files changed, 5 insertions, 6 deletions
diff --git a/compiler/typecheck/Inst.hs b/compiler/typecheck/Inst.hs index daadf57313..28794aaafa 100644 --- a/compiler/typecheck/Inst.hs +++ b/compiler/typecheck/Inst.hs @@ -297,24 +297,23 @@ instTyVarsWith :: CtOrigin -> [TyVar] -> [TcType] -> TcM TCvSubst -- If they don't match, emit a kind-equality to promise that they will -- eventually do so, and thus make a kind-homongeneous substitution. instTyVarsWith orig tvs tys - = go empty_subst tvs tys + = go emptyTCvSubst tvs tys where - empty_subst = mkEmptyTCvSubst (mkInScopeSet (tyCoVarsOfTypes tys)) - go subst [] [] = return subst go subst (tv:tvs) (ty:tys) | tv_kind `tcEqType` ty_kind - = go (extendTCvSubst subst tv ty) tvs tys + = go (extendTvSubstAndInScope subst tv ty) tvs tys | otherwise = do { co <- emitWantedEq orig KindLevel Nominal ty_kind tv_kind - ; go (extendTCvSubst subst tv (ty `mkCastTy` co)) tvs tys } + ; go (extendTvSubstAndInScope subst tv (ty `mkCastTy` co)) tvs tys } where tv_kind = substTy subst (tyVarKind tv) ty_kind = tcTypeKind ty go _ _ _ = pprPanic "instTysWith" (ppr tvs $$ ppr tys) + {- ************************************************************************ * * diff --git a/compiler/typecheck/TcCanonical.hs b/compiler/typecheck/TcCanonical.hs index e0c87e0f70..c296a9eee3 100644 --- a/compiler/typecheck/TcCanonical.hs +++ b/compiler/typecheck/TcCanonical.hs @@ -1007,7 +1007,7 @@ can_eq_nc_forall ev eq_rel s1 s2 = do { let tv2 = binderVar bndr2 ; (kind_co, wanteds1) <- unify loc Nominal (tyVarKind skol_tv) (substTy subst (tyVarKind tv2)) - ; let subst' = extendTvSubst subst tv2 + ; let subst' = extendTvSubstAndInScope subst tv2 (mkCastTy (mkTyVarTy skol_tv) kind_co) ; (co, wanteds2) <- go skol_tvs subst' bndrs2 ; return ( mkTcForAllCo skol_tv kind_co co |