diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index e255f32..be81a74 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -1,29 +1,24 @@ name: github-action -on: [push, pull_request] +on: [push, pull_request] jobs: build: strategy: matrix: - ghc: ['8.0.2', '8.2.2', '8.4.4', '8.6.5', '8.8.4', '8.10.2', '9.0.1'] + ghc: ['8.4.4', '8.6.5', '8.8.4', '8.10.7', '9.0.2', '9.2.5'] os: ['ubuntu-latest', 'macos-latest'] - exclude: - # There are some linker warnings in 802 on darwin that - # cause compilation to fail - # See https://github.com/NixOS/nixpkgs/issues/25139 - - ghc: '8.0.2' - os: 'macos-latest' runs-on: ${{ matrix.os }} name: GHC ${{ matrix.ghc }} on ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-haskell@v1 + - uses: actions/checkout@v3 + - uses: haskell/actions/setup@v2 with: ghc-version: ${{ matrix.ghc }} + cabal-version: '3.10.1.0' - name: Cache - uses: actions/cache@v1 + uses: actions/cache@v3 env: cache-name: cache-cabal with: @@ -36,10 +31,12 @@ jobs: ${{ runner.os }} - name: Install dependencies - run: | - cabal update - cabal build --only-dependencies --enable-tests --enable-benchmarks + run: cabal build --only-dependencies --enable-tests --enable-benchmarks - name: Build run: cabal build --enable-tests --enable-benchmarks all - name: Run tests - run: cabal test all + run: cabal test --enable-tests all + - if: matrix.ghc != '8.4.4' + # docs aren't built on ghc 8.4.4 because some dependency docs don't build on older GHCs + name: Build Docs + run: cabal haddock diff --git a/ChangeLog.md b/ChangeLog.md index 5621c70..1d96bd9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,10 @@ # Revision history for aeson-gadt-th +## 0.2.5.2 - 2022-07-03 + +* Loosen version bounds +* Support GHC 9.2 + ## 0.2.5.1 - 2022-01-04 * Remove dependency on `th-extras`. We were just using a reexport (under a diff --git a/aeson-gadt-th.cabal b/aeson-gadt-th.cabal index 2a1cb1d..5bd796c 100644 --- a/aeson-gadt-th.cabal +++ b/aeson-gadt-th.cabal @@ -20,13 +20,13 @@ flag build-readme library exposed-modules: Data.Aeson.GADT.TH - build-depends: base >= 4.8 && < 4.16 - , aeson >= 1.3 && < 1.6 + build-depends: base >= 4.8 && < 4.20 + , aeson >= 1.3 && < 2.3 , containers >= 0.5 && < 0.7 , dependent-sum >= 0.4 && < 0.8 - , transformers >= 0.5 && < 0.6 - , template-haskell >= 2.11.0 && < 2.18 - , th-abstraction >= 0.4 && < 0.5 + , transformers >= 0.5 && < 0.7 + , template-haskell >= 2.11.0 && < 2.22 + , th-abstraction >= 0.4 && < 0.7 if impl(ghc < 8.2) build-depends: dependent-sum < 0.6.2.2 hs-source-dirs: src @@ -39,7 +39,7 @@ executable readme build-depends: base , aeson , dependent-sum - , dependent-sum-template >= 0.1 && < 0.2 + , dependent-sum-template >= 0.2 && < 0.3 , dependent-map >= 0.3 && < 0.5 , aeson-gadt-th default-language: Haskell2010 diff --git a/src/Data/Aeson/GADT/TH.hs b/src/Data/Aeson/GADT/TH.hs index 2fb827a..231a8c8 100644 --- a/src/Data/Aeson/GADT/TH.hs +++ b/src/Data/Aeson/GADT/TH.hs @@ -45,7 +45,16 @@ import qualified Data.Set as Set import Data.Some (Some(..)) import Language.Haskell.TH hiding (cxt) import Language.Haskell.TH.Datatype (ConstructorInfo(..), applySubstitution, datatypeCons, reifyDatatype, unifyTypes) -import Language.Haskell.TH.Datatype.TyVarBndr (TyVarBndr_, tvName) +import Language.Haskell.TH.Datatype.TyVarBndr (tvName) + +#if !MIN_VERSION_template_haskell(2,21,0) +#if MIN_VERSION_th_abstraction(0,6,0) +import Language.Haskell.TH.Datatype.TyVarBndr (TyVarBndrVis) +#else +import Language.Haskell.TH.Datatype.TyVarBndr (TyVarBndr_) +type TyVarBndrVis = TyVarBndr_ () +#endif +#endif #if MIN_VERSION_dependent_sum(0,5,0) #else @@ -54,7 +63,7 @@ pattern Some x = This x #endif -- Do not export this type family, it must remain empty. It's used as a way to trick GHC into not unifying certain type variables. -type family Skolem :: k -> k +data family Skolem :: k -> k skolemize :: Set Name -> Type -> Type skolemize rigids t = case t of @@ -143,7 +152,7 @@ deriveFromJSONGADTWithOptions opts n = do let constraints = map head . group . sort $ constraints' -- This 'head' is safe because 'group' returns a list of non-empty lists v <- newName "v" parser <- funD 'parseJSON - [ clause [varP v] (normalB [e| + [ clause [varP v] (normalB [e| do (tag', _v') <- parseJSON $(varE v) $(caseE [|tag' :: String|] $ map pure matches ++ [wild]) |]) [] @@ -238,10 +247,17 @@ conMatches clsName topVars ixVar c = do [InstanceD _ cxt (AppT _className (AppT (ConT _some) ityp)) _] -> do sub <- lift $ unifyTypes [ityp, tn] tellCxt $ applySubstitution sub cxt - return (ConP 'Some [VarP x], VarE x) + return ( ConP + 'Some +#if MIN_VERSION_template_haskell(2,18,0) + [] +#endif + [VarP x] + , VarE x + ) _ -> error $ "The following instances of " ++ show clsName ++ " for " ++ show (ppr [AppT (ConT ''Some) tn]) ++ " exist (rigids: " ++ unwords (map show $ Set.toList rigidVars) ++ "), and I don't know which to pick:\n" ++ unlines (map (show . ppr) insts) _ -> do - demandInstanceIfNecessary + demandInstanceIfNecessary return (VarP x, VarE x) -- The singleton is special-cased because of -- https://downloads.haskell.org/ghc/8.10.1-rc1/docs/html/users_guide/8.10.1-notes.html#template-haskell @@ -266,7 +282,7 @@ kindArity = \case -- its declaration, and the arity of the kind of type being defined (i.e. how many more arguments would -- need to be supplied in addition to the bound parameters in order to obtain an ordinary type of kind *). -- If the supplied 'Name' is anything other than a data or newtype, produces an error. -tyConArity' :: Name -> Q ([TyVarBndr_ ()], Int) +tyConArity' :: Name -> Q ([TyVarBndrVis], Int) tyConArity' n = reify n >>= return . \case TyConI (DataD _ _ ts mk _ _) -> (ts, maybe 0 kindArity mk) TyConI (NewtypeD _ _ ts mk _ _) -> (ts, maybe 0 kindArity mk)