[Git][ghc/ghc][wip/andreask/rec_tyCon_opt] checkRecTc: Use UniqFM instead of NameEnv.

Andreas Klebinger gitlab at gitlab.haskell.org
Mon Jun 15 11:16:28 UTC 2020



Andreas Klebinger pushed to branch wip/andreask/rec_tyCon_opt at Glasgow Haskell Compiler / GHC


Commits:
74bf38c2 by Andreas Klebinger at 2020-06-15T13:16:03+02:00
checkRecTc: Use UniqFM instead of NameEnv.

The unique of a TyCon is the same as it's name.

So we can simply use the tyCons unique directly
instead of taking a indirection via the name.

Saves one indirection when getting the unique.

- - - - -


1 changed file:

- compiler/GHC/Core/TyCon.hs


Changes:

=====================================
compiler/GHC/Core/TyCon.hs
=====================================
@@ -167,6 +167,7 @@ import GHC.Settings.Constants
 import GHC.Utils.Misc
 import GHC.Types.Unique( tyConRepNameUnique, dataConTyRepNameUnique )
 import GHC.Types.Unique.Set
+import GHC.Types.Unique.FM
 import GHC.Unit.Module
 
 import qualified Data.Data as Data
@@ -2746,13 +2747,16 @@ good to be able to unwrap multiple layers.
 The function that manages all this is checkRecTc.
 -}
 
-data RecTcChecker = RC !Int (NameEnv Int)
+data RecTcChecker = RC !Int (UniqFM Int)
   -- The upper bound, and the number of times
   -- we have encountered each TyCon
+  -- We use UniqFM since:
+  -- * Conveniently tyCons already have uniques to identenfy them
+  -- * Insertion order does not matter for this use case
 
 -- | Initialise a 'RecTcChecker' with 'defaultRecTcMaxBound'.
 initRecTc :: RecTcChecker
-initRecTc = RC defaultRecTcMaxBound emptyNameEnv
+initRecTc = RC defaultRecTcMaxBound emptyUFM
 
 -- | The default upper bound (100) for the number of times a 'RecTcChecker' is
 -- allowed to encounter each 'TyCon'.
@@ -2769,12 +2773,15 @@ checkRecTc :: RecTcChecker -> TyCon -> Maybe RecTcChecker
 -- Nothing      => Recursion detected
 -- Just rec_tcs => Keep going
 checkRecTc (RC bound rec_nts) tc
-  = case lookupNameEnv rec_nts tc_name of
+  | isTupleTyCon tc
+  = Just (RC bound rec_nts)
+  | otherwise
+  = case lookupUFM rec_nts tc_unique of
       Just n | n >= bound -> Nothing
-             | otherwise  -> Just (RC bound (extendNameEnv rec_nts tc_name (n+1)))
-      Nothing             -> Just (RC bound (extendNameEnv rec_nts tc_name 1))
+             | otherwise  -> Just (RC bound (addToUFM rec_nts tc_unique $! (n+1)))
+      Nothing             -> Just (RC bound (addToUFM rec_nts tc_unique 1))
   where
-    tc_name = tyConName tc
+    tc_unique = tyConUnique tc
 
 -- | Returns whether or not this 'TyCon' is definite, or a hole
 -- that may be filled in at some later point.  See Note [Skolem abstract data]



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/74bf38c234e98ec6dd289ce662c44b10e53aa352
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/20200615/03c11955/attachment-0001.html>


More information about the ghc-commits mailing list