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

Backport instances introduced in base-4.20 #72

Merged
merged 3 commits into from
Apr 30, 2024
Merged
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
52 changes: 37 additions & 15 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/haskell-CI/haskell-ci
#
# version: 0.17.20231010
# version: 0.19.20240416
#
# REGENDATA ("0.17.20231010",["github","--config=cabal.haskell-ci","cabal.project"])
# REGENDATA ("0.19.20240416",["github","--config=cabal.haskell-ci","cabal.project"])
#
name: Haskell-CI
on:
Expand All @@ -28,19 +28,24 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.8.1
- compiler: ghc-9.10.0.20240413
compilerKind: ghc
compilerVersion: 9.8.1
compilerVersion: 9.10.0.20240413
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.6.2
- compiler: ghc-9.8.2
compilerKind: ghc
compilerVersion: 9.6.2
compilerVersion: 9.8.2
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.4.5
- compiler: ghc-9.6.5
compilerKind: ghc
compilerVersion: 9.4.5
compilerVersion: 9.6.5
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.4.8
compilerKind: ghc
compilerVersion: 9.4.8
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.2.8
Expand Down Expand Up @@ -121,18 +126,20 @@ jobs:
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"
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" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.8.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)
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.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"
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 cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.8.yaml;
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
fi
env:
HCKIND: ${{ matrix.compilerKind }}
Expand All @@ -152,20 +159,20 @@ jobs:
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"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.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"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
fi

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"
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
if [ $((HCNUMVER >= 91000)) -ne 0 ] ; then echo "HEADHACKAGE=true" >> "$GITHUB_ENV" ; else echo "HEADHACKAGE=false" >> "$GITHUB_ENV" ; fi
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
echo "GHCJSARITH=0" >> "$GITHUB_ENV"
env:
Expand Down Expand Up @@ -194,6 +201,18 @@ 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 @@ -247,6 +266,9 @@ jobs:
package base-orphans
ghc-options: -Werror
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 /^(base-orphans)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Changes in next [????.??.??]
- Backport new instances from GHC 9.10/`base-4.20`:
* `Fractional`, `RealFrac`, `Floating`, and `RealFloat` instances for `Compose`

## Changes in 0.9.1 [2023.10.11]
- Backport new instances from GHC 9.8/`base-4.19`:
* `Eq` and `Ord` instances for `SChar`, `SNat`, and `SSymbol`
Expand Down
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ To use `base-orphans`, simply `import Data.Orphans ()`.
* `Eq` and `Ord` instances for `SChar`, `SNat`, and `SSymbol`
* `Eq1`, `Read1`, and `Show1` instances for `Complex`
* `Eq1`, `Ord1`, `Read1`, and `Show1` instances for `NonEmpty`
* `Enum`, `Bounded`, `Num`, `Real`, and `Integral` instances for `Compose`
* `Enum`, `Bounded`, `Num`, `Real`, `Integral`, `Fractional`, `RealFrac`, `Floating`, and `RealFloat` instances for `Compose`
* `Foldable` instance for `Either`, `(,)` and `Const`
* `Foldable` and `Traversable` instances for `Alt` from `Data.Monoid`
* `Functor`, `Applicative`, and `Monad` instances for
Expand Down Expand Up @@ -106,6 +106,7 @@ To use `base-orphans`, simply `import Data.Orphans ()`.

## Supported versions of GHC/`base`

* `ghc-9.10.*` / `base-4.20.*`
* `ghc-9.8.*` / `base-4.19.*`
* `ghc-9.6.*` / `base-4.18.*`
* `ghc-9.4.*` / `base-4.17.*`
Expand Down
6 changes: 3 additions & 3 deletions base-orphans.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.35.4.
-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 4e4482d938177240bd3d33937246a570b07764edf79c92c1609492b56b35944b
-- hash: 4ccae773cb442c2dc6ecb60b76941fc47c5cc30027ed9c770150160b3cf63aa9

name: base-orphans
version: 0.9.1
Expand Down Expand Up @@ -36,7 +36,7 @@ license: MIT
license-file: LICENSE
build-type: Simple
tested-with:
GHC == 7.0.4 , GHC == 7.2.2 , GHC == 7.4.2 , GHC == 7.6.3 , GHC == 7.8.4 , GHC == 7.10.3 , GHC == 8.0.2 , GHC == 8.2.2 , GHC == 8.4.4 , GHC == 8.6.5 , GHC == 8.8.4 , GHC == 8.10.7 , GHC == 9.0.2 , GHC == 9.2.8 , GHC == 9.4.5 , GHC == 9.6.2 , GHC == 9.8.1
GHC == 7.0.4 , GHC == 7.2.2 , GHC == 7.4.2 , GHC == 7.6.3 , GHC == 7.8.4 , GHC == 7.10.3 , GHC == 8.0.2 , GHC == 8.2.2 , GHC == 8.4.4 , GHC == 8.6.5 , GHC == 8.8.4 , GHC == 8.10.7 , GHC == 9.0.2 , GHC == 9.2.8 , GHC == 9.4.8 , GHC == 9.6.5 , GHC == 9.8.2 , GHC == 9.10.1
extra-source-files:
CHANGES.markdown
README.markdown
Expand Down
7 changes: 4 additions & 3 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ tested-with: GHC == 7.0.4
, GHC == 8.10.7
, GHC == 9.0.2
, GHC == 9.2.8
, GHC == 9.4.5
, GHC == 9.6.2
, GHC == 9.8.1
, GHC == 9.4.8
, GHC == 9.6.5
, GHC == 9.8.2
, GHC == 9.10.1

extra-source-files:
- CHANGES.markdown
Expand Down
21 changes: 20 additions & 1 deletion src/Data/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import GHC.ConsoleHandler as Console
# endif
#endif

#if !(MIN_VERSION_base(4,19,0))
#if !(MIN_VERSION_base(4,20,0))
import Data.Orphans.Prelude
#endif

Expand Down Expand Up @@ -2050,6 +2050,25 @@ instance Ord (SSymbol s) where
# endif
#endif

#if !(MIN_VERSION_base(4,20,0))
# if MIN_VERSION_base(4,9,0)
deriving instance Fractional (f (g a)) => Fractional (Compose f g a)
deriving instance Floating (f (g a)) => Floating (Compose f g a)

-- RealFrac and RealFloat both have Ord as a superclass. For the reasons stated
-- above (near the Real/Integral instances for Compose), these
-- RealFrace/RealFloat instances are slightly more complicated for older
-- versions of base.
# if MIN_VERSION_base(4,18,0)
deriving instance RealFrac (f (g a)) => RealFrac (Compose f g a)
deriving instance RealFloat (f (g a)) => RealFloat (Compose f g a)
# else
deriving instance (RealFrac (f (g a)), Ord1 f, Ord1 g, Ord a) => RealFrac (Compose f g a)
deriving instance (RealFloat (f (g a)), Ord1 f, Ord1 g, Ord a) => RealFloat (Compose f g a)
# endif
# endif
#endif

#if __GLASGOW_HASKELL__ < 710
deriving instance Typeable All
deriving instance Typeable AnnotationWrapper
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Orphans/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This makes it much easier to be -Wall-compliant.
Note that this module does not export any modules that could introduce name clashes.
-}
module Data.Orphans.Prelude
#if MIN_VERSION_base(4,19,0)
#if MIN_VERSION_base(4,20,0)
() where
#else
( module OrphansPrelude
Expand Down
11 changes: 8 additions & 3 deletions test/Data/Version/OrphansSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ spec = do
describe "Data Version instance" $
it "allows obtaining a Version constructor" $
dataTypeName (dataTypeOf (Version [1,2,3] [])) `shouldBe`
-- Some old versions of GHC incorrectly return "Version" instead of
-- "Data.Version.Version" due to
-- https://gitlab.haskell.org/ghc/ghc/-/issues/20371.
#if __GLASGOW_HASKELL__ >= 801 && __GLASGOW_HASKELL__ < 903
-- Some old versions of GHC incorrectly return "Version" due to
-- https://gitlab.haskell.org/ghc/ghc/-/issues/20371.
"Version"
#elif __GLASGOW_HASKELL__ >= 910
-- In GHC 9.10 and later, Version is defined in
-- GHC.Internal.Data.Version (in the ghc-internal library).
"GHC.Internal.Data.Version.Version"
#else
-- In older versions of GHC, Version is defined in Data.Version (in the
-- base library).
"Data.Version.Version"
#endif

Expand Down
Loading