[Git][ghc/ghc][wip/T23146] Account for all VoidRep types on precomputedStaticConInfo

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Thu Mar 23 16:27:29 UTC 2023



Ben Gamari pushed to branch wip/T23146 at Glasgow Haskell Compiler / GHC


Commits:
b8ce1ba6 by romes at 2023-03-23T12:27:23-04: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

- - - - -


3 changed files:

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


Changes:

=====================================
compiler/GHC/Core/DataCon.hs
=====================================
@@ -1397,7 +1397,7 @@ dataConSourceArity (MkData { dcSourceArity = arity }) = arity
 
 -- | Gives the number of actual fields in the /representation/ of the
 -- data constructor. This may be more than appear in the source code;
--- the extra ones are the existentially quantified dictionaries
+-- the extra ones are the existentially quantified dictionaries. ROMES:TODO:
 dataConRepArity :: DataCon -> Arity
 dataConRepArity (MkData { dcRepArity = arity }) = arity
 


=====================================
compiler/GHC/StgToCmm/Closure.hs
=====================================
@@ -24,6 +24,8 @@ module GHC.StgToCmm.Closure (
         NonVoid(..), fromNonVoid, nonVoidIds, nonVoidStgArgs,
         assertNonVoidIds, assertNonVoidStgArgs,
 
+        isStgNullaryDataCon,
+
         -- * LambdaFormInfo
         LambdaFormInfo,         -- Abstract
         StandardFormInfo,        -- ...ditto...
@@ -201,6 +203,18 @@ addArgReps = map (\arg -> let arg' = fromNonVoid arg
 argPrimRep :: StgArg -> PrimRep
 argPrimRep arg = typePrimRep1 (stgArgType arg)
 
+-- | Morally equivalent to @isNullaryRepDataCon con@ at the Stg level, where
+-- we do not 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 :: DataCon -> Bool
+isStgNullaryDataCon =
+    null . filter (not . isZeroBitTy . scaledThing) . dataConRepArgTys
+
 ------------------------------------------------------
 --                Building LambdaFormInfo
 ------------------------------------------------------
@@ -267,7 +281,7 @@ mkLFImported id =
         -- Interface doesn't have a LambdaFormInfo, make a conservative one from
         -- the type.
         | Just con <- isDataConId_maybe id
-        , isNullaryRepDataCon con
+        , isStgNullaryDataCon con
             -- See Note [Imported nullary datacon wrappers must have correct LFInfo]
             -- in GHC.StgToCmm.Types
         -> LFCon con   -- An imported nullary constructor


=====================================
compiler/GHC/StgToCmm/DataCon.hs
=====================================
@@ -327,9 +327,10 @@ 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))
+
 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/b8ce1ba698b0740cf7027efdc5e25d03a836b9a9

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b8ce1ba698b0740cf7027efdc5e25d03a836b9a9
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/20230323/def39781/attachment-0001.html>


More information about the ghc-commits mailing list