From 3d0831a5f3611b02085c612dcef6574251325c93 Mon Sep 17 00:00:00 2001 From: 0rphee <0rph3e@proton.me> Date: Fri, 20 Oct 2023 19:14:47 -0600 Subject: [PATCH] Support GHC 9.8 Bump dependencies Add Debug908.hs Fix renaming of `(,)` to `Tuple2` from `GHC.Tuple.Prim` https://hackage.haskell.org/package/ghc-prim-0.11.0/docs/GHC-Tuple-Prim.html#t:Tuple2 Set conditional `--allow-newer' for ci --- .github/workflows/ci.yml | 12 ++++- src/Stan/Ghc/Compat.hs | 2 + src/Stan/Ghc/Compat906.hs | 2 +- src/Stan/Hie/Compat.hs | 2 + src/Stan/Hie/Compat904.hs | 2 +- src/Stan/Hie/Debug.hs | 2 + src/Stan/Hie/Debug908.hs | 100 ++++++++++++++++++++++++++++++++++++++ src/Stan/Pattern/Type.hs | 4 ++ stan.cabal | 13 ++--- 9 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 src/Stan/Hie/Debug908.hs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9eb813..4f96d13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,8 @@ jobs: - "9.4.6" - "9.4.7" - "9.6.3" + - "9.8.1" + exclude: - os: macOS-latest ghc: 8.8.4 @@ -55,9 +57,17 @@ jobs: # configuring *after* freezing seemed to mean that the cache got # stuck in some bad state where it couldn't find a build plan. We # should revisit this decision later. + + - name: Set envvar EXTRA_FLAGS + shell: bash + if: ${{ matrix.ghc == '9.8.1' }} + run: | + echo "EXTRA_FLAGS=--allow-newer" >> "$GITHUB_ENV" + - name: Configure + shell: bash run: | - cabal configure --enable-tests --enable-benchmarks --test-show-details=direct + cabal configure --enable-tests --enable-benchmarks --test-show-details=direct $EXTRA_FLAGS - name: Freeze run: | diff --git a/src/Stan/Ghc/Compat.hs b/src/Stan/Ghc/Compat.hs index 795fbbd..9e65b99 100644 --- a/src/Stan/Ghc/Compat.hs +++ b/src/Stan/Ghc/Compat.hs @@ -12,4 +12,6 @@ import Stan.Ghc.Compat902 as Compat import Stan.Ghc.Compat902 as Compat #elif __GLASGOW_HASKELL__ == 906 import Stan.Ghc.Compat906 as Compat +#elif __GLASGOW_HASKELL__ == 908 +import Stan.Ghc.Compat906 as Compat #endif diff --git a/src/Stan/Ghc/Compat906.hs b/src/Stan/Ghc/Compat906.hs index 866d1b9..c1c822e 100644 --- a/src/Stan/Ghc/Compat906.hs +++ b/src/Stan/Ghc/Compat906.hs @@ -4,7 +4,7 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Stan.Ghc.Compat906 -#if __GLASGOW_HASKELL__ == 906 +#if __GLASGOW_HASKELL__ == 906 || __GLASGOW_HASKELL__ == 908 ( -- * Modules Module , ModuleName diff --git a/src/Stan/Hie/Compat.hs b/src/Stan/Hie/Compat.hs index dcf4534..f2cbcdc 100644 --- a/src/Stan/Hie/Compat.hs +++ b/src/Stan/Hie/Compat.hs @@ -12,4 +12,6 @@ import Stan.Hie.Compat902 as Compat import Stan.Hie.Compat904 as Compat #elif __GLASGOW_HASKELL__ == 906 import Stan.Hie.Compat904 as Compat +#elif __GLASGOW_HASKELL__ == 908 +import Stan.Hie.Compat904 as Compat #endif diff --git a/src/Stan/Hie/Compat904.hs b/src/Stan/Hie/Compat904.hs index 1152431..faa30ad 100644 --- a/src/Stan/Hie/Compat904.hs +++ b/src/Stan/Hie/Compat904.hs @@ -1,7 +1,7 @@ {-# LANGUAGE CPP #-} module Stan.Hie.Compat904 -#if __GLASGOW_HASKELL__ == 904 || __GLASGOW_HASKELL__ == 906 +#if __GLASGOW_HASKELL__ == 904 || __GLASGOW_HASKELL__ == 906 || __GLASGOW_HASKELL__ == 908 ( -- * Main HIE types ContextInfo (..) , HieArgs (..) diff --git a/src/Stan/Hie/Debug.hs b/src/Stan/Hie/Debug.hs index 82ab72a..2ead6bb 100644 --- a/src/Stan/Hie/Debug.hs +++ b/src/Stan/Hie/Debug.hs @@ -12,4 +12,6 @@ import Stan.Hie.Debug902 as Compat import Stan.Hie.Debug902 as Compat #elif __GLASGOW_HASKELL__ == 906 import Stan.Hie.Debug902 as Compat +#elif __GLASGOW_HASKELL__ == 908 +import Stan.Hie.Debug908 as Compat #endif diff --git a/src/Stan/Hie/Debug908.hs b/src/Stan/Hie/Debug908.hs new file mode 100644 index 0000000..feffd73 --- /dev/null +++ b/src/Stan/Hie/Debug908.hs @@ -0,0 +1,100 @@ +{-# LANGUAGE CPP #-} + +{-# OPTIONS_GHC -fno-warn-orphans #-} + +{-# LANGUAGE FlexibleInstances #-} + +{- | +Copyright: (c) 2020 Kowainik +SPDX-License-Identifier: MPL-2.0 +Maintainer: Kowainik + +Useful debugging and printing utilities for HIE types. They are +implemented in two ways: + +1. Using derived 'Show' instances. +2. Using @ghc@ pretty-printing. + +To make full use of derived 'Show' instances, add the @pretty-simple@ +package to dependencies and use the @pPrint@ function from the +@Text.Pretty.Simple@ module. +-} + +module Stan.Hie.Debug908 +#if __GLASGOW_HASKELL__ == 908 + ( debugHieFile + ) where + +import Text.Pretty.Simple (pPrint) + +import Stan.Core.ModuleName (fromGhcModule) +import Stan.Ghc.Compat (AvailInfo (..), FieldLabel (..), IfaceTyCon (..), + IfaceTyConInfo (..), IfaceTyConSort (..), IfaceTyLit (..), Module, + Name, PromotionFlag (..), TupleSort (..), isExternalName, + moduleStableString, moduleUnitId, nameModule, nameOccName, + nameStableString, occNameString, showTUnitId) +import Stan.Hie.Compat (HieAST (..), HieASTs (..), HieArgs (..), HieFile (..), HieType (..), + IdentifierDetails (..), NodeInfo (..)) +import Stan.NameMeta (NameMeta (..)) + +import qualified Text.Show + +import GHC.Iface.Ext.Types (SourcedNodeInfo(..), NodeOrigin(..), ContextInfo(..), IEType(..), BindType(..), Scope(..), DeclType(..), TyVarScope(..), RecFieldContext(..), EvVarSource(..), EvBindDeps(..), DeclType(..), NodeAnnotation (..)) +import GHC.Types.Var (Specificity(..)) + +debugHieFile :: FilePath -> [HieFile] -> IO () +debugHieFile path hieFiles = do + let mHieFile = find (\HieFile{..} -> hie_hs_file == path) hieFiles + whenJust mHieFile pPrint + +deriving stock instance Show a => Show (SourcedNodeInfo a) +deriving stock instance Show NodeOrigin +deriving stock instance Show ContextInfo +deriving stock instance Show IEType +deriving stock instance Show BindType +deriving stock instance Show Scope +deriving stock instance Show DeclType +deriving stock instance Show TyVarScope +deriving stock instance Show EvBindDeps +deriving stock instance Show EvVarSource +deriving stock instance Show RecFieldContext + +deriving stock instance Show Specificity + +-- orphan intances +deriving stock instance Show HieFile +deriving stock instance Show a => Show (HieType a) +deriving stock instance Show a => Show (HieAST a) +deriving newtype instance Show a => Show (HieASTs a) +deriving newtype instance Show a => Show (HieArgs a) +deriving stock instance Show a => Show (NodeInfo a) +deriving stock instance Show a => Show (IdentifierDetails a) +deriving stock instance Show IfaceTyCon +deriving stock instance Show IfaceTyConInfo +deriving stock instance Show IfaceTyConSort +deriving stock instance Show IfaceTyLit +deriving stock instance Show PromotionFlag +deriving stock instance Show TupleSort +deriving stock instance Show AvailInfo +deriving stock instance Show FieldLabel +deriving stock instance Show NodeAnnotation + +instance Show Module where + show = moduleStableString + +instance Show Name where + show nm = + if isExternalName nm + then show $ toNameMeta nm + else nameStableString nm + where + toNameMeta :: Name -> NameMeta + toNameMeta name = + let nameMetaName = toText $ occNameString $ nameOccName name + nameMetaModuleName = fromGhcModule $ nameModule name + nameMetaPackage = showTUnitId $ moduleUnitId $ nameModule name + in NameMeta{..} +#else + () where +#endif + diff --git a/src/Stan/Pattern/Type.hs b/src/Stan/Pattern/Type.hs index 3ebc48c..defd595 100644 --- a/src/Stan/Pattern/Type.hs +++ b/src/Stan/Pattern/Type.hs @@ -176,7 +176,11 @@ eitherPattern = "Either" `baseNameFrom` "Data.Either" |:: [ (?), (?) ] -- | 'PatternType' for pair @(,)@. pairPattern :: PatternType +#if __GLASGOW_HASKELL__ < 908 pairPattern = "(,)" `ghcPrimNameFrom` ghcTuple |:: [ (?), (?) ] +#elif __GLASGOW_HASKELL__ >= 908 +pairPattern = "Tuple2" `ghcPrimNameFrom` ghcTuple |:: [ (?), (?) ] +#endif where #if __GLASGOW_HASKELL__ < 906 ghcTuple = "GHC.Tuple" diff --git a/stan.cabal b/stan.cabal index 62766a3..7ce19fc 100644 --- a/stan.cabal +++ b/stan.cabal @@ -27,7 +27,7 @@ source-repository head location: https://github.com/kowainik/stan.git common common-options - build-depends: base >= 4.13 && < 4.19 && (< 4.16.3.0 || >= 4.17) + build-depends: base >= 4.13 && < 4.20 && (< 4.16.3.0 || >= 4.17) -- ^^ .hie files don't contain enough type -- information on ghc-9.2.[4-8] (base >= -- 4.16.3.0 && < 4.17) @@ -130,11 +130,12 @@ library Stan.Hie.Debug810 Stan.Hie.Debug900 Stan.Hie.Debug902 + Stan.Hie.Debug908 build-depends: array ^>= 0.5 , base64 ^>= 0.4.1 , blaze-html ^>= 0.9.1 - , bytestring >= 0.10 && < 0.12 + , bytestring >= 0.10 && < 0.13 , clay ^>= 0.14 , colourista >= 0.1 && < 0.3 , cryptohash-sha1 ^>= 0.11 @@ -142,11 +143,11 @@ library , directory ^>= 1.3 , extensions ^>= 0.0.0.1 || ^>= 0.1.0.0 , filepath ^>= 1.4 - , ghc >= 8.8 && < 9.7 - , ghc-boot-th >= 8.8 && < 9.7 + , ghc >= 8.8 && < 9.9 + , ghc-boot-th >= 8.8 && < 9.9 , gitrev ^>= 1.3.1 , microaeson ^>= 0.1.0.0 - , optparse-applicative >= 0.15 && < 0.17 + , optparse-applicative >= 0.15 && < 0.19 , pretty-simple ^>= 4.0 , process ^>= 1.6.8.0 , slist >= 0.1 && < 0.3 @@ -201,7 +202,7 @@ test-suite stan-test , containers , filepath ^>= 1.4 , ghc - , hedgehog >= 1.0 && < 1.4 + , hedgehog >= 1.0 && < 1.5 , hspec >= 2.7 && < 2.12 , hspec-hedgehog >= 0.0.1.2 , optparse-applicative