[Git][ghc/ghc][wip/T23210] StgToByteCode: Don't assume that data con workers are nullary

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Mon May 15 21:33:21 UTC 2023



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


Commits:
6b51e51e by Ben Gamari at 2023-05-15T17:33:14-04:00
StgToByteCode: Don't assume that data con workers are nullary

Previously StgToByteCode assumed that all data-con workers were of a
nullary representation. This is not a valid assumption, as seen
in #23210, where an unsaturated application of a unary data
constructor's worker resulted in invalid bytecode. Sadly, I have not yet
been able to reduce a minimal testcase for this.

Fixes #23210.

- - - - -


2 changed files:

- compiler/GHC/StgToByteCode.hs
- rts/Interpreter.c


Changes:

=====================================
compiler/GHC/StgToByteCode.hs
=====================================
@@ -1820,13 +1820,11 @@ pushAtom d p (StgVarArg var)
         -- PUSH_G doesn't tag constructors. So we use PACK here
         -- if we are dealing with nullary constructor.
         case isDataConWorkId_maybe var of
-          Just con -> do
-            massert (isNullaryRepDataCon con)
+          Just con | isNullaryRepDataCon con -> do
             return (unitOL (PACK con 0), szb)
 
-          Nothing
             -- see Note [Generating code for top-level string literal bindings]
-            | isUnliftedType (idType var) -> do
+          _ | isUnliftedType (idType var) -> do
               massert (idType var `eqType` addrPrimTy)
               return (unitOL (PUSH_ADDR (getName var)), szb)
 


=====================================
rts/Interpreter.c
=====================================
@@ -1687,7 +1687,6 @@ run_BCO:
             // n_nptrs=1, n_ptrs=0.
             ASSERT(n_ptrs + n_nptrs == n_words || (n_nptrs == 1 && n_ptrs == 0));
             ASSERT(n_ptrs + n_nptrs > 0);
-            //ASSERT(n_words > 0); // We shouldn't ever need to allocate nullary constructors
             for (int i = 0; i < n_words; i++) {
                 con->payload[i] = (StgClosure*)SpW(i);
             }



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6b51e51e8c2e617ecfcc54957d8cfeda0f62e82c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6b51e51e8c2e617ecfcc54957d8cfeda0f62e82c
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/20230515/8dd45ec5/attachment-0001.html>


More information about the ghc-commits mailing list