[Git][ghc/ghc][wip/decode_cloned_stack] Get rid of static word size in test

Sven Tennie (@supersven) gitlab at gitlab.haskell.org
Sat Jan 21 20:27:32 UTC 2023



Sven Tennie pushed to branch wip/decode_cloned_stack at Glasgow Haskell Compiler / GHC


Commits:
66b45602 by Sven Tennie at 2023-01-21T20:27:03+00:00
Get rid of static word size in test

- - - - -


2 changed files:

- libraries/ghc-heap/tests/TestUtils.hs
- libraries/ghc-heap/tests/stack_lib.c


Changes:

=====================================
libraries/ghc-heap/tests/TestUtils.hs
=====================================
@@ -9,7 +9,7 @@ module TestUtils
   ( assertEqual,
     assertThat,
     assertStackInvariants,
-    unbox
+    unbox,
   )
 where
 
@@ -61,19 +61,20 @@ foreign import ccall "foldStackToArrayClosure" foldStackToArrayClosure# :: Stack
 foldStackToArrayClosure :: StackSnapshot -> ByteArray
 foldStackToArrayClosure (StackSnapshot s#) = ByteArray (foldStackToArrayClosure# s#)
 
+foreign import ccall "bytesInWord" bytesInWord# :: Word
+
 stackSnapshotToClosureTypes :: ByteArray -> [ClosureType]
 stackSnapshotToClosureTypes = wordsToClosureTypes . toWords
   where
     toWords :: ByteArray -> [Word]
     toWords ba@(ByteArray b#) =
       let s = I# (sizeofByteArray# b#)
-       in -- TODO: Adjust 8 to machine word size
-          [W# (indexWordArray# b# (toInt# i)) | i <- [0 .. maxWordIndex (ba)]]
+       in [W# (indexWordArray# b# (toInt# i)) | i <- [0 .. maxWordIndex (ba)]]
       where
         maxWordIndex :: ByteArray -> Int
         maxWordIndex (ByteArray ba#) =
           let s = I# (sizeofByteArray# ba#)
-              words = s `div` 8
+              words = s `div` fromIntegral bytesInWord#
            in case words of
                 w | w == 0 -> error "ByteArray contains no content!"
                 w -> w - 1


=====================================
libraries/ghc-heap/tests/stack_lib.c
=====================================
@@ -240,3 +240,7 @@ StgArrBytes *foldStackToArrayClosure(StgStack *stack) {
   freeList(cl);
   return arrayClosure;
 }
+
+StgWord bytesInWord() {
+  return SIZEOF_W;
+}



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/66b456027815af00e40bd20a08769a880ce5fbc5

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/66b456027815af00e40bd20a08769a880ce5fbc5
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/20230121/6860be23/attachment-0001.html>


More information about the ghc-commits mailing list