Skip to content

Commit 071ef8e

Browse files
committed
Add support for GHC 9.2.
Doesn't cover the plugin yet.
1 parent 3b82a61 commit 071ef8e

File tree

8 files changed

+104
-7
lines changed

8 files changed

+104
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
- "8.8.1"
2121
- "8.10.1"
2222
- "9.0.1"
23+
- "9.2.1"
2324
steps:
2425
- uses: actions/checkout@v2
2526
- uses: haskell/actions/setup@v1

examples/src/ConCat/Dual.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE ConstraintKinds #-}
22
{-# LANGUAGE CPP #-}
3+
{-# LANGUAGE FlexibleContexts #-}
34
{-# LANGUAGE FlexibleInstances #-}
45
{-# LANGUAGE TypeOperators #-}
56
{-# LANGUAGE TupleSections #-}

examples/src/ConCat/TArr.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ import Prelude hiding (id, (.), const, curry, uncurry) -- Coming from ConCat.Al
4545
import Data.Monoid
4646
import Data.Foldable
4747
import GHC.TypeLits
48+
#if !MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
4849
import GHC.Types (Nat)
50+
#endif
4951
import GHC.Generics (U1(..),Par1(..),(:*:)(..),(:.:)(..))
5052
import GHC.Exts (Coercible,coerce)
5153

inline/src/ConCat/Inline/Plugin.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import qualified ConCat.Inline.ClassOp as CO
1212
import Data.List (elemIndex)
1313

1414
-- GHC API
15+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
16+
import qualified GHC.Driver.Backend as Backend
17+
import GHC.Types.TyThing (lookupId, lookupTyCon)
18+
#endif
1519
#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
1620
import GHC.Core.Class (classAllSelIds)
1721
import GHC.Plugins
@@ -36,9 +40,14 @@ install _opts todos =
3640
do dflags <- getDynFlags
3741
-- Unfortunately, the plugin doesn't work in GHCi. Until fixed,
3842
-- disable under GHCi, so we can at least type-check conveniently.
43+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
44+
if backend dflags == Backend.Interpreter then
45+
return todos
46+
#else
3947
if hscTarget dflags == HscInterpreted then
4048
return todos
41-
else
49+
#endif
50+
else
4251
do
4352
#if !MIN_VERSION_GLASGOW_HASKELL(8,2,0,0)
4453
reinitializeGlobals

plugin/src/ConCat/Plugin.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ import GHC.Runtime.Loader
5959
import GHC.Tc.Utils.TcType (isFloatTy,isDoubleTy,isIntegerTy,isIntTy,isBoolTy,isUnitTy
6060
,tcSplitTyConApp_maybe)
6161
import GHC.Types.Id.Make (mkDictSelRhs,coerceId)
62+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
63+
import GHC.Builtin.Uniques (mkBuiltinUnique)
64+
#else
6265
import GHC.Types.Unique (mkBuiltinUnique)
66+
#endif
6367
import qualified GHC.Types.Unique.DFM as DFMap
6468
#else
6569
import GhcPlugins as GHC hiding (substTy,cat)

satisfy/src/ConCat/BuildDictionary.hs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import Control.Arrow (second)
3838
import GHC.Core.Predicate
3939
import GHC.Core.TyCo.Rep (CoercionHole(..), Type(..))
4040
import GHC.Core.TyCon (isTupleTyCon)
41-
import GHC.Driver.Finder (findExposedPackageModule)
4241
import GHC.HsToCore.Binds
4342
import GHC.HsToCore.Monad
4443
import GHC.Plugins
@@ -56,8 +55,16 @@ import GHC.Tc.Utils.Monad (getCtLocM,traceTc)
5655
import GHC.Tc.Utils.Zonk (emptyZonkEnv,zonkEvBinds)
5756
import GHC.Types.Unique (mkUniqueGrimily)
5857
import qualified GHC.Types.Unique.Set as NonDetSet
58+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
59+
import GHC.Runtime.Context (InteractiveContext (..), InteractiveImport (..))
60+
import GHC.Types.Error (getErrorMessages, getWarningMessages)
61+
import GHC.Unit.Finder (FindResult (..), findExposedPackageModule)
62+
import GHC.Unit.Module.Deps (Dependencies (..))
63+
import GHC.Utils.Error (pprMsgEnvelopeBagWithLoc)
64+
#else
65+
import GHC.Driver.Finder (findExposedPackageModule)
5966
import GHC.Utils.Error (pprErrMsgBagWithLoc)
60-
import GHC.Utils.Encoding (zEncodeString)
67+
#endif
6168
#else
6269
import GhcPlugins
6370
import TyCoRep (CoercionHole(..), Type(..))
@@ -82,7 +89,6 @@ import DsBinds
8289
import TcSimplify
8390
import TcRnTypes
8491
import ErrUtils (pprErrMsgBagWithLoc)
85-
import Encoding (zEncodeString)
8692
import Unique (mkUniqueGrimily)
8793
import Finder (findExposedPackageModule)
8894

@@ -150,9 +156,15 @@ runTcM env0 dflags guts m = do
150156
orphans <- filterM (moduleIsOkay env0) (moduleName <$> dep_orphs (mg_deps guts))
151157
-- pprTrace' "runTcM orphans" (ppr orphans) (return ())
152158
(msgs, mr) <- runTcInteractive (env orphans) m
159+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
160+
let showMsgs msg = showSDoc dflags $ vcat $
161+
text "Errors:" : pprMsgEnvelopeBagWithLoc (getErrorMessages msg)
162+
++ text "Warnings:" : pprMsgEnvelopeBagWithLoc (getWarningMessages msg)
163+
#else
153164
let showMsgs (warns, errs) = showSDoc dflags $ vcat $
154165
text "Errors:" : pprErrMsgBagWithLoc errs
155166
++ text "Warnings:" : pprErrMsgBagWithLoc warns
167+
#endif
156168
maybe (fail $ showMsgs msgs) return mr
157169
where
158170
imports0 = ic_imports (hsc_IC env0)
@@ -265,7 +277,11 @@ reallyBuildDictionary env dflags guts uniqSupply _inScope evType evTypes ev goal
265277
then dict
266278
else case evIds of
267279
[evId] -> mkCoreLet (NonRec evId ev) dict
280+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
281+
_ -> mkWildCase' ev evType goalTy [Alt (DataAlt (tupleDataCon Boxed (length evIds))) evIds dict]
282+
#else
268283
_ -> mkWildCase' ev evType goalTy [(DataAlt (tupleDataCon Boxed (length evIds)), evIds, dict)]
284+
#endif
269285

270286
evVarName :: FastString
271287
evVarName = mkFastString "evidence"
@@ -346,8 +362,13 @@ annotateExpr fnId fnId' typeArgsCount expr0 =
346362
go _evVars expr@(Type _) = expr
347363
go _evVars expr@(Coercion _) = expr
348364

365+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
366+
annotateAlt evVars (Alt con binders rhs) =
367+
Alt con binders $ go (extendEvVarsList evVars binders) rhs
368+
#else
349369
annotateAlt evVars (con, binders, rhs) =
350370
(con, binders, go (extendEvVarsList evVars binders) rhs)
371+
#endif
351372

352373
-- Maybe place in a GHC utils module.
353374

satisfy/src/ConCat/Satisfy/Plugin.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ module ConCat.Satisfy.Plugin where
1010
import System.IO.Unsafe (unsafePerformIO)
1111

1212
-- GHC API
13+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
14+
import GHC.Core.Unfold (defaultUnfoldingOpts)
15+
import qualified GHC.Driver.Backend as Backend
16+
import GHC.Utils.Logger (getLogger)
17+
#endif
1318
#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
1419
import GHC.Core.Class (classAllSelIds)
1520
import GHC.Core.Make (mkCoreTup)
@@ -43,8 +48,14 @@ install _opts todos =
4348
do dflags <- getDynFlags
4449
-- Unfortunately, the plugin doesn't work in GHCi. Until fixed,
4550
-- disable under GHCi, so we can at least type-check conveniently.
51+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
52+
logger <- getLogger
53+
if backend dflags == Backend.Interpreter then
54+
return todos
55+
#else
4656
if hscTarget dflags == HscInterpreted then
4757
return todos
58+
#endif
4859
else do
4960
#if !MIN_VERSION_GLASGOW_HASKELL(8,2,0,0)
5061
reinitializeGlobals
@@ -74,6 +85,12 @@ install _opts todos =
7485
, sm_inline = False -- important
7586
, sm_eta_expand = False -- ??
7687
, sm_case_case = True
88+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
89+
, sm_uf_opts = defaultUnfoldingOpts
90+
, sm_pre_inline = False
91+
, sm_logger = logger
92+
93+
#endif
7794
#if MIN_VERSION_GLASGOW_HASKELL(8,4,0,0)
7895
, sm_dflags = dflags
7996
#endif

satisfy/src/ConCat/Simplify.hs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,22 @@ module ConCat.Simplify (simplifyE) where
2323
import System.IO.Unsafe (unsafePerformIO)
2424

2525
#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
26+
#if !MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
2627
import GHC.Core (emptyRuleEnv)
28+
#endif
2729
import GHC.Core.FamInstEnv (emptyFamInstEnvs)
2830
import GHC.Core.Opt.OccurAnal (occurAnalyseExpr)
2931
import GHC.Core.Opt.Simplify (simplExpr)
3032
import GHC.Core.Opt.Simplify.Env
3133
import GHC.Core.Opt.Simplify.Monad (SimplM,initSmpl)
3234
import GHC.Core.Stats (exprSize)
3335
import GHC.Plugins
36+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
37+
import GHC.Core.Unfold (defaultUnfoldingOpts)
38+
import qualified GHC.Utils.Logger as Err
39+
#else
3440
import qualified GHC.Utils.Error as Err
41+
#endif
3542
#else
3643
import GhcPlugins
3744
import Simplify (simplExpr)
@@ -44,10 +51,15 @@ import OccurAnal (occurAnalyseExpr)
4451
import FamInstEnv (emptyFamInstEnvs)
4552
#endif
4653

54+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
55+
dumpIfSet_dyn' :: Err.Logger -> DynFlags -> DumpFlag -> String -> SDoc -> IO ()
56+
dumpIfSet_dyn' logger dflags dumpFlag str =
57+
Err.dumpIfSet_dyn logger dflags dumpFlag str Err.FormatCore
58+
#elif MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
4759
dumpIfSet_dyn' :: DynFlags -> DumpFlag -> String -> SDoc -> IO ()
48-
#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
4960
dumpIfSet_dyn' dflags dumpFlag str = Err.dumpIfSet_dyn dflags dumpFlag str Err.FormatCore
5061
#else
62+
dumpIfSet_dyn' :: DynFlags -> DumpFlag -> String -> SDoc -> IO ()
5163
dumpIfSet_dyn' = Err.dumpIfSet_dyn
5264
#endif
5365

@@ -71,15 +83,26 @@ simplifyExpr :: DynFlags -- includes spec of what core-to-core passes to do
7183
--
7284
-- Also used by Template Haskell
7385
simplifyExpr dflags inline expr
74-
= do us <- mkSplitUniqSupply 'r'
75-
let sz = exprSize expr
86+
= do let sz = exprSize expr
87+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
88+
logger <- Err.initLogger
89+
(expr', counts) <- initSmpl logger dflags emptyRuleEnv
90+
emptyFamInstEnvs sz
91+
(simplExprGently (simplEnvForCcc dflags inline logger) expr)
92+
Err.dumpIfSet logger dflags (dopt Opt_D_dump_simpl_stats dflags)
93+
"Simplifier statistics" (pprSimplCount counts)
94+
dumpIfSet_dyn' logger dflags Opt_D_dump_simpl "Simplified expression"
95+
(ppr expr')
96+
#else
97+
us <- mkSplitUniqSupply 'r'
7698
(expr', counts) <- initSmpl dflags emptyRuleEnv
7799
emptyFamInstEnvs us sz
78100
(simplExprGently (simplEnvForCcc dflags inline) expr)
79101
Err.dumpIfSet dflags (dopt Opt_D_dump_simpl_stats dflags)
80102
"Simplifier statistics" (pprSimplCount counts)
81103
dumpIfSet_dyn' dflags Opt_D_dump_simpl "Simplified expression"
82104
(ppr expr')
105+
#endif
83106
return expr'
84107

85108
-- Copied from SimplCore (not exported)
@@ -89,6 +112,24 @@ simplExprGently env expr = do
89112
simplExpr env (occurAnalyseExpr expr1)
90113

91114
-- Like simplEnvForGHCi but with inlining.
115+
#if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
116+
simplEnvForCcc :: DynFlags -> Bool -> Err.Logger -> SimplEnv
117+
simplEnvForCcc dflags inline logger
118+
= mkSimplEnv $ SimplMode { sm_names = ["Simplify for ccc"]
119+
, sm_phase = Phase 0 -- Was InitialPhase
120+
, sm_rules = rules_on
121+
, sm_inline = inline -- was False
122+
, sm_eta_expand = eta_expand_on
123+
, sm_case_case = True
124+
, sm_uf_opts = defaultUnfoldingOpts
125+
, sm_pre_inline = inline
126+
, sm_logger = logger
127+
, sm_dflags = dflags
128+
}
129+
where
130+
rules_on = gopt Opt_EnableRewriteRules dflags
131+
eta_expand_on = gopt Opt_DoLambdaEtaExpansion dflags
132+
#else
92133
simplEnvForCcc :: DynFlags -> Bool -> SimplEnv
93134
simplEnvForCcc dflags inline
94135
= mkSimplEnv $ SimplMode { sm_names = ["Simplify for ccc"]
@@ -104,3 +145,4 @@ simplEnvForCcc dflags inline
104145
where
105146
rules_on = gopt Opt_EnableRewriteRules dflags
106147
eta_expand_on = gopt Opt_DoLambdaEtaExpansion dflags
148+
#endif

0 commit comments

Comments
 (0)