From 1818f039a0915d639c381cc33a6772b9d1542cae Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 24 Oct 2024 07:19:52 -0400 Subject: [PATCH] Add Prisms for template-haskell-2.23 --- .github/workflows/haskell-ci.yml | 76 ++++++++++++++++++++------- CHANGELOG.markdown | 5 ++ cabal.project | 18 +++++++ examples/lens-examples.cabal | 1 + lens-properties/lens-properties.cabal | 1 + lens.cabal | 3 +- src/Language/Haskell/TH/Lens.hs | 44 ++++++++++++++++ 7 files changed, 129 insertions(+), 19 deletions(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 6c48d883f..60652e5af 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -1,6 +1,6 @@ # 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 # @@ -8,9 +8,9 @@ # # 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: @@ -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 @@ -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 }} @@ -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 }} @@ -152,6 +162,18 @@ jobs: repository hackage.haskell.org url: http://hackage.haskell.org/ EOF + if $HEADHACKAGE; then + cat >> $CABAL_CONFIG <> $CABAL_CONFIG <= 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 <> 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 @@ -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 diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 51340c223..2070aee0d 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -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] ------------------ diff --git a/cabal.project b/cabal.project index b91f16f28..76c9b1c1b 100644 --- a/cabal.project +++ b/cabal.project @@ -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 diff --git a/examples/lens-examples.cabal b/examples/lens-examples.cabal index 85c8793fc..3dd298792 100644 --- a/examples/lens-examples.cabal +++ b/examples/lens-examples.cabal @@ -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 diff --git a/lens-properties/lens-properties.cabal b/lens-properties/lens-properties.cabal index 6f411930d..910450777 100644 --- a/lens-properties/lens-properties.cabal +++ b/lens-properties/lens-properties.cabal @@ -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 diff --git a/lens.cabal b/lens.cabal index 812cbddff..18b969476 100644 --- a/lens.cabal +++ b/lens.cabal @@ -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 @@ -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, diff --git a/src/Language/Haskell/TH/Lens.hs b/src/Language/Haskell/TH/Lens.hs index 0a7b76abd..9abca9c62 100644 --- a/src/Language/Haskell/TH/Lens.hs +++ b/src/Language/Haskell/TH/Lens.hs @@ -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 @@ -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 @@ -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 @@ -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