Skip to content

Commit e5439d2

Browse files
Make it work on wasm32-wasi and older GHCs
1 parent 5d6ad40 commit e5439d2

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Data/Atomic.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,29 @@ module Data.Atomic
1717
, subtract
1818
) where
1919

20+
#include "MachDeps.h"
21+
#ifndef SIZEOF_HSINT
22+
#error "MachDeps.h didn't define SIZEOF_HSINT"
23+
#endif
24+
2025
import Prelude hiding (read, subtract)
2126

2227
import GHC.Int
28+
29+
#if SIZEOF_HSINT == 8
30+
31+
-- 64-bit imports
2332
import GHC.IO
2433
import GHC.Prim
2534

26-
#include "MachDeps.h"
27-
#ifndef SIZEOF_HSINT
28-
#error "MachDeps.h didn't define SIZEOF_HSINT"
35+
#else
36+
37+
-- 32-bit imports
38+
import Data.IORef
39+
2940
#endif
3041

42+
3143
-- 64-bit machine, Int ~ Int64, do it the fast way:
3244
#if SIZEOF_HSINT == 8
3345

@@ -85,11 +97,11 @@ write (C ior) !i = atomicWriteIORef ior i
8597

8698
-- | Increase the atomic by the given amount.
8799
add :: Atomic -> Int64 -> IO ()
88-
add (C ior) !i = atomicModifyIORef' ior (\!n -> (n+i, ()))
100+
add (C ior) !i = atomicModifyIORef' ior (\(!n) -> (n+i, ()))
89101

90102
-- | Decrease the atomic by the given amount.
91103
subtract :: Atomic -> Int64 -> IO ()
92-
subtract (C ior) !i = atomicModifyIORef' ior (\!n -> (n-i, ()))
104+
subtract (C ior) !i = atomicModifyIORef' ior (\(!n) -> (n-i, ()))
93105

94106
#endif
95107

System/Metrics/Distribution.hsc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE BangPatterns #-}
2-
{-# LANGUAGE ExtendedLiterals #-}
32
{-# LANGUAGE ForeignFunctionInterface #-}
43
{-# LANGUAGE MagicHash #-}
54
{-# LANGUAGE RecordWildCards #-}
@@ -91,7 +90,7 @@ newDistrib = IO $ \s ->
9190
-- probably unecessary
9291
case atomicWriteIntArray## mba lockPos' 0## s1 of { s2 ->
9392
case countPos of { (I## countPos') ->
94-
case writeInt64Array## mba countPos' 0##Int64 s2 of { s3 ->
93+
case writeInt64Array## mba countPos' (intToInt64## 0##) s2 of { s3 ->
9594
case meanPos of { (I## meanPos') ->
9695
case writeDoubleArray## mba meanPos' 0.0#### s3 of { s4 ->
9796
case sumSqDeltaPos of { (I## sumSqDeltaPos') ->
@@ -228,7 +227,7 @@ combine (Distrib bMBA) (Distrib aMBA) = IO $ \s ->
228227
)
229228
) of { sumSqDelta' ->
230229
case writeInt64Array## aMBA countPos' count' s7 of { s8 ->
231-
case (case eqInt64## count' 0##Int64 of { 0## -> mean'; _ -> 0.0#### }) of { writeMean ->
230+
case (case eqInt64## count' (intToInt64## 0##) of { 0## -> mean'; _ -> 0.0#### }) of { writeMean ->
232231
case writeDoubleArray## aMBA meanPos' writeMean s8 of { s9 ->
233232
case writeDoubleArray## aMBA sumSqDeltaPos' sumSqDelta' s9 of { s10 ->
234233
case sumPos of { (I## sumPos') ->

0 commit comments

Comments
 (0)