[Git][ghc/ghc][wip/T23109] Make newtype classes pretend to be injective

Simon Peyton Jones (@simonpj) gitlab at gitlab.haskell.org
Tue Apr 30 13:10:01 UTC 2024



Simon Peyton Jones pushed to branch wip/T23109 at Glasgow Haskell Compiler / GHC


Commits:
6ae47cf0 by Simon Peyton Jones at 2024-04-30T14:08:29+01:00
Make newtype classes pretend to be injective

- - - - -


2 changed files:

- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/TyCon.hs


Changes:

=====================================
compiler/GHC/Core/Opt/Arity.hs
=====================================
@@ -52,7 +52,7 @@ import GHC.Core
 import GHC.Core.FVs
 import GHC.Core.Utils
 import GHC.Core.DataCon
-import GHC.Core.TyCon     ( TyCon, tyConArity )
+import GHC.Core.TyCon     ( TyCon, tyConArity, isInjectiveTyCon )
 import GHC.Core.TyCon.RecWalk     ( initRecTc, checkRecTc )
 import GHC.Core.Predicate ( isDictTy, isEvVar, isCallStackPredTy, isCallStackTy )
 import GHC.Core.Multiplicity
@@ -3091,6 +3091,7 @@ push_data_con to_tc to_tc_arg_tys dc dc_args co role
   = assertPpr (eqType from_ty dc_app_ty)     dump_doc $
     assertPpr (equalLength val_args arg_tys) dump_doc $
     assertPpr (role == coercionRole co)      dump_doc $
+    assertPpr (isInjectiveTyCon to_tc role)  dump_doc $
     (dc, to_tc_arg_tys, to_ex_args ++ new_val_args)
   where
     Pair from_ty to_ty = coercionKind co


=====================================
compiler/GHC/Core/TyCon.hs
=====================================
@@ -2053,8 +2053,9 @@ isInjectiveTyCon (TyCon { tyConDetails = details }) role
     go_alg_rep (SumTyCon {})      _               = True
     go_alg_rep (DataTyCon {})     _               = True
     go_alg_rep (AbstractTyCon {}) _               = False
--- Not sure why we need this
---    go_alg_rep (NewTyCon {})      (ClassTyCon {}) = True -- See Note [Newtype classes]
+    go_alg_rep (NewTyCon {})      (ClassTyCon {}) = True -- See Note [Newtype classes]
+       -- ToDo: Lint and pushDataCon both check for injective TyCons in SelCo
+       -- So newtype classes need to pretend to be injective.
     go_alg_rep (NewTyCon {})      _               = False
 
 {- Note [Newtype classes]



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6ae47cf0696b9a4bc6ecfee77676758edfaec5dc

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6ae47cf0696b9a4bc6ecfee77676758edfaec5dc
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240430/ff4fcf1a/attachment-0001.html>


More information about the ghc-commits mailing list