Skip to content

Commit

Permalink
Add Prisms for template-haskell-2.23
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanGlScott committed Dec 22, 2024
1 parent 0ef83b7 commit 1818f03
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 19 deletions.
76 changes: 58 additions & 18 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# This GitHub workflow config has been generated by a script via
#
# haskell-ci '--config=cabal.haskell-ci' 'cabal.project'
# haskell-ci 'github' '--config=cabal.haskell-ci' 'cabal.project'
#
# To regenerate the script (for example after adjusting tested-with) run
#
# haskell-ci regenerate
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
# version: 0.19.20240708
# version: 0.19.20241219
#
# REGENDATA ("0.19.20240708",["--config=cabal.haskell-ci","cabal.project"])
# REGENDATA ("0.19.20241219",["github","--config=cabal.haskell-ci","cabal.project"])
#
name: Haskell-CI
on:
Expand All @@ -28,6 +28,11 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.12.1
compilerKind: ghc
compilerVersion: 9.12.1
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.10.1
compilerKind: ghc
compilerVersion: 9.10.1
Expand Down Expand Up @@ -90,17 +95,31 @@ jobs:
allow-failure: false
fail-fast: false
steps:
- name: apt
- name: apt-get install
run: |
apt-get update
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 libnuma-dev
apt-get install -y freeglut3-dev
- name: Install GHCup
run: |
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.30.0/x86_64-linux-ghcup-0.1.30.0 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
- name: Install cabal-install (prerelease)
run: |
"$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.15.0.0.2024.10.3 || (cat "$HOME"/.ghcup/logs/*.* && false)
echo "CABAL=$HOME/.ghcup/bin/cabal-3.15.0.0.2024.10.3 -vnormal+nowrap" >> "$GITHUB_ENV"
- name: Install GHC (GHCup)
if: matrix.setup-method == 'ghcup'
run: |
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.12.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
apt-get update
apt-get install -y freeglut3-dev
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"
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
Expand All @@ -111,21 +130,12 @@ jobs:
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
HCDIR=/opt/$HCKIND/$HCVER
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.12.1.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"
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
if [ $((HCNUMVER >= 91200)) -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:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
Expand All @@ -152,6 +162,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 @@ -223,7 +245,25 @@ jobs:
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package lens-properties" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi
cat >> cabal.project <<EOF
allow-newer: aeson:ghc-prim
allow-newer: aeson:template-haskell
allow-newer: binary-orphans:base
allow-newer: boring:base
allow-newer: indexed-traversable:base
allow-newer: indexed-traversable-instances:base
allow-newer: integer-conversion:base
allow-newer: microstache:base
allow-newer: scientific:base
allow-newer: scientific:template-haskell
allow-newer: semialign:base
allow-newer: these:base
allow-newer: time-compat:base
allow-newer: time-compat:time
allow-newer: uuid-types:template-haskell
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: any.$_ installed\n" unless /^(lens|lens-examples|lens-properties)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
Expand Down Expand Up @@ -263,8 +303,8 @@ jobs:
run: |
if [ $((HCNUMVER >= 80800)) -ne 0 ] ; then $CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all ; fi
- name: save cache
uses: actions/cache/save@v4
if: always()
uses: actions/cache/save@v4
with:
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
path: ~/.cabal/store
5 changes: 5 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ next [????.??.??]

Also add `classIdFields :: LensRules` and `classIdNamer :: FieldNamer`, both
of which use the same naming rules as `makeFieldsId`.
* Update the `Prism`s in `Language.Haskell.TH.Lens` to reflect additions to
`template-haskell-2.23.0.0`:
* Add an `_OrP` `Prism` for the `Pat` data type.
* Add `_ForallE`, `_ForallVisE`, and `_ConstrainedE` `Prism`s for the `Exp`
data type.

5.3.2 [2024.05.12]
------------------
Expand Down
18 changes: 18 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
packages: .
./examples
./lens-properties

-- TODO: Remove this once the ecosystem has caught up with GHC 9.12
allow-newer:
aeson:ghc-prim,
aeson:template-haskell,
binary-orphans:base,
boring:base,
indexed-traversable:base,
indexed-traversable-instances:base,
integer-conversion:base,
microstache:base,
scientific:base,
scientific:template-haskell,
semialign:base,
these:base,
time-compat:base,
time-compat:time,
uuid-types:template-haskell
1 change: 1 addition & 0 deletions examples/lens-examples.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tested-with: GHC == 8.0.2
, GHC == 9.6.6
, GHC == 9.8.2
, GHC == 9.10.1
, GHC == 9.12.1

source-repository head
type: git
Expand Down
1 change: 1 addition & 0 deletions lens-properties/lens-properties.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tested-with: GHC == 8.0.2
, GHC == 9.6.6
, GHC == 9.8.2
, GHC == 9.10.1
, GHC == 9.12.1

extra-source-files:
.hlint.yaml
Expand Down
3 changes: 2 additions & 1 deletion lens.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tested-with: GHC == 8.0.2
, GHC == 9.6.6
, GHC == 9.8.2
, GHC == 9.10.1
, GHC == 9.12.1
synopsis: Lenses, Folds and Traversals
description:
This package comes \"Batteries Included\" with many useful lenses for the types
Expand Down Expand Up @@ -200,7 +201,7 @@ library
semigroupoids >= 5.0.1 && < 7,
strict >= 0.4 && < 0.6,
tagged >= 0.8.6 && < 1,
template-haskell >= 2.11.1.0 && < 2.23,
template-haskell >= 2.11.1.0 && < 2.24,
text >= 1.2.3.0 && < 2.2,
th-abstraction >= 0.4.1 && < 0.8,
these >= 1.1.1.1 && < 1.3,
Expand Down
44 changes: 44 additions & 0 deletions src/Language/Haskell/TH/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ module Language.Haskell.TH.Lens
#endif
#if MIN_VERSION_template_haskell(2,22,0)
, _TypeE
#endif
#if MIN_VERSION_template_haskell(2,23,0)
, _ForallE
, _ForallVisE
, _ConstrainedE
#endif
-- ** Body Prisms
, _GuardedB
Expand Down Expand Up @@ -337,6 +342,9 @@ module Language.Haskell.TH.Lens
#if MIN_VERSION_template_haskell(2,22,0)
, _TypeP
, _InvisP
#endif
#if MIN_VERSION_template_haskell(2,23,0)
, _OrP
#endif
-- ** Type Prisms
, _ForallT
Expand Down Expand Up @@ -2137,6 +2145,32 @@ _TypeE
remitter _ = Nothing
#endif

#if MIN_VERSION_template_haskell(2,23,0)
_ForallE :: Prism' Exp ([TyVarBndr Specificity], Exp)
_ForallE
= prism' reviewer remitter
where
reviewer (x, y) = ForallE x y
remitter (ForallE x y) = Just (x, y)
remitter _ = Nothing

_ForallVisE :: Prism' Exp ([TyVarBndr ()], Exp)
_ForallVisE
= prism' reviewer remitter
where
reviewer (x, y) = ForallVisE x y
remitter (ForallVisE x y) = Just (x, y)
remitter _ = Nothing

_ConstrainedE :: Prism' Exp ([Exp], Exp)
_ConstrainedE
= prism' reviewer remitter
where
reviewer (x, y) = ConstrainedE x y
remitter (ConstrainedE x y) = Just (x, y)
remitter _ = Nothing
#endif

_GuardedB :: Prism' Body [(Guard, Exp)]
_GuardedB
= prism' reviewer remitter
Expand Down Expand Up @@ -2504,6 +2538,16 @@ _InvisP
remitter _ = Nothing
#endif

#if MIN_VERSION_template_haskell(2,23,0)
_OrP :: Prism' Pat (NonEmpty Pat)
_OrP
= prism' reviewer remitter
where
reviewer = OrP
remitter (OrP x) = Just x
remitter _ = Nothing
#endif

_ForallT :: Prism' Type ([TyVarBndrSpec], Cxt, Type)
_ForallT
= prism' reviewer remitter
Expand Down

0 comments on commit 1818f03

Please sign in to comment.