Skip to content

Commit f3282bd

Browse files
Add CPP to support both ghc-8.10 and ghc-9
1 parent 26f8fd1 commit f3282bd

File tree

12 files changed

+63
-3
lines changed

12 files changed

+63
-3
lines changed

package.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ dependencies:
2525
library:
2626
source-dirs: src
2727
dependencies:
28-
- ghc >= 8.10.2 && < 9.0
28+
- ghc >= 8.10.2 && <= 9.1
2929
- containers >= 0.6.2.1
3030
- term-rewriting >= 0.3.0.1
3131
- transformers >= 0.5.6.2
32+
default-extensions: CPP
3233

3334
tests:
3435
should-compile:

src/TypeLevel/Rewrite.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Data.Foldable
88
import Data.Traversable
99

1010
-- GHC API
11+
#if MIN_VERSION_ghc(9,0,0)
1112
import GHC.Core.Coercion (Role(Representational), mkUnivCo)
1213
import GHC.Tc.Types.Constraint (CtEvidence(ctev_loc), Ct, ctEvExpr, ctLoc, mkNonCanonical)
1314
import GHC.Plugins (PredType, SDoc, eqType, fsep, ppr)
@@ -17,6 +18,17 @@ import GHC.Tc.Plugin (newWanted)
1718
import GHC.Core.TyCo.Rep (UnivCoProvenance(PluginProv))
1819
import GHC.Plugins (synTyConDefn_maybe)
1920
import GHC.Tc.Types (TcPluginResult(..), TcPluginM, ErrCtxt, pushErrCtxtSameOrigin, TcPlugin(..))
21+
#else
22+
import Coercion (Role(Representational), mkUnivCo)
23+
import Constraint (CtEvidence(ctev_loc), Ct, ctEvExpr, ctLoc, mkNonCanonical)
24+
import GhcPlugins (PredType, SDoc, eqType, fsep, ppr)
25+
import Plugins (Plugin(pluginRecompile, tcPlugin), CommandLineOption, defaultPlugin, purePlugin)
26+
import TcEvidence (EvExpr, EvTerm, evCast)
27+
import TcPluginM (newWanted)
28+
import TcRnTypes
29+
import TyCoRep (UnivCoProvenance(PluginProv))
30+
import TyCon (synTyConDefn_maybe)
31+
#endif
2032

2133
import TypeLevel.Rewrite.Internal.ApplyRules
2234
import TypeLevel.Rewrite.Internal.DecomposedConstraint

src/TypeLevel/Rewrite/Internal/ApplyRules.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import Data.Traversable
1313
import qualified Data.Map as Map
1414

1515
-- GHC API
16+
#if MIN_VERSION_ghc(9,0,0)
1617
import GHC.Plugins (TyVar)
18+
#else
19+
import Type (TyVar)
20+
#endif
1721

1822
-- term-rewriting API
1923
import Data.Rewriting.Rule (Rule(..))

src/TypeLevel/Rewrite/Internal/DecomposedConstraint.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import Control.Applicative
55

66
-- GHC API
77
import GHC (Class, Type)
8+
#if MIN_VERSION_ghc(9,0,0)
89
import GHC.Tc.Types.Constraint (Ct, ctEvPred, ctEvidence)
910
import GHC.Core.Predicate (EqRel(NomEq), Pred(ClassPred, EqPred), classifyPredType, mkClassPred, mkPrimEqPred)
11+
#else
12+
import Constraint (Ct, ctEvPred, ctEvidence)
13+
import Predicate (EqRel(NomEq), Pred(ClassPred, EqPred), classifyPredType, mkClassPred, mkPrimEqPred)
14+
#endif
1015

1116

1217
data DecomposedConstraint a

src/TypeLevel/Rewrite/Internal/Lookup.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import Control.Arrow ((***), first)
55
import Data.Tuple (swap)
66

77
-- GHC API
8-
import GHC.Driver.Finder (cannotFindModule)
98
import GHC (DataCon, TyCon, dataConTyCon)
9+
#if MIN_VERSION_ghc(9,0,0)
10+
import GHC.Driver.Finder (cannotFindModule)
1011
import GHC (Module, ModuleName, mkModuleName)
1112
import GHC.Plugins (mkDataOcc, mkTcOcc)
1213
import GHC.Utils.Panic (panicDoc)
@@ -15,7 +16,14 @@ import GHC.Tc.Plugin
1516
, unsafeTcPluginTcM
1617
)
1718
import GHC.Tc.Solver.Monad (getDynFlags)
18-
19+
#else
20+
import Finder (cannotFindModule)
21+
import Module (Module, ModuleName, mkModuleName)
22+
import OccName (mkDataOcc, mkTcOcc)
23+
import Panic (panicDoc)
24+
import TcPluginM
25+
import TcSMonad (getDynFlags)
26+
#endif
1927

2028
lookupModule
2129
:: String -- ^ module name

src/TypeLevel/Rewrite/Internal/PrettyPrint.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ module TypeLevel.Rewrite.Internal.PrettyPrint where
44
import Data.List (intercalate)
55

66
-- GHC API
7+
#if MIN_VERSION_ghc(9,0,0)
78
import GHC.Utils.Outputable (ppr, showSDocUnsafe)
89
import GHC.Plugins (TyCon)
910
import GHC.Plugins (TyVar, Type)
11+
#else
12+
import Outputable (ppr, showSDocUnsafe)
13+
import TyCon (TyCon)
14+
import Type (TyVar, Type)
15+
#endif
1016

1117
-- term-rewriting API
1218
import Data.Rewriting.Rule (Rule(..))

src/TypeLevel/Rewrite/Internal/TypeEq.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ module TypeLevel.Rewrite.Internal.TypeEq where
22

33
import Data.Function
44

5+
#if MIN_VERSION_ghc(9,0,0)
56
import GHC.Plugins (Type, eqType)
7+
#else
8+
import GhcPlugins (Type, eqType)
9+
#endif
610

711

812
-- | A newtype around 'Type' which has an 'Eq' instance.

src/TypeLevel/Rewrite/Internal/TypeNode.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
module TypeLevel.Rewrite.Internal.TypeNode where
33

44
-- GHC API
5+
#if MIN_VERSION_ghc(9,0,0)
56
import GHC (TyCon)
67
import GHC.Plugins (Type, isNumLitTy, isStrLitTy, mkTyConApp, splitTyConApp_maybe)
8+
#else
9+
import TyCon (TyCon)
10+
import Type (Type, isNumLitTy, isStrLitTy, mkTyConApp, splitTyConApp_maybe)
11+
#endif
712

813
import TypeLevel.Rewrite.Internal.TypeEq
914

src/TypeLevel/Rewrite/Internal/TypeRule.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
module TypeLevel.Rewrite.Internal.TypeRule where
44

55
-- GHC API
6+
#if MIN_VERSION_ghc(9,0,0)
67
import GHC.Plugins (getOccString)
78
import GHC.Core.Predicate (mkPrimEqPred)
89
import GHC.Plugins (TyVar, Type, mkTyVarTy)
10+
#else
11+
import Name (getOccString)
12+
import Predicate (mkPrimEqPred)
13+
import Type (TyVar, Type, mkTyVarTy)
14+
#endif
915

1016
-- term-rewriting API
1117
import Data.Rewriting.Rule (Rule(..))

src/TypeLevel/Rewrite/Internal/TypeTemplate.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
module TypeLevel.Rewrite.Internal.TypeTemplate where
33

44
-- GHC API
5+
#if MIN_VERSION_ghc(9,0,0)
56
import GHC.Plugins (TyVar, Type, getTyVar_maybe)
7+
#else
8+
import Type (TyVar, Type, getTyVar_maybe)
9+
#endif
610

711
-- term-rewriting API
812
import Data.Rewriting.Term (Term(Fun, Var))

0 commit comments

Comments
 (0)