Skip to content

Add a cabal test-suite #69

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 33 additions & 86 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#
# For more information, see https://github.com/andreasabel/haskell-ci
#
# version: 0.17.20230928
# version: 0.17.20240110
#
# REGENDATA ("0.17.20230928",["github","parallel.cabal"])
# REGENDATA ("0.17.20240110",["github","parallel.cabal"])
#
name: Haskell-CI
on:
Expand All @@ -32,19 +32,19 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.8.0.20230919
- compiler: ghc-9.8.1
compilerKind: ghc
compilerVersion: 9.8.0.20230919
compilerVersion: 9.8.1
setup-method: ghcup
allow-failure: true
- compiler: ghc-9.6.3
allow-failure: false
- compiler: ghc-9.6.4
compilerKind: ghc
compilerVersion: 9.6.3
compilerVersion: 9.6.4
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.4.7
- compiler: ghc-9.4.8
compilerKind: ghc
compilerVersion: 9.4.7
compilerVersion: 9.4.8
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.2.8
Expand All @@ -65,56 +65,24 @@ jobs:
- compiler: ghc-8.8.4
compilerKind: ghc
compilerVersion: 8.8.4
setup-method: hvr-ppa
setup-method: ghcup
allow-failure: false
- compiler: ghc-8.6.5
compilerKind: ghc
compilerVersion: 8.6.5
setup-method: hvr-ppa
allow-failure: false
- compiler: ghc-8.4.4
compilerKind: ghc
compilerVersion: 8.4.4
setup-method: hvr-ppa
allow-failure: false
- compiler: ghc-8.2.2
compilerKind: ghc
compilerVersion: 8.2.2
setup-method: hvr-ppa
allow-failure: false
- compiler: ghc-8.0.2
compilerKind: ghc
compilerVersion: 8.0.2
setup-method: hvr-ppa
allow-failure: false
- compiler: ghc-7.10.3
compilerKind: ghc
compilerVersion: 7.10.3
setup-method: hvr-ppa
setup-method: ghcup
allow-failure: false
fail-fast: false
steps:
- name: apt
run: |
apt-get update
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
if [ "${{ matrix.setup-method }}" = ghcup ]; then
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.19.5/x86_64-linux-ghcup-0.1.19.5 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.7.yaml;
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
else
apt-add-repository -y 'ppa:hvr/ghc'
apt-get update
apt-get install -y "$HCNAME"
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.19.5/x86_64-linux-ghcup-0.1.19.5 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.7.yaml;
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
fi
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
Expand All @@ -126,27 +94,18 @@ jobs:
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
HCDIR=/opt/$HCKIND/$HCVER
if [ "${{ matrix.setup-method }}" = ghcup ]; then
HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
else
HC=$HCDIR/bin/$HCKIND
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV"
echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
fi

HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV"
if [ $((HCNUMVER >= 90800)) -ne 0 ] ; then echo "HEADHACKAGE=true" >> "$GITHUB_ENV" ; else echo "HEADHACKAGE=false" >> "$GITHUB_ENV" ; fi
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
echo "GHCJSARITH=0" >> "$GITHUB_ENV"
env:
Expand Down Expand Up @@ -175,18 +134,6 @@ jobs:
repository hackage.haskell.org
url: http://hackage.haskell.org/
EOF
if $HEADHACKAGE; then
cat >> $CABAL_CONFIG <<EOF
repository head.hackage.ghc.haskell.org
url: https://ghc.gitlab.haskell.org/head.hackage/
secure: True
root-keys: 7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
key-threshold: 3
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org:override
EOF
fi
cat >> $CABAL_CONFIG <<EOF
program-default-options
ghc-options: $GHCJOBS +RTS -M3G -RTS
Expand Down Expand Up @@ -234,13 +181,10 @@ jobs:
touch cabal.project
touch cabal.project.local
echo "packages: ${PKGDIR_parallel}" >> cabal.project
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package parallel" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi
echo "package parallel" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
cat >> cabal.project <<EOF
EOF
if $HEADHACKAGE; then
echo "allow-newer: $($HCPKG list --simple-output | sed -E 's/([a-zA-Z-]+)-[0-9.]+/*:\1,/g')" >> cabal.project
fi
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(parallel)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
Expand All @@ -264,6 +208,9 @@ jobs:
- name: build
run: |
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always
- name: tests
run: |
$CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct
- name: cabal check
run: |
cd ${PKGDIR_parallel} || false
Expand All @@ -280,10 +227,10 @@ jobs:
rm -f cabal.project.local
- name: constraint set containers-0.7
run: |
if [ $((HCNUMVER >= 80200 && HCNUMVER < 90800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='containers ^>= 0.7' all --dry-run ; fi
if [ $((HCNUMVER >= 80200 && HCNUMVER < 90800)) -ne 0 ] ; then cabal-plan topo | sort ; fi
if [ $((HCNUMVER >= 80200 && HCNUMVER < 90800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='containers ^>= 0.7' --dependencies-only -j2 all ; fi
if [ $((HCNUMVER >= 80200 && HCNUMVER < 90800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='containers ^>= 0.7' all ; fi
if [ $((HCNUMVER < 90800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='containers ^>= 0.7' all --dry-run ; fi
if [ $((HCNUMVER < 90800)) -ne 0 ] ; then cabal-plan topo | sort ; fi
if [ $((HCNUMVER < 90800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='containers ^>= 0.7' --dependencies-only -j2 all ; fi
if [ $((HCNUMVER < 90800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='containers ^>= 0.7' all ; fi
- name: save cache
uses: actions/cache/save@v3
if: always()
Expand Down
12 changes: 8 additions & 4 deletions Control/Parallel/Strategies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ newtype Eval a = Eval {unEval_ :: IO a}

-- | Run the evaluation.
runEval :: Eval a -> a
# if MIN_VERSION_base(4,4,0)
#if MIN_VERSION_base(4,4,0)
runEval = unsafeDupablePerformIO . unEval_
# else
#else
runEval = unsafePerformIO . unEval_
# endif
#endif

-- | Run the evaluation in the 'IO' monad. This allows sequencing of
-- evaluations relative to 'IO' actions.
Expand Down Expand Up @@ -530,6 +530,8 @@ evalTraversable = traverse
{-# INLINE evalTraversable #-}

-- | Like 'evalTraversable', but evaluates all elements in parallel.
--
-- > parTraversable = evalTraversable . rparWith
parTraversable :: Traversable t => Strategy a -> Strategy (t a)
parTraversable strat = evalTraversable (rparWith strat)
{-# INLINE parTraversable #-}
Expand All @@ -549,6 +551,8 @@ evalList = evalTraversable

-- | Evaluate each element of a list in parallel according to given strategy.
-- Equivalent to 'parTraversable' at the list type.
--
-- > parList = evalList . rparWith
parList :: Strategy a -> Strategy [a]
parList = parTraversable
-- Alternative definition via evalList:
Expand Down Expand Up @@ -652,7 +656,7 @@ evalBufferWHNF n0 xs0 = return (ret xs0 (start n0 xs0))
-- > evalBuffer n r0 == evalBuffer n rseq
--
evalBuffer :: Int -> Strategy a -> Strategy [a]
evalBuffer n strat = evalBufferWHNF n . map (withStrategy strat)
evalBuffer n strat = evalBufferWHNF n . map (withStrategy strat)

-- Like evalBufferWHNF, but sparks the list elements when pushing them
-- into the buffer.
Expand Down
2 changes: 2 additions & 0 deletions Control/Seq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ seqArrayBounds :: Ix i => Strategy i -> Strategy (Array i a)
seqArrayBounds strat = seqTuple2 strat strat . Data.Array.bounds

-- | Evaluate the keys and values of a map according to the given strategies.
--
-- Note: A 'Map' is strict in its keys, so the keys will always be at least in WHNF.
seqMap :: Strategy k -> Strategy v -> Strategy (Map k v)
seqMap stratK stratV = seqList (seqTuple2 stratK stratV) . Data.Map.toList

Expand Down
6 changes: 0 additions & 6 deletions Setup.hs

This file was deleted.

1 change: 0 additions & 1 deletion cabal.project

This file was deleted.

37 changes: 20 additions & 17 deletions parallel.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,14 @@ category: Control, Parallelism
build-type: Simple

tested-with:
GHC == 9.8.0
GHC == 9.6.3
GHC == 9.4.7
GHC == 9.8.1
GHC == 9.6.4
GHC == 9.4.8
GHC == 9.2.8
GHC == 9.0.2
GHC == 8.10.7
GHC == 8.8.4
GHC == 8.6.5
GHC == 8.4.4
GHC == 8.2.2
GHC == 8.0.2
GHC == 7.10.3
-- Drop these old GHCs from CI:
-- GHC == 7.8.4
-- GHC == 7.6.3
-- GHC == 7.4.2
-- GHC == 7.2.2
-- GHC == 7.0.4

description:
This package provides a library for parallel programming.
Expand Down Expand Up @@ -68,11 +58,24 @@ library
containers >= 0.4 && < 0.8,
deepseq >= 1.1 && < 1.6

ghc-options: -Wall

if impl(ghc >= 6.11)
ghc-options:
-Wall
-- To improve parallel performance:
ghc-options: -feager-blackholing
-feager-blackholing

if impl(ghc >= 7.2.1)
build-depends: ghc-prim

test-suite tests
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: Main.hs
other-modules:
Par
Seq
Util

build-depends: array, base, containers, nothunks, parallel, tasty, tasty-hunit

ghc-options: -Wall -threaded
1 change: 0 additions & 1 deletion prologue.txt

This file was deleted.

14 changes: 0 additions & 14 deletions tests/.gitignore

This file was deleted.

24 changes: 24 additions & 0 deletions tests/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Test.Tasty
import Test.Tasty.HUnit

import Control.Parallel

import qualified Par
import qualified Seq

parnofib :: Int -> Int
parnofib 0 = 1
parnofib 1 = 1
parnofib n =
let n1 = parnofib (n - 1)
n2 = parnofib (n - 2)
in n1 `par` n2 `pseq` n1 + n2 + 1

main :: IO ()
main = defaultMain $ testGroup "parallel"
[ testGroup "Control.Parallel"
[ testCase "parnofib" $ parnofib 30 @?= 2692537
]
, Par.tests
, Seq.tests
]
25 changes: 0 additions & 25 deletions tests/Makefile

This file was deleted.

Loading