[Git][ghc/ghc][wip/24107] compiler: Force IfGlobalRdrEnv in NFData instance.

Zubin (@wz1000) gitlab at gitlab.haskell.org
Thu Dec 7 08:50:12 UTC 2023



Zubin pushed to branch wip/24107 at Glasgow Haskell Compiler / GHC


Commits:
23f9dd2b by Zubin Duggal at 2023-12-07T14:19:33+05:30
compiler: Force IfGlobalRdrEnv in NFData instance.

- - - - -


2 changed files:

- compiler/GHC/Types/Name/Reader.hs
- compiler/GHC/Unit/Module/ModIface.hs


Changes:

=====================================
compiler/GHC/Types/Name/Reader.hs
=====================================
@@ -574,6 +574,9 @@ data GlobalRdrEltX info
             -- Note [Retrieving the GREInfo from interfaces] in GHC.Types.GREInfo.
     } deriving (Data)
 
+instance NFData a => NFData (GlobalRdrEltX a) where
+  rnf (GRE name par _ imp info) = rnf name `seq` rnf par `seq` rnf imp `seq` rnf info
+
 
 {- Note [IfGlobalRdrEnv]
 ~~~~~~~~~~~~~~~~~~~~~~~~
@@ -625,13 +628,17 @@ instance NFData IfGlobalRdrElt where
 
 -- | See Note [Parents]
 data Parent = NoParent
-            | ParentIs  { par_is :: Name }
+            | ParentIs  { par_is :: !Name }
             deriving (Eq, Data)
 
 instance Outputable Parent where
    ppr NoParent        = empty
    ppr (ParentIs n)    = text "parent:" <> ppr n
 
+instance NFData Parent where
+  rnf NoParent = ()
+  rnf (ParentIs n) = rnf n
+
 plusParent :: Parent -> Parent -> Parent
 -- See Note [Combining parents]
 plusParent p1@(ParentIs _)    p2 = hasParent p1 p2
@@ -934,11 +941,10 @@ globalRdrEnvElts env = nonDetFoldOccEnv (++) [] env
 
 -- | Drop all 'GREInfo' fields in a 'GlobalRdrEnv' in order to
 -- avoid space leaks.
--- Also forces the bag in gre_imp.
 -- See Note [Forcing GREInfo] in GHC.Types.GREInfo.
 forceGlobalRdrEnv :: GlobalRdrEnvX info -> IfGlobalRdrEnv
 forceGlobalRdrEnv rdrs =
-  strictMapOccEnv (strictMap (\ gre -> rnf (gre_imp gre) `seq` gre { gre_info = ()})) rdrs
+  strictMapOccEnv (strictMap (\ gre -> gre { gre_info = ()})) rdrs
 
 -- | Hydrate a previously dehydrated 'GlobalRdrEnv',
 -- by (lazily!) looking up the 'GREInfo' using the provided function.


=====================================
compiler/GHC/Unit/Module/ModIface.hs
=====================================
@@ -575,11 +575,7 @@ instance ( NFData (IfaceBackendExts (phase :: ModIfacePhase))
     `seq` rnf mi_anns
     `seq` rnf mi_decls
     `seq` rnf mi_extra_decls
-    `seq`     mi_globals
-    -- NB: we already removed any potential space leaks in 'mi_globals' by
-    -- dehydrating, that is, by turning the 'GlobalRdrEnv' into a 'IfGlobalRdrEnv'.
-    -- This means we don't need to use 'rnf' here.
-    -- See Note [Forcing GREInfo] in GHC.Types.GREInfo.
+    `seq` rnf mi_globals
     `seq` rnf mi_insts
     `seq` rnf mi_fam_insts
     `seq` rnf mi_rules



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/23f9dd2b9768ee2dc7a4dd5c4d90c04d1405f164
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/20231207/baf14515/attachment-0001.html>


More information about the ghc-commits mailing list