[Git][ghc/ghc][wip/romes/static-gadt-con-info] Account for all VoidRep types on precomputedStaticConInfo

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Wed Mar 22 22:34:14 UTC 2023



Rodrigo Mesquita pushed to branch wip/romes/static-gadt-con-info at Glasgow Haskell Compiler / GHC


Commits:
12f9387a by romes at 2023-03-22T22:34:06+00:00
Account for all VoidRep types on precomputedStaticConInfo

Previously, we were considering coercion values whose unlifted type
equality had a zerobit runtime representation (VoidRep) to be
constructor arguments when determining whether we should pre-compute a
staticConInfo for a data constructor.

This made it so that GADT constructors with type-equality constraints
that should have no runtime representation actually ended up impacting
the code generation.

Fixes #23158

- - - - -


1 changed file:

- compiler/GHC/StgToCmm/DataCon.hs


Changes:

=====================================
compiler/GHC/StgToCmm/DataCon.hs
=====================================
@@ -37,11 +37,12 @@ import GHC.Runtime.Heap.Layout
 import GHC.Types.CostCentre
 import GHC.Unit
 import GHC.Core.DataCon
+import GHC.Core.TyCo.Rep (scaledThing)
 import GHC.Data.FastString
 import GHC.Types.Id
 import GHC.Types.Id.Info( CafInfo( NoCafRefs ) )
 import GHC.Types.Name (isInternalName)
-import GHC.Types.RepType (countConRepArgs)
+import GHC.Types.RepType (countConRepArgs, isZeroBitTy)
 import GHC.Types.Literal
 import GHC.Builtin.Utils
 import GHC.Utils.Panic
@@ -327,9 +328,19 @@ because they don't support cross package data references well.
 precomputedStaticConInfo_maybe :: StgToCmmConfig -> Id -> DataCon -> [NonVoid StgArg] -> Maybe CgIdInfo
 precomputedStaticConInfo_maybe cfg binder con []
 -- Nullary constructors
-  | isNullaryRepDataCon con
+  | isStgNullaryDataCon con
   = Just $ litIdInfo (stgToCmmPlatform cfg) binder (mkConLFInfo con)
                 (CmmLabel (mkClosureLabel (dataConName con) NoCafRefs))
+  where
+    -- morally equivalent to (isNullaryRepDataCon con) at the Stg level, where we
+    -- doesn't consider types with no runtime representation to be constructor arguments.
+    --
+    -- isNullaryRepDataCon is not fit for checking whether the constructor is
+    -- nullary at the Stg level because the function 'dataConRepArgTys' it
+    -- depends on includes unlifted type equalities, whose runtime
+    -- representation is 'VoidRep', in the returned list.
+    isStgNullaryDataCon = null . filter (isZeroBitTy . scaledThing) . dataConRepArgTys
+
 precomputedStaticConInfo_maybe cfg binder con [arg]
   -- Int/Char values with existing closures in the RTS
   | intClosure || charClosure



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/12f9387ab8599333cfe599f614ceec5f8762da1b
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/20230322/e022b617/attachment-0001.html>


More information about the ghc-commits mailing list