diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2023-03-27 13:00:49 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-03-30 01:40:49 -0400 |
commit | f4f1f14f8009c3c120b8b963ec130cbbc774ec02 (patch) | |
tree | ca3a2abdc1b3f95ba7a7f2df07343a21c4ba5468 | |
parent | b159e0e94f8d049198947965046b6a5edbd89c36 (diff) | |
download | haskell-f4f1f14f8009c3c120b8b963ec130cbbc774ec02.tar.gz |
ghc-heap: remove wrong Addr# coercion (#23181)
Conversion from Addr# to I# isn't correct with the JS backend.
Also used the opportunity to reenable 64-bit Word/Int tests
-rw-r--r-- | libraries/ghc-heap/GHC/Exts/Heap.hs | 6 | ||||
-rw-r--r-- | libraries/ghc-heap/GHC/Exts/Heap/Closures.hs | 2 | ||||
-rw-r--r-- | libraries/ghc-heap/tests/heap_all.hs | 19 |
3 files changed, 13 insertions, 14 deletions
diff --git a/libraries/ghc-heap/GHC/Exts/Heap.hs b/libraries/ghc-heap/GHC/Exts/Heap.hs index ac954bba8b..173eca29e4 100644 --- a/libraries/ghc-heap/GHC/Exts/Heap.hs +++ b/libraries/ghc-heap/GHC/Exts/Heap.hs @@ -112,15 +112,15 @@ instance Word# ~ a => HasHeapRep (a :: TYPE 'WordRep) where instance Int64# ~ a => HasHeapRep (a :: TYPE 'Int64Rep) where getClosureData x = return $ - Int64Closure { ptipe = PInt64, int64Val = I64# (unsafeCoerce# x) } + Int64Closure { ptipe = PInt64, int64Val = I64# x } instance Word64# ~ a => HasHeapRep (a :: TYPE 'Word64Rep) where getClosureData x = return $ - Word64Closure { ptipe = PWord64, word64Val = W64# (unsafeCoerce# x) } + Word64Closure { ptipe = PWord64, word64Val = W64# x } instance Addr# ~ a => HasHeapRep (a :: TYPE 'AddrRep) where getClosureData x = return $ - AddrClosure { ptipe = PAddr, addrVal = I# (unsafeCoerce# x) } + AddrClosure { ptipe = PAddr, addrVal = Ptr x } instance Float# ~ a => HasHeapRep (a :: TYPE 'FloatRep) where getClosureData x = return $ diff --git a/libraries/ghc-heap/GHC/Exts/Heap/Closures.hs b/libraries/ghc-heap/GHC/Exts/Heap/Closures.hs index 6078a927bf..a65eb9cbed 100644 --- a/libraries/ghc-heap/GHC/Exts/Heap/Closures.hs +++ b/libraries/ghc-heap/GHC/Exts/Heap/Closures.hs @@ -329,7 +329,7 @@ data GenClosure b -- | Primitive Addr | AddrClosure { ptipe :: PrimType - , addrVal :: !Int } + , addrVal :: !(Ptr ()) } -- | Primitive Float | FloatClosure diff --git a/libraries/ghc-heap/tests/heap_all.hs b/libraries/ghc-heap/tests/heap_all.hs index ac8953b5d2..8cc9afce95 100644 --- a/libraries/ghc-heap/tests/heap_all.hs +++ b/libraries/ghc-heap/tests/heap_all.hs @@ -12,6 +12,7 @@ import GHC.Int import GHC.IO import GHC.IORef import GHC.MVar +import GHC.Ptr import GHC.Stack import GHC.STRef import GHC.Weak @@ -176,7 +177,7 @@ exWord64Closure = Word64Closure exAddrClosure :: Closure exAddrClosure = AddrClosure - { ptipe = PAddr, addrVal = 42 } + { ptipe = PAddr, addrVal = nullPtr `plusPtr` 42 } exFloatClosure :: Closure exFloatClosure = FloatClosure @@ -316,19 +317,17 @@ main = do assertClosuresEq exWordClosure -- Primitive Int64 - -- FAILING: On 64-bit platforms, v is a regular Int - -- let (I64# v) = 42 - -- getClosureData v >>= - -- assertClosuresEq exInt64Closure + let (I64# v) = 42 + getClosureData v >>= + assertClosuresEq exInt64Closure -- Primitive Word64 - -- FAILING: On 64-bit platforms, v is a regular Word - -- let (W64# v) = 42 - -- getClosureData v >>= - -- assertClosuresEq exWord64Closure + let (W64# v) = 42 + getClosureData v >>= + assertClosuresEq exWord64Closure -- Primitive Addr - let v = unsafeCoerce# 42# :: Addr# + let (Ptr v) = nullPtr `plusPtr` 42 getClosureData v >>= assertClosuresEq exAddrClosure |