Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize #88

Closed
wants to merge 12 commits into from
62 changes: 38 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ defaults:
run:
shell: bash

# Cancel running actions when a new action on the same PR is started
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
cabal:
name: ${{ matrix.os }} / ghc ${{ matrix.ghc }}
Expand All @@ -18,29 +23,38 @@ jobs:
matrix:
include:
### -- Linux --
- { cabal: "3.4", os: ubuntu-latest, ghc: "7.10.3" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.0.2" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.2.2" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.4.4" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.6.5" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.8.4" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.10.7" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "9.0.1" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.2.1", skip-bench: "true" }
- { cabal: "3.4", os: ubuntu-20.04, ghc: "7.10.3" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.0.2" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.2.2" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.4.4" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.6.5" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.8.4" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "8.10.7" }
- { cabal: "3.4", os: ubuntu-latest, ghc: "9.0.2" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.2.8", skip-bench: "true" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.4.7" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.6.3" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.8.1" }
## -- Win --
- { cabal: "3.4", os: windows-latest, ghc: "8.4.4" }
- { cabal: "3.4", os: windows-latest, ghc: "8.6.5" }
- { cabal: "3.4", os: windows-latest, ghc: "8.8.4" }
- { cabal: "3.4", os: windows-latest, ghc: "8.10.7" }
- { cabal: "3.4", os: windows-latest, ghc: "9.0.1" }
- { cabal: "3.6", os: windows-latest, ghc: "9.2.1", skip-bench: "true" }
- { cabal: "3.4", os: windows-latest, ghc: "8.4.4" }
- { cabal: "3.4", os: windows-latest, ghc: "8.6.5" }
- { cabal: "3.4", os: windows-latest, ghc: "8.8.4" }
- { cabal: "3.4", os: windows-latest, ghc: "8.10.7" }
- { cabal: "3.4", os: windows-latest, ghc: "9.0.2" }
- { cabal: "3.6", os: windows-latest, ghc: "9.2.8", skip-bench: "true" }
- { cabal: "3.10", os: windows-latest, ghc: "9.4.7" }
- { cabal: "3.10", os: windows-latest, ghc: "9.6.3" }
- { cabal: "3.10", os: windows-latest, ghc: "9.8.1" }
# MacOS
- { cabal: "3.4", os: macOS-latest, ghc: "8.4.4" }
- { cabal: "3.4", os: macOS-latest, ghc: "8.6.5" }
- { cabal: "3.4", os: macOS-latest, ghc: "8.8.4" }
- { cabal: "3.4", os: macOS-latest, ghc: "8.10.7" }
- { cabal: "3.4", os: macOS-latest, ghc: "9.0.1" }
- { cabal: "3.6", os: macOS-latest, ghc: "9.2.1", skip-bench: "true" }
- { cabal: "3.4", os: macOS-latest, ghc: "8.4.4" }
- { cabal: "3.4", os: macOS-latest, ghc: "8.6.5" }
- { cabal: "3.4", os: macOS-latest, ghc: "8.8.4" }
- { cabal: "3.4", os: macOS-latest, ghc: "8.10.7" }
- { cabal: "3.4", os: macOS-latest, ghc: "9.0.2" }
- { cabal: "3.6", os: macOS-latest, ghc: "9.2.8", skip-bench: "true" }
- { cabal: "3.10", os: macOS-latest, ghc: "9.4.7" }
- { cabal: "3.10", os: macOS-latest, ghc: "9.6.3" }
- { cabal: "3.10", os: macOS-latest, ghc: "9.8.1" }
fail-fast: false

steps:
Expand All @@ -50,16 +64,16 @@ jobs:
echo M1 ${{ matrix.ghc }}
echo M2 ${{ matrix.skip-bench }}
# ----------------
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# ----------------
- uses: haskell/actions/setup@v1
- uses: haskell-actions/setup@v2
id: setup-haskell-cabal
name: Setup Haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
# ----------------
- uses: actions/cache@v1
- uses: actions/cache@v3
name: Cache ~/.cabal/store
with:
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
Expand Down
13 changes: 10 additions & 3 deletions System/Random/MWC.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE BangPatterns, CPP, DeriveDataTypeable, FlexibleContexts,
FlexibleInstances, MultiParamTypeClasses, MagicHash, Rank2Types,
ScopedTypeVariables, TypeFamilies, UnboxedTuples
ScopedTypeVariables, TypeFamilies, TypeOperators, UnboxedTuples
#-}
-- |
-- Module : System.Random.MWC
Expand Down Expand Up @@ -159,13 +159,16 @@ module System.Random.MWC
#endif

import Control.Monad (ap, liftM, unless)
import Control.Monad.Primitive (PrimMonad, PrimBase, PrimState, unsafePrimToIO, unsafeSTToPrim)
import Control.Monad.Primitive (PrimMonad, PrimBase, PrimState, unsafePrimToIO, stToPrim)
import Control.Monad.ST (ST,runST)
import Data.Bits ((.&.), (.|.), shiftL, shiftR, xor)
import Data.Int (Int8, Int16, Int32, Int64)
import Data.IORef (IORef, atomicModifyIORef, newIORef)
import Data.Typeable (Typeable)
import Data.Vector.Generic (Vector)
#if __GLASGOW_HASKELL__ >= 800
import Data.Kind (Type)
#endif
import Data.Word
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Generic.Mutable as GM
Expand Down Expand Up @@ -462,7 +465,7 @@ instance (s ~ PrimState m, PrimMonad m) => Random.StatefulGen (Gen s) m where
{-# INLINE uniformWord32 #-}
uniformWord64 = uniform
{-# INLINE uniformWord64 #-}
uniformShortByteString n g = unsafeSTToPrim (Random.genShortByteStringST n (uniform g))
uniformShortByteString n g = stToPrim (Random.genShortByteStringST n (uniform g))
{-# INLINE uniformShortByteString #-}

-- | @since 0.15.0.0
Expand Down Expand Up @@ -623,7 +626,11 @@ uniform2 f (Gen q) = do
-- Type family for fixed size integrals. For signed data types it's
-- its unsigned counterpart with same size and for unsigned data types
-- it's same type
#if __GLASGOW_HASKELL__ >= 800
type family Unsigned a :: Type
#else
type family Unsigned a :: *
#endif

type instance Unsigned Int8 = Word8
type instance Unsigned Int16 = Word16
Expand Down
5 changes: 3 additions & 2 deletions System/Random/MWC/SeedSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import Foreign.Marshal.Array (peekArray)
#if defined(mingw32_HOST_OS)
import Foreign.Ptr
import Foreign.C.Types
#else
import System.IO (IOMode(..), hGetBuf, withBinaryFile)
#endif
import System.CPUTime (cpuTimePrecision, getCPUTime)
import System.IO (IOMode(..), hGetBuf, withBinaryFile)

-- Acquire seed from current time. This is horrible fallback for
-- Windows system.
acquireSeedTime :: IO [Word32]
acquireSeedTime = do
c <- (numerator . (%cpuTimePrecision)) `liftM` getCPUTime
c <- (numerator . (% cpuTimePrecision)) `liftM` getCPUTime
t <- toRational `liftM` getPOSIXTime
let n = fromIntegral (numerator t) :: Word64
return [fromIntegral c, fromIntegral n, fromIntegral (n `shiftR` 32)]
Expand Down
3 changes: 0 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
packages:
mwc-random.cabal

allow-newer:QuickCheck:splitmix
allow-newer:QuickCheck:random
11 changes: 8 additions & 3 deletions mwc-random.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ tested-with:
|| ==8.2.2
|| ==8.4.4
|| ==8.6.5
|| ==8.8.3
|| ==8.10.1
|| ==8.8.4
|| ==8.10.7
|| ==9.0.2
|| ==9.2.8
|| ==9.4.7
|| ==9.6.3
|| ==9.8.1
, GHCJS ==8.4

library
Expand Down Expand Up @@ -103,7 +108,7 @@ test-suite mwc-doctests
build-depends:
base -any
, mwc-random -any
, doctest >=0.15 && <0.20
, doctest >=0.15 && <0.23
--
, bytestring
, primitive
Expand Down
7 changes: 2 additions & 5 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
resolver: lts-15.2
resolver: lts-21.17
packages:
- '.'

extra-deps:
- github: idontgetoutmuch/random
commit: 86e06b8902d4d5c32b14b6a5ef44b964280bcc32
- splitmix-0.1@sha256:d50c4d0801a35be7875a040470c09863342514930c82a7d25780a6c2efc4fda9,5249
extra-deps: []
Loading