[Git][ghc/ghc][wip/oneshot-unify] GHC.Core.Unify: Make UM actions one-shot by default

Sebastian Graf gitlab at gitlab.haskell.org
Fri Jun 12 08:40:27 UTC 2020



Sebastian Graf pushed to branch wip/oneshot-unify at Glasgow Haskell Compiler / GHC


Commits:
51c37e79 by Sebastian Graf at 2020-06-12T10:40:18+02:00
GHC.Core.Unify: Make UM actions one-shot by default

See also !3309, which applies this to all Reader/State-like monads in
GHC for compile-time perf improvements. The pattern used here enables
something similar to the state-hack, but is applicable to user-defined
monads, not just `IO`.

- - - - -


1 changed file:

- compiler/GHC/Core/Unify.hs


Changes:

=====================================
compiler/GHC/Core/Unify.hs
=====================================
@@ -1,6 +1,6 @@
 -- (c) The University of Glasgow 2006
 
-{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE ScopedTypeVariables, PatternSynonyms #-}
 {-# LANGUAGE CPP #-}
 {-# LANGUAGE DeriveFunctor #-}
 
@@ -44,6 +44,7 @@ import GHC.Data.Pair
 import GHC.Utils.Outputable
 import GHC.Types.Unique.FM
 import GHC.Types.Unique.Set
+import GHC.Exts( oneShot )
 
 import Control.Monad
 import Control.Applicative hiding ( empty )
@@ -1235,8 +1236,14 @@ data UMState = UMState
                    { um_tv_env   :: TvSubstEnv
                    , um_cv_env   :: CvSubstEnv }
 
-newtype UM a = UM { unUM :: UMState -> UnifyResultM (UMState, a) }
-    deriving (Functor)
+newtype UM a
+  = UMNoEta { unUM :: UMState -> UnifyResultM (UMState, a) }
+  deriving (Functor)
+
+pattern UM :: (UMState -> UnifyResultM (UMState, a)) -> UM a
+pattern UM m <- UMNoEta m
+  where
+    UM m = UMNoEta (oneShot m)
 
 instance Applicative UM where
       pure a = UM (\s -> pure (s, a))



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/51c37e79e553d6cd0ce0ca11ccc0138d40d113e5
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/20200612/e51185ef/attachment-0001.html>


More information about the ghc-commits mailing list