Skip to content

Commit 6d2eb5e

Browse files
authored
GHC 9.12 (#151)
1 parent a9fe689 commit 6d2eb5e

File tree

6 files changed

+231
-31
lines changed

6 files changed

+231
-31
lines changed

apply-refact.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extra-source-files:
2222
tests/examples/*.hs.expected
2323
tests/examples/*.hs.refact
2424

25-
tested-with: GHC ==9.2.8 || ==9.4.6 || ==9.6.6 || ==9.8.2
25+
tested-with: GHC ==9.2.8 || ==9.4.6 || ==9.6.6 || ==9.8.2 || ==9.12.1
2626

2727
source-repository head
2828
type: git
@@ -44,8 +44,9 @@ library
4444
, directory >=1.3
4545
, extra >=1.7.3
4646
, filemanip >=0.3.6.3 && <0.4
47+
, ghc
4748
, ghc-boot-th
48-
, ghc-exactprint ^>=1.5.0 || ^>=1.6.0 || ^>=1.7.0 || ^>=1.8.0
49+
, ghc-exactprint ^>=1.5.0 || ^>=1.6.0 || ^>=1.7.0 || ^>=1.8.0 || ^>=1.12.0
4950
, process >=1.6
5051
, refact >=0.2
5152
, syb >=0.7.1

src/Refact/Compat.hs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
module Refact.Compat (
66
-- * ApiAnnotation / GHC.Parser.ApiAnnotation
7+
#if MIN_VERSION_ghc(9,12,0)
8+
#else
79
AnnKeywordId (..),
10+
#endif
811
DeltaPos(..),
912

1013
-- * BasicTypes / GHC.Types.Basic
@@ -93,6 +96,12 @@ module Refact.Compat (
9396
setSrcSpanFile,
9497
srcSpanToAnnSpan,
9598
AnnSpan,
99+
commentSrcSpan,
100+
ann,
101+
transferEntryDP,
102+
transferEntryDP',
103+
AnnConstraint,
104+
showAst,
96105

97106
#if MIN_VERSION_ghc(9,4,0)
98107
-- * GHC 9.4 stuff
@@ -101,7 +110,11 @@ module Refact.Compat (
101110
) where
102111

103112
import Control.Monad.Trans.State.Strict (StateT)
113+
#if MIN_VERSION_ghc(9,12,0)
114+
import Data.Data (Data, Typeable)
115+
#else
104116
import Data.Data (Data)
117+
#endif
105118
import qualified GHC
106119
import GHC.Data.Bag (unitBag, bagToList)
107120
import GHC.Data.FastString (FastString, mkFastString)
@@ -115,7 +128,7 @@ import GHC.Driver.Errors.Types (ErrorMessages, ghcUnknownMessage, GhcMessage)
115128
#endif
116129
import GHC.Driver.Session hiding (initDynFlags)
117130
#if MIN_VERSION_ghc(9,6,0)
118-
import GHC.Hs hiding (Pat, Stmt, parseModuleName)
131+
import GHC.Hs hiding (Pat, Stmt, parseModuleName, ann)
119132
#else
120133
import GHC.Hs hiding (Pat, Stmt)
121134
#endif
@@ -148,6 +161,18 @@ import GHC.Utils.Panic
148161
import Language.Haskell.GHC.ExactPrint.Parsers (Parser)
149162
import Language.Haskell.GHC.ExactPrint.Utils
150163
import Refact.Types (Refactoring)
164+
#if MIN_VERSION_ghc(9,12,0)
165+
import qualified Language.Haskell.GHC.ExactPrint.Transform as Exact
166+
#else
167+
import Language.Haskell.GHC.ExactPrint (transferEntryDP, transferEntryDP', showAst)
168+
#endif
169+
170+
171+
#if MIN_VERSION_ghc(9,12,0)
172+
type AnnConstraint an = (NoAnn an, Semigroup an)
173+
#else
174+
type AnnConstraint an = (Monoid an)
175+
#endif
151176

152177
type MonadFail' = MonadFail
153178

@@ -171,7 +196,11 @@ ppp pst = concatMap unDecorated $ fmap (diagnosticMessage . errMsgDiagnostic) $
171196
ppp pst = concatMap unDecorated (errMsgDiagnostic <$> bagToList pst)
172197
#endif
173198

199+
#if MIN_VERSION_ghc(9,12,0)
200+
type FunBind = HsMatchContext (LocatedN RdrName)
201+
#else
174202
type FunBind = HsMatchContext GhcPs
203+
#endif
175204

176205
pattern RealSrcLoc' :: RealSrcLoc -> SrcLoc
177206
pattern RealSrcLoc' r <- RealSrcLoc r _ where
@@ -266,3 +295,33 @@ type ReplaceWorker a mod =
266295
Int ->
267296
Refactoring SrcSpan ->
268297
IO mod
298+
299+
300+
commentSrcSpan :: GHC.LEpaComment -> SrcSpan
301+
#if MIN_VERSION_ghc(9,12,0)
302+
commentSrcSpan (GHC.L (GHC.EpaSpan l) _) = l
303+
commentSrcSpan (GHC.L (GHC.EpaDelta l _ _) _) = l
304+
#else
305+
commentSrcSpan (GHC.L (GHC.Anchor l _) _) = GHC.RealSrcSpan l Strict.Nothing
306+
#endif
307+
308+
#if MIN_VERSION_ghc(9,12,0)
309+
transferEntryDP :: (Typeable t1, Typeable t2, Exact.HasTransform m)
310+
=> LocatedAn t1 a -> LocatedAn t2 b -> m (LocatedAn t2 b)
311+
transferEntryDP a b = return $ Exact.transferEntryDP a b
312+
#endif
313+
314+
#if MIN_VERSION_ghc(9,12,0)
315+
transferEntryDP' ::(Exact.HasTransform m)
316+
=> LHsDecl GhcPs -> LHsDecl GhcPs -> m (LHsDecl GhcPs)
317+
transferEntryDP' a b = return $ Exact.transferEntryDP' a b
318+
#endif
319+
320+
321+
#if MIN_VERSION_ghc(9,12,0)
322+
ann :: EpAnn a -> a
323+
ann ls = GHC.anns ls
324+
#else
325+
ann :: SrcSpanAnn' a -> a
326+
ann = GHC.ann
327+
#endif

src/Refact/Fixity.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE OverloadedStrings #-}
23
{-# LANGUAGE ViewPatterns #-}
34

@@ -7,8 +8,8 @@ import Control.Monad.Trans.State
78
import Data.Generics hiding (Fixity)
89
import Data.Maybe
910
import qualified GHC
10-
import Language.Haskell.GHC.ExactPrint
11-
import Refact.Compat (Fixity (..), SourceText (..), occNameString, rdrNameOcc)
11+
import Language.Haskell.GHC.ExactPrint hiding (transferEntryDP)
12+
import Refact.Compat (Fixity (..), SourceText (..), occNameString, rdrNameOcc,transferEntryDP)
1213
import Refact.Utils
1314

1415
-- | Rearrange infix expressions to account for fixity.
@@ -31,10 +32,13 @@ getIdent _ = error "Must be HsVar"
3132
mkOpAppRn ::
3233
[(String, GHC.Fixity)] ->
3334
GHC.SrcSpanAnnA ->
35+
#if MIN_VERSION_ghc(9,12,0)
36+
GHC.NoExtField ->
37+
#else
3438
GHC.EpAnn [GHC.AddEpAnn] ->
39+
#endif
3540
Expr -> -- Left operand; already rearranged
36-
Expr ->
37-
GHC.Fixity -> -- Operator and fixity
41+
Expr -> GHC.Fixity -> -- Operator and fixity
3842
Expr -> -- Right operand (not an OpApp, but might
3943
-- be a NegApp)
4044
StateT () IO Expr
@@ -151,4 +155,8 @@ infix_ = fixity GHC.InfixN
151155

152156
-- Internal: help function for the above definitions.
153157
fixity :: GHC.FixityDirection -> Int -> [String] -> [(String, GHC.Fixity)]
158+
#if MIN_VERSION_ghc(9,12,0)
159+
fixity a p = map (,Fixity p a)
160+
#else
154161
fixity a p = map (,Fixity (SourceText "") p a)
162+
#endif

0 commit comments

Comments
 (0)