[Git][ghc/ghc][wip/tyconapp-opts] Fix it

Ben Gamari gitlab at gitlab.haskell.org
Tue Nov 10 22:23:25 UTC 2020



Ben Gamari pushed to branch wip/tyconapp-opts at Glasgow Haskell Compiler / GHC


Commits:
e0c03f29 by Ben Gamari at 2020-11-10T17:23:11-05:00
Fix it

- - - - -


4 changed files:

- compiler/GHC/Builtin/Types/Prim.hs
- + compiler/GHC/Builtin/Types/Prim.hs-boot
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Tc/Utils/TcMType.hs


Changes:

=====================================
compiler/GHC/Builtin/Types/Prim.hs
=====================================
@@ -551,37 +551,6 @@ mkPrimTcName built_in_syntax occ key tycon
   = mkWiredInName gHC_PRIM (mkTcOccFS occ) key (mkATyCon tycon) built_in_syntax
 
 -----------------------------
--- | Given a RuntimeRep, applies TYPE to it.
--- see Note [TYPE and RuntimeRep]
-tYPE :: Type -> Type
-tYPE (TyConApp tc [])
-  | tc `hasKey` liftedRepDataConKey = liftedTypeKind  -- TYPE 'LiftedPtrRep
-tYPE rr = TyConApp tYPETyCon [rr]
-
--- Note [Prefer Type over TYPE 'LiftedPtrRep]
--- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
--- The Core of nearly any program will have numerous occurrences of
--- @TYPE 'LiftedPtrRep@ floating about. Consequently, we try hard to ensure
--- that operations on such types are efficient:
---
---   * Instead of representing the lifted kind as
---     @TyConApp tYPETyCon [liftedRepDataCon]@ we rather prefer to
---     use the 'GHC.Types.Type' type synonym (available in GHC as
---     'TysPrim.liftedTypeKind'). Note only is this a smaller AST but it also
---     guarantees sharing on the heap.
---
---   * To avoid allocating 'TyConApp' constructors 'TysPrim.tYPE'
---     catches the lifted case and uses `liftedTypeKind` instead of building an
---     application.
---
---   * Similarly, 'Type.mkTyConApp' catches applications of TYPE and
---     handles them using 'TysPrim.tYPE', ensuring that it benefits from the
---     optimisation described above.
---
---   * Since 'liftedTypeKind' is a nullary type synonym application,
---     it benefits from the optimisation described in Note [Comparing nullary
---     type synonyms] in "GHC.Core.Type".
 
 -- Given a Multiplicity, applies FUN to it.
 functionWithMultiplicity :: Type -> Type


=====================================
compiler/GHC/Builtin/Types/Prim.hs-boot
=====================================
@@ -0,0 +1,5 @@
+module GHC.Builtin.Types.Prim where
+
+import GHC.Core.TyCon
+
+tYPETyCon :: TyCon


=====================================
compiler/GHC/Core/TyCo/Rep.hs
=====================================
@@ -52,6 +52,7 @@ module GHC.Core.TyCo.Rep (
         mkVisFunTyMany, mkVisFunTysMany,
         mkInvisFunTyMany, mkInvisFunTysMany,
         mkTyConApp,
+        tYPE,
 
         -- * Functions over binders
         TyCoBinder(..), TyCoVarBinder, TyBinder,
@@ -90,8 +91,9 @@ import GHC.Core.TyCon
 import GHC.Core.Coercion.Axiom
 
 -- others
-import GHC.Builtin.Names ( liftedTypeKindTyConKey, manyDataConKey )
-import {-# SOURCE #-} GHC.Builtin.Types ( liftedTypeKindTyCon, manyDataConTy )
+import GHC.Builtin.Names ( liftedTypeKindTyConKey, liftedRepDataConKey, manyDataConKey, tYPETyConKey )
+import {-# SOURCE #-} GHC.Builtin.Types ( liftedTypeKindTyCon, liftedTypeKind, manyDataConTy )
+import {-# SOURCE #-} GHC.Builtin.Types.Prim ( tYPETyCon )
 import GHC.Types.Basic ( LeftOrRight(..), pickLR )
 import GHC.Types.Unique ( hasKey )
 import GHC.Utils.Outputable
@@ -1018,14 +1020,46 @@ mkTyConApp tycon tys
   -- avoid reboxing every time `mkTyConApp` is called.
   = ASSERT2( null tys, ppr tycon $$ ppr tys )
     manyDataConTy
-  -- See Note [Prefer Type over TYPE 'LiftedPtrRep] in GHC.BuiltIn.Types.Prim.
-  | tycon == tYPETyCon
+  -- See Note [Prefer Type over TYPE 'LiftedPtrRep].
+  | tycon `hasKey` tYPETyConKey
   , [rep] <- tys
   = tYPE rep
   -- The catch-all case
   | otherwise
   = TyConApp tycon tys
 
+-- Note [Prefer Type over TYPE 'LiftedPtrRep]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--
+-- The Core of nearly any program will have numerous occurrences of
+-- @TYPE 'LiftedPtrRep@ floating about. Consequently, we try hard to ensure
+-- that operations on such types are efficient:
+--
+--   * Instead of representing the lifted kind as
+--     @TyConApp tYPETyCon [liftedRepDataCon]@ we rather prefer to
+--     use the 'GHC.Types.Type' type synonym (available in GHC as
+--     'TysPrim.liftedTypeKind'). Note only is this a smaller AST but it also
+--     guarantees sharing on the heap.
+--
+--   * To avoid allocating 'TyConApp' constructors 'TysPrim.tYPE'
+--     catches the lifted case and uses `liftedTypeKind` instead of building an
+--     application.
+--
+--   * Similarly, 'Type.mkTyConApp' catches applications of TYPE and
+--     handles them using 'TysPrim.tYPE', ensuring that it benefits from the
+--     optimisation described above.
+--
+--   * Since 'liftedTypeKind' is a nullary type synonym application,
+--     it benefits from the optimisation described in Note [Comparing nullary
+--     type synonyms] in "GHC.Core.Type".
+
+-- | Given a RuntimeRep, applies TYPE to it.
+-- see Note [TYPE and RuntimeRep]
+tYPE :: Type -> Type
+tYPE (TyConApp tc [])
+  | tc `hasKey` liftedRepDataConKey = liftedTypeKind  -- TYPE 'LiftedPtrRep
+tYPE rr = TyConApp tYPETyCon [rr]
+
 -- This is a single, global definition of the type `Type`
 -- Defined here so it is only allocated once.
 -- See Note [mkTyConApp and Type]


=====================================
compiler/GHC/Tc/Utils/TcMType.hs
=====================================
@@ -120,7 +120,6 @@ import GHC.Types.Id as Id
 import GHC.Types.Name
 import GHC.Types.Var.Set
 import GHC.Builtin.Types
-import GHC.Builtin.Types.Prim
 import GHC.Types.Var.Env
 import GHC.Types.Name.Env
 import GHC.Utils.Misc



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e0c03f29343f2920991b0c8b28d9e9fac3bf6979
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/20201110/0afb1b1f/attachment-0001.html>


More information about the ghc-commits mailing list