Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHC 9.12 #151

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apply-refact.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extra-source-files:
tests/examples/*.hs.expected
tests/examples/*.hs.refact

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

source-repository head
type: git
Expand All @@ -44,8 +44,9 @@ library
, directory >=1.3
, extra >=1.7.3
, filemanip >=0.3.6.3 && <0.4
, ghc
, ghc-boot-th
, ghc-exactprint ^>=1.5.0 || ^>=1.6.0 || ^>=1.7.0 || ^>=1.8.0
, ghc-exactprint ^>=1.5.0 || ^>=1.6.0 || ^>=1.7.0 || ^>=1.8.0 || ^>=1.12.0
, process >=1.6
, refact >=0.2
, syb >=0.7.1
Expand Down
61 changes: 60 additions & 1 deletion src/Refact/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

module Refact.Compat (
-- * ApiAnnotation / GHC.Parser.ApiAnnotation
#if MIN_VERSION_ghc(9,12,0)
#else
AnnKeywordId (..),
#endif
DeltaPos(..),

-- * BasicTypes / GHC.Types.Basic
Expand Down Expand Up @@ -93,6 +96,12 @@
setSrcSpanFile,
srcSpanToAnnSpan,
AnnSpan,
commentSrcSpan,
ann,
transferEntryDP,
transferEntryDP',
AnnConstraint,
showAst,

#if MIN_VERSION_ghc(9,4,0)
-- * GHC 9.4 stuff
Expand All @@ -101,7 +110,11 @@
) where

import Control.Monad.Trans.State.Strict (StateT)
#if MIN_VERSION_ghc(9,12,0)
import Data.Data (Data, Typeable)
#else
import Data.Data (Data)
#endif
import qualified GHC
import GHC.Data.Bag (unitBag, bagToList)
import GHC.Data.FastString (FastString, mkFastString)
Expand All @@ -115,7 +128,7 @@
#endif
import GHC.Driver.Session hiding (initDynFlags)
#if MIN_VERSION_ghc(9,6,0)
import GHC.Hs hiding (Pat, Stmt, parseModuleName)
import GHC.Hs hiding (Pat, Stmt, parseModuleName, ann)
#else
import GHC.Hs hiding (Pat, Stmt)
#endif
Expand Down Expand Up @@ -148,6 +161,18 @@
import Language.Haskell.GHC.ExactPrint.Parsers (Parser)
import Language.Haskell.GHC.ExactPrint.Utils
import Refact.Types (Refactoring)
#if MIN_VERSION_ghc(9,12,0)
import qualified Language.Haskell.GHC.ExactPrint.Transform as Exact
#else
import Language.Haskell.GHC.ExactPrint (transferEntryDP, transferEntryDP', showAst)
#endif


#if MIN_VERSION_ghc(9,12,0)
type AnnConstraint an = (NoAnn an, Semigroup an)
#else
type AnnConstraint an = (Monoid an)
#endif

type MonadFail' = MonadFail

Expand All @@ -171,7 +196,11 @@
ppp pst = concatMap unDecorated (errMsgDiagnostic <$> bagToList pst)
#endif

#if MIN_VERSION_ghc(9,12,0)
type FunBind = HsMatchContext (LocatedN RdrName)
#else
type FunBind = HsMatchContext GhcPs
#endif

pattern RealSrcLoc' :: RealSrcLoc -> SrcLoc
pattern RealSrcLoc' r <- RealSrcLoc r _ where
Expand Down Expand Up @@ -266,3 +295,33 @@
Int ->
Refactoring SrcSpan ->
IO mod


commentSrcSpan :: GHC.LEpaComment -> SrcSpan
#if MIN_VERSION_ghc(9,12,0)
commentSrcSpan (GHC.L (GHC.EpaSpan l) _) = l
commentSrcSpan (GHC.L (GHC.EpaDelta l _ _) _) = l
#else
commentSrcSpan (GHC.L (GHC.Anchor l _) _) = GHC.RealSrcSpan l Strict.Nothing

Check failure on line 305 in src/Refact/Compat.hs

View workflow job for this annotation

GitHub Actions / build (9.2.8)

Not in scope: data constructor ‘Strict.Nothing’
#endif

#if MIN_VERSION_ghc(9,12,0)
transferEntryDP :: (Typeable t1, Typeable t2, Exact.HasTransform m)
=> LocatedAn t1 a -> LocatedAn t2 b -> m (LocatedAn t2 b)
transferEntryDP a b = return $ Exact.transferEntryDP a b
#endif

#if MIN_VERSION_ghc(9,12,0)
transferEntryDP' ::(Exact.HasTransform m)
=> LHsDecl GhcPs -> LHsDecl GhcPs -> m (LHsDecl GhcPs)
transferEntryDP' a b = return $ Exact.transferEntryDP' a b
#endif


#if MIN_VERSION_ghc(9,12,0)
ann :: EpAnn a -> a
ann ls = GHC.anns ls
#else
ann :: SrcSpanAnn' a -> a
ann = GHC.ann
#endif
16 changes: 12 additions & 4 deletions src/Refact/Fixity.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

Expand All @@ -7,8 +8,8 @@ import Control.Monad.Trans.State
import Data.Generics hiding (Fixity)
import Data.Maybe
import qualified GHC
import Language.Haskell.GHC.ExactPrint
import Refact.Compat (Fixity (..), SourceText (..), occNameString, rdrNameOcc)
import Language.Haskell.GHC.ExactPrint hiding (transferEntryDP)
import Refact.Compat (Fixity (..), SourceText (..), occNameString, rdrNameOcc,transferEntryDP)
import Refact.Utils

-- | Rearrange infix expressions to account for fixity.
Expand All @@ -31,10 +32,13 @@ getIdent _ = error "Must be HsVar"
mkOpAppRn ::
[(String, GHC.Fixity)] ->
GHC.SrcSpanAnnA ->
#if MIN_VERSION_ghc(9,12,0)
GHC.NoExtField ->
#else
GHC.EpAnn [GHC.AddEpAnn] ->
#endif
Expr -> -- Left operand; already rearranged
Expr ->
GHC.Fixity -> -- Operator and fixity
Expr -> GHC.Fixity -> -- Operator and fixity
Expr -> -- Right operand (not an OpApp, but might
-- be a NegApp)
StateT () IO Expr
Expand Down Expand Up @@ -151,4 +155,8 @@ infix_ = fixity GHC.InfixN

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