[Git][ghc/ghc][wip/romes/isNullaryRepDataCon] Precompute static closures for DataCons with zero-width args

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Mon Apr 17 11:20:58 UTC 2023



Rodrigo Mesquita pushed to branch wip/romes/isNullaryRepDataCon at Glasgow Haskell Compiler / GHC


Commits:
0ad91552 by Rodrigo Mesquita at 2023-04-17T12:20:11+01:00
Precompute static closures for DataCons with zero-width args

Relax the predicate over nullary datacons that determines whether we can
return a precomputed static closure for them, such that we give
precomputed static closures to datacons that only take zero-width
arguments.

Previously, we would only allow datacons that were nullary with regard
to their Core representation, which prevented datacons with only
zero-width arguments from using a precomputed static closure.

Closes #23158

- - - - -


2 changed files:

- compiler/GHC/StgToCmm/Closure.hs
- compiler/GHC/StgToCmm/DataCon.hs


Changes:

=====================================
compiler/GHC/StgToCmm/Closure.hs
=====================================
@@ -22,7 +22,7 @@ module GHC.StgToCmm.Closure (
         argPrimRep,
 
         NonVoid(..), fromNonVoid, nonVoidIds, nonVoidStgArgs,
-        assertNonVoidIds, assertNonVoidStgArgs,
+        assertNonVoidIds, assertNonVoidStgArgs, hasNoNonZeroWidthArgs,
 
         -- * LambdaFormInfo
         LambdaFormInfo,         -- Abstract
@@ -170,6 +170,12 @@ assertNonVoidStgArgs :: [StgArg] -> [NonVoid StgArg]
 assertNonVoidStgArgs args = assert (not (any (isZeroBitTy . stgArgType) args)) $
                             coerce args
 
+-- | Returns whether there are any arguments with a non-zero-width runtime
+-- representation.
+--
+-- Returns True if the datacon has no or /just/ zero-width arguments.
+hasNoNonZeroWidthArgs :: DataCon -> Bool
+hasNoNonZeroWidthArgs = all (isZeroBitTy . scaledThing) . dataConRepArgTys
 
 -----------------------------------------------------------------------------
 --                Representations
@@ -281,7 +287,6 @@ mkLFImported id =
         -> mkLFArgument id -- Not sure of exact arity
   where
     arity = idFunRepArity id
-    hasNoNonZeroWidthArgs = all (isZeroBitTy . scaledThing) . dataConRepArgTys
 
 {-
 Note [The LFInfo of Imported Ids]


=====================================
compiler/GHC/StgToCmm/DataCon.hs
=====================================
@@ -326,9 +326,9 @@ because they don't support cross package data references well.
 -- See Note [Precomputed static closures]
 precomputedStaticConInfo_maybe :: StgToCmmConfig -> Id -> DataCon -> [NonVoid StgArg] -> Maybe CgIdInfo
 precomputedStaticConInfo_maybe cfg binder con []
--- Nullary constructors
-  | isNullaryRepDataCon con
-  = Just $ litIdInfo (stgToCmmPlatform cfg) binder (mkConLFInfo con)
+  -- Nullary constructors (list of nonvoid args is null)
+  = assert (hasNoNonZeroWidthArgs con) $
+    Just $ litIdInfo (stgToCmmPlatform cfg) binder (mkConLFInfo con)
                 (CmmLabel (mkClosureLabel (dataConName con) NoCafRefs))
 precomputedStaticConInfo_maybe cfg binder con [arg]
   -- Int/Char values with existing closures in the RTS



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

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


More information about the ghc-commits mailing list