Simon Peyton Jones pushed to branch wip/T26746 at Glasgow Haskell Compiler / GHC Commits: 96c19504 by Simon Peyton Jones at 2026-01-12T23:49:44+00:00 wibbles - - - - - 3 changed files: - compiler/GHC/Core/FamInstEnv.hs - compiler/GHC/Tc/Instance/Family.hs - compiler/GHC/Tc/Solver/Equality.hs Changes: ===================================== compiler/GHC/Core/FamInstEnv.hs ===================================== @@ -1061,10 +1061,10 @@ lookup_fam_inst_env' lookup_mode (FamIE _ ie) fam match_tys , fi_tys = tpl_tys }) = do subst <- tcMatchTys tpl_tys match_tys1 return (FamInstMatch { fim_instance = item - , fim_tys = substTyVars subst tpl_tvs `chkAppend` match_tys2 - , fim_cos = assert (all (isJust . lookupCoVar subst) tpl_cvs) $ - substCoVars subst tpl_cvs - }) + , fim_tys = substTyVars subst tpl_tvs `chkAppend` match_tys2 + , fim_cos = assert (all (isJust . lookupCoVar subst) tpl_cvs) $ + substCoVars subst tpl_cvs + }) where (match_tys1, match_tys2) = split_tys tpl_tys ===================================== compiler/GHC/Tc/Instance/Family.hs ===================================== @@ -451,25 +451,27 @@ tcLookupDataFamInst_maybe fam_inst_envs tc tc_args | otherwise = Nothing --- | 'tcUnwrapNewtype_mabye' gets rid of top-level newtypes, --- potentially also looking through newtype /instances/ +-- | 'tcUnwrapNewtype_mabye' gets rid of /one layer/ of top-level newtypes -- -- It is only used by the type inference engine (specifically, when -- solving representational equality), and hence it is careful to unwrap -- only if the relevant data constructor is in scope. That's why -- it gets a GlobalRdrEnv argument. -- --- It is careful not to unwrap data/newtype instances if it can't --- unwrap the newtype inside it. Such care is necessary for proper --- error messages. +-- It is capable of unwrapping a newtype /instance/. E.g +-- data D a +-- newtype instance D Int = MkD Bool +-- Then `tcUnwrapNewtype_maybe (D Int)` will unwrap to give the `Bool` inside. +-- However, it is careful not to unwrap data/newtype instances if it can't +-- unwrap the newtype inside it; that might in the example if `MkD` was +-- not in scope. Such care is necessary for proper error messages. -- -- It does not look through type families. --- It does not normalise arguments to a tycon. +-- It does not normalise arguments to the tycon. -- --- If the result is Just ((gres, co), rep_ty), then +-- If the result is Just (gre, co, rep_ty), then -- co : ty ~R rep_ty --- gres are the GREs for the data constructors that --- had to be in scope +-- gre is the GRE for the data constructor that had to be in scope tcUnwrapNewtype_maybe :: FamInstEnvs -> GlobalRdrEnv -> Type ===================================== compiler/GHC/Tc/Solver/Equality.hs ===================================== @@ -333,14 +333,6 @@ can_eq_nc rewritten rdr_env envs ev eq_rel ty1 ps_ty1 ty2 ps_ty2 | Just ty1' <- coreView ty1 = can_eq_nc rewritten rdr_env envs ev eq_rel ty1' ps_ty1 ty2 ps_ty2 | Just ty2' <- coreView ty2 = can_eq_nc rewritten rdr_env envs ev eq_rel ty1 ps_ty1 ty2' ps_ty2 --- When working with ReprEq, unwrap newtypes. --- See Note [Eager reflexivity check] --- See Note [Unwrap newtypes first] --- This must be above the TyVarTy case, in order to guarantee (TyEq:N) --- --- We unwrap *one layer only*; `can_eq_newtype_nc` then loops back to --- `can_eq_nc`. If there is a recursive newtype, so that we keep --- unwrapping, the depth limit in `can_eq_newtype_nc` will blow up. can_eq_nc _rewritten _rdr_env _envs ev eq_rel ty1 _ ty2 _ | ReprEq <- eq_rel , TyConApp tc1 tys1 <- ty1 @@ -366,6 +358,14 @@ can_eq_nc _rewritten _rdr_env _envs ev eq_rel ty1 _ ty2 _ ok _ _ [] = False -- Oversaturated TyCon ok _ _ _ = pprPanic "can_eq_nc:mismatch" (ppr ty1 $$ ppr ty2) +-- Unwrap newtypes, when in ReprEq only +-- See Note [Eager reflexivity check] +-- See Note [Unwrap newtypes first] +-- This must be above the TyVarTy case, in order to guarantee (TyEq:N) +-- +-- We unwrap *one layer only*; `can_eq_newtype_nc` then loops back to +-- `can_eq_nc`. If there is a recursive newtype, so that we keep +-- unwrapping, the depth limit in `can_eq_newtype_nc` will blow up. can_eq_nc _rewritten rdr_env envs ev eq_rel ty1 ps_ty1 ty2 ps_ty2 | ReprEq <- eq_rel , Just stuff1 <- tcUnwrapNewtype_maybe envs rdr_env ty1 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/96c19504a9da2088d19701a5f12e49b8... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/96c19504a9da2088d19701a5f12e49b8... You're receiving this email because of your account on gitlab.haskell.org.