From 7364d7bd5788bba00ced19cdfdc6723eba7d2315 Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Sat, 18 Feb 2023 16:04:25 +0100 Subject: [PATCH 1/7] Bump GHC upper bound from 9.6 to 9.8 --- ghc-typelits-natnormalise.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ghc-typelits-natnormalise.cabal b/ghc-typelits-natnormalise.cabal index ffc32d3..7aaf822 100644 --- a/ghc-typelits-natnormalise.cabal +++ b/ghc-typelits-natnormalise.cabal @@ -68,7 +68,7 @@ library GHC.TypeLits.Normalise.Unify build-depends: base >=4.9 && <5, containers >=0.5.7.1 && <0.7, - ghc >=8.0.1 && <9.6, + ghc >=8.0.1 && <9.8, ghc-tcplugins-extra >=0.3.1, transformers >=0.5.2.0 && < 0.6 if impl(ghc >= 9.0.0) @@ -78,7 +78,7 @@ library hs-source-dirs: src if impl(ghc >= 8.0) && impl(ghc < 9.4) hs-source-dirs: src-pre-ghc-9.4 - if impl(ghc >= 9.4) && impl(ghc < 9.6) + if impl(ghc >= 9.4) && impl(ghc < 9.8) hs-source-dirs: src-ghc-9.4 default-language: Haskell2010 other-extensions: CPP From 9c8093e1a38b8dcff3b7db392979313799b93107 Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Sat, 18 Feb 2023 16:18:28 +0100 Subject: [PATCH 2/7] Add some dodgy ifdefs in suspect places --- src-ghc-9.4/GHC/TypeLits/Normalise.hs | 8 ++++++++ src/GHC/TypeLits/Normalise/Unify.hs | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src-ghc-9.4/GHC/TypeLits/Normalise.hs b/src-ghc-9.4/GHC/TypeLits/Normalise.hs index fa56676..052bb29 100644 --- a/src-ghc-9.4/GHC/TypeLits/Normalise.hs +++ b/src-ghc-9.4/GHC/TypeLits/Normalise.hs @@ -143,6 +143,7 @@ xs :: OptVector t (n-l) where /n-l/ is a negative number. -} +{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RecordWildCards #-} @@ -185,8 +186,15 @@ import GHC.Core.Predicate mkPrimEqPred, isEqPred, isEqPrimPred, getClassPredTys_maybe) import GHC.Core.TyCo.Rep (Type (..), UnivCoProvenance (..)) import GHC.Core.TyCon (TyCon) +#if MIN_VERSION_ghc(9,6,0) +import GHC.Core.Type + (Kind, PredType, mkTyVarTy, tyConAppTyCon_maybe, typeKind, mkTyConApp) +import GHC.Core.TyCo.Compare + (eqType) +#else import GHC.Core.Type (Kind, PredType, eqType, mkTyVarTy, tyConAppTyCon_maybe, typeKind, mkTyConApp) +#endif import GHC.Driver.Plugins (Plugin (..), defaultPlugin, purePlugin) import GHC.Tc.Plugin (TcPluginM, tcLookupClass, tcPluginTrace, tcPluginIO, newEvVar) diff --git a/src/GHC/TypeLits/Normalise/Unify.hs b/src/GHC/TypeLits/Normalise/Unify.hs index 9bc20b1..702ae86 100644 --- a/src/GHC/TypeLits/Normalise/Unify.hs +++ b/src/GHC/TypeLits/Normalise/Unify.hs @@ -73,8 +73,15 @@ import GHC.Builtin.Types.Literals (typeNatLeqTyCon) #endif import GHC.Core.Predicate (EqRel (NomEq), Pred (EqPred), classifyPredType, mkPrimEqPred) import GHC.Core.TyCon (TyCon) +#if MIN_VERSION_ghc(9,6,0) +import GHC.Core.Type + (PredType, TyVar, coreView, mkNumLitTy, mkTyConApp, mkTyVarTy, typeKind) +import GHC.Core.TyCo.Compare + (eqType, nonDetCmpType) +#else import GHC.Core.Type (PredType, TyVar, coreView, eqType, mkNumLitTy, mkTyConApp, mkTyVarTy, nonDetCmpType, typeKind) +#endif import GHC.Core.TyCo.Rep (Kind, Type (..), TyLit (..)) import GHC.Tc.Plugin (TcPluginM, tcPluginTrace) import GHC.Tc.Types.Constraint (Ct, ctEvidence, ctEvId, ctEvPred, isGiven) From da5b5acdc4758adf90f1eea4860e49938843b05e Mon Sep 17 00:00:00 2001 From: Christiaan Baaij Date: Mon, 20 Feb 2023 21:17:40 +0100 Subject: [PATCH 3/7] Test GHC 9.6 in CI --- .github/workflows/haskell-ci.yml | 60 +++++++++++++++++++++++--------- ghc-typelits-natnormalise.cabal | 4 +-- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 1b7293a..e522cfe 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -8,9 +8,9 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.15.20220826 +# version: 0.15.20230217 # -# REGENDATA ("0.15.20220826",["github","ghc-typelits-natnormalise.cabal"]) +# REGENDATA ("0.15.20230217",["github","ghc-typelits-natnormalise.cabal"]) # name: Haskell-CI on: @@ -28,14 +28,19 @@ jobs: strategy: matrix: include: - - compiler: ghc-9.4.2 + - compiler: ghc-9.6.0.20230210 compilerKind: ghc - compilerVersion: 9.4.2 + compilerVersion: 9.6.0.20230210 + setup-method: ghcup + allow-failure: true + - compiler: ghc-9.4.4 + compilerKind: ghc + compilerVersion: 9.4.4 setup-method: ghcup allow-failure: false - - compiler: ghc-9.2.4 + - compiler: ghc-9.2.6 compilerKind: ghc - compilerVersion: 9.2.4 + compilerVersion: 9.2.6 setup-method: ghcup allow-failure: false - compiler: ghc-9.0.2 @@ -83,8 +88,9 @@ jobs: mkdir -p "$HOME/.ghcup/bin" curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.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.7.yaml; "$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false) - "$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + "$HOME/.ghcup/bin/ghcup" install cabal 3.9.0.0 || (cat "$HOME"/.ghcup/logs/*.* && false) else apt-add-repository -y 'ppa:hvr/ghc' apt-get update @@ -92,7 +98,8 @@ jobs: mkdir -p "$HOME/.ghcup/bin" curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup" chmod a+x "$HOME/.ghcup/bin/ghcup" - "$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.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.7.yaml; + "$HOME/.ghcup/bin/ghcup" install cabal 3.9.0.0 || (cat "$HOME"/.ghcup/logs/*.* && false) fi env: HCKIND: ${{ matrix.compilerKind }} @@ -110,20 +117,20 @@ jobs: echo "HC=$HC" >> "$GITHUB_ENV" echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV" echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV" - echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.9.0.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.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.9.0.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 >= 90600)) -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: @@ -152,6 +159,18 @@ jobs: repository hackage.haskell.org url: http://hackage.haskell.org/ EOF + if $HEADHACKAGE; then + cat >> $CABAL_CONFIG <> $CABAL_CONFIG <> cabal.project - echo "package ghc-typelits-natnormalise" >> cabal.project - echo " flags: +deverror" >> cabal.project if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package ghc-typelits-natnormalise" >> 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: $_ installed\n" unless /^(ghc-typelits-natnormalise)$/; }' >> cabal.project.local cat cabal.project cat cabal.project.local @@ -212,8 +232,8 @@ jobs: run: | $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all cabal-plan - - name: cache - uses: actions/cache@v2 + - name: restore cache + uses: actions/cache/restore@v3 with: key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} path: ~/.cabal/store @@ -237,8 +257,14 @@ jobs: ${CABAL} -vnormal check - name: haddock run: | - if [ $((HCNUMVER == 80605)) -ne 0 ] ; then $CABAL v2-haddock $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all; else $CABAL v2-haddock --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all ; fi + if [ $((HCNUMVER == 80605)) -ne 0 ] ; then $CABAL v2-haddock --disable-documentation $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all; else $CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all; fi - name: unconstrained build run: | rm -f cabal.project.local $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: save cache + uses: actions/cache/save@v3 + if: always() + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store diff --git a/ghc-typelits-natnormalise.cabal b/ghc-typelits-natnormalise.cabal index 7aaf822..62addae 100644 --- a/ghc-typelits-natnormalise.cabal +++ b/ghc-typelits-natnormalise.cabal @@ -49,8 +49,8 @@ extra-source-files: README.md CHANGELOG.md cabal-version: >=1.10 tested-with: 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.4, - GHC == 9.4.2 + GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.6, + GHC == 9.4.4, GHC == 9.6.1 source-repository head type: git From 6504de22075bed4be3e3c33441d3330a72e298f5 Mon Sep 17 00:00:00 2001 From: Christiaan Baaij Date: Mon, 20 Feb 2023 21:26:39 +0100 Subject: [PATCH 4/7] Hide SNat in tests on GHC 9.6+ --- tests/Tests.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Tests.hs b/tests/Tests.hs index a1fc1f9..3d5b02a 100644 --- a/tests/Tests.hs +++ b/tests/Tests.hs @@ -25,6 +25,10 @@ {-# OPTIONS_GHC -dcore-lint #-} import GHC.TypeLits +#if MIN_VERSION_base(4,18,0) + hiding (type SNat) +#endif + import Unsafe.Coerce import Prelude hiding (head,tail,init,(++),splitAt,concat,drop) import qualified Prelude as P From 0e2af9d1426caa5ac0e388c633e446890a2125de Mon Sep 17 00:00:00 2001 From: Christiaan Baaij Date: Mon, 20 Feb 2023 21:49:34 +0100 Subject: [PATCH 5/7] Adapt testsuite to GHC Proposal #106 --- tests/ErrorTests.hs | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/ErrorTests.hs b/tests/ErrorTests.hs index 088d6af..6a0cca4 100644 --- a/tests/ErrorTests.hs +++ b/tests/ErrorTests.hs @@ -191,7 +191,24 @@ testProxy10 :: Proxy (a :: Nat) -> Proxy (a + 2) -> () testProxy10 = proxyInEq' testProxy10Errors = -#if __GLASGOW_HASKELL__ >= 902 +#if __GLASGOW_HASKELL__ >= 906 + [$(do localeEncoding <- runIO (getLocaleEncoding) + if textEncodingName localeEncoding == textEncodingName utf8 + then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond" + else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond" + ) + ,$(do localeEncoding <- runIO (getLocaleEncoding) + if textEncodingName localeEncoding == textEncodingName utf8 + then litE $ stringL "(CmpNat a (a + 2)) True True False’" + else litE $ stringL "(CmpNat a (a + 2)) True True False'" + ) + ,$(do localeEncoding <- runIO (getLocaleEncoding) + if textEncodingName localeEncoding == textEncodingName utf8 + then litE $ stringL "with ‘False" + else litE $ stringL "with False" + ) + ] +#elif __GLASGOW_HASKELL__ >= 902 [$(do localeEncoding <- runIO (getLocaleEncoding) if textEncodingName localeEncoding == textEncodingName utf8 then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond" @@ -222,8 +239,13 @@ testProxy11 = proxyInEq' testProxy11Errors = [$(do localeEncoding <- runIO (getLocaleEncoding) if textEncodingName localeEncoding == textEncodingName utf8 +#if __GLASGOW_HASKELL__ >= 906 + then litE $ stringL "Couldn't match type ‘True’ with ‘False’" + else litE $ stringL "Couldn't match type True with False" +#else then litE $ stringL "Couldn't match type ‘'True’ with ‘'False’" else litE $ stringL "Couldn't match type 'True with 'False" +#endif )] testProxy12 :: Proxy (a + b) -> Proxy (a + c) -> () @@ -292,7 +314,24 @@ testProxy14 :: Proxy (2*a) -> Proxy (4*a) -> () testProxy14 = proxyInEq' testProxy14Errors = -#if __GLASGOW_HASKELL__ >= 902 +#if __GLASGOW_HASKELL__ >= 906 + [$(do localeEncoding <- runIO (getLocaleEncoding) + if textEncodingName localeEncoding == textEncodingName utf8 + then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond" + else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond" + ) + ,$(do localeEncoding <- runIO (getLocaleEncoding) + if textEncodingName localeEncoding == textEncodingName utf8 + then litE $ stringL "(CmpNat (2 * a) (4 * a)) True True False’" + else litE $ stringL "(CmpNat (2 * a) (4 * a)) True True False'" + ) + ,$(do localeEncoding <- runIO (getLocaleEncoding) + if textEncodingName localeEncoding == textEncodingName utf8 + then litE $ stringL "with ‘False" + else litE $ stringL "with False" + ) + ] +#elif __GLASGOW_HASKELL__ >= 902 [$(do localeEncoding <- runIO (getLocaleEncoding) if textEncodingName localeEncoding == textEncodingName utf8 then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond" From 172ae5618343cc6b663af0867b9fbe0025abf59f Mon Sep 17 00:00:00 2001 From: Christiaan Baaij Date: Mon, 20 Feb 2023 21:50:46 +0100 Subject: [PATCH 6/7] Bump transformers dependency --- ghc-typelits-natnormalise.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghc-typelits-natnormalise.cabal b/ghc-typelits-natnormalise.cabal index 62addae..58d1828 100644 --- a/ghc-typelits-natnormalise.cabal +++ b/ghc-typelits-natnormalise.cabal @@ -70,7 +70,7 @@ library containers >=0.5.7.1 && <0.7, ghc >=8.0.1 && <9.8, ghc-tcplugins-extra >=0.3.1, - transformers >=0.5.2.0 && < 0.6 + transformers >=0.5.2.0 && < 0.7 if impl(ghc >= 9.0.0) build-depends: ghc-bignum >=1.0 && <1.4 else From 13e5073c54d70bfc1cead5c0b11820dec08ca9d4 Mon Sep 17 00:00:00 2001 From: Christiaan Baaij Date: Mon, 20 Feb 2023 21:56:55 +0100 Subject: [PATCH 7/7] Bump version and make release --- CHANGELOG.md | 3 ++- ghc-typelits-natnormalise.cabal | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeae609..1620bf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog for the [`ghc-typelits-natnormalise`](http://hackage.haskell.org/package/ghc-typelits-natnormalise) package -## Unreleased +## 0.7.8 *February 20th 2023* * Try and outright solve substituted constraints, the same as is done with the unsubstituted constraint. Partially Fixes [#65](https://github.com/clash-lang/ghc-typelits-natnormalise/issues/65). +* Support for GHC-9.6.0.20230210 ## 0.7.7 *October 10th 2022* * Solve unflattened wanteds instead of the wanteds passed to the plugin. Fixes [#1901]https://github.com/clash-lang/clash-compiler/issues/1901. diff --git a/ghc-typelits-natnormalise.cabal b/ghc-typelits-natnormalise.cabal index 58d1828..0b90ed0 100644 --- a/ghc-typelits-natnormalise.cabal +++ b/ghc-typelits-natnormalise.cabal @@ -1,5 +1,5 @@ name: ghc-typelits-natnormalise -version: 0.7.7 +version: 0.7.8 synopsis: GHC typechecker plugin for types of kind GHC.TypeLits.Nat description: A type checker plugin for GHC that can solve /equalities/ and /inequalities/