Skip to content

Commit 05bc7a7

Browse files
committed
Remove compatibility code for GHC < 8
Follow-up to 92cc704 (drop GHC 7 support). Remove code that was only needed for GHC versions older than 8: - Remove CPP macros always true with base >= 4.9: APPLICATIVE_MONAD, FUNCTOR_IDENTITY_IN_BASE, MONOID_IN_PRELUDE, NATURAL_IN_BASE, SEMIGROUP_IN_BASE - Remove conditional dependencies on semigroups, fail, void, ghc-prim - Always enable -Wcompat (was conditional on GHC >= 8.0) - Remove doctest buildability conditions for GHC < 7.10 - Remove unused Control.Applicative imports (in Prelude since base 4.8) Assisted-by: GLM-5 <noreply@fireworks.ai>
1 parent d2ddf82 commit 05bc7a7

18 files changed

Lines changed: 14 additions & 121 deletions

File tree

misc/version-compatibility-macros.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
-- These macros allow writing CPP compatibility hacks in a way that makes their
99
-- purpose much clearer than just demanding a specific version of a library.
1010

11-
#define APPLICATIVE_MONAD MIN_VERSION_base(4,8,0)
12-
#define FOLDABLE_TRAVERSABLE_IN_PRELUDE (MIN_VERSION_base(4,8,0) && !defined(__MHS__))
13-
#define FUNCTOR_IDENTITY_IN_BASE MIN_VERSION_base(4,8,0)
14-
#define MONOID_IN_PRELUDE MIN_VERSION_base(4,8,0)
15-
#define NATURAL_IN_BASE MIN_VERSION_base(4,8,0)
11+
#define FOLDABLE_TRAVERSABLE_IN_PRELUDE !defined(__MHS__)
1612

17-
#define SEMIGROUP_IN_BASE MIN_VERSION_base(4,9,0)
13+
#define LIFTA2_IN_PRELUDE MIN_VERSION_base(4,18,0)
1814

1915
#define SEMIGROUP_MONOID_SUPERCLASS MIN_VERSION_base(4,11,0)
2016

prettyprinter-ansi-terminal/prettyprinter-ansi-terminal.cabal

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ library
3434
, Data.Text.Prettyprint.Doc.Render.Terminal.Internal
3535
, Prettyprinter.Render.Terminal
3636
, Prettyprinter.Render.Terminal.Internal
37-
ghc-options: -Wall -O2
37+
ghc-options: -Wall -O2 -Wcompat
3838
hs-source-dirs: src
3939
include-dirs: misc
4040
default-language: Haskell2010
@@ -58,11 +58,6 @@ library
5858
, Data.Text.Lazy
5959
, Data.Text.Lazy.Builder
6060

61-
if impl(ghc >= 8.0)
62-
ghc-options: -Wcompat
63-
if !impl(ghc >= 8.0) && !impl(mhs)
64-
build-depends: semigroups >= 0.1
65-
6661
test-suite doctest
6762
type: exitcode-stdio-1.0
6863
hs-source-dirs: test/Doctest
@@ -72,9 +67,6 @@ test-suite doctest
7267
, doctest >= 0.9
7368
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
7469
default-language: Haskell2010
75-
if impl (ghc < 7.10)
76-
buildable: False
77-
-- Doctest cannot search folders in old versions it seems :-(
7870

7971
benchmark large-output
8072
build-depends:
@@ -93,7 +85,3 @@ benchmark large-output
9385
ghc-options: -O2 -rtsopts -Wall
9486
default-language: Haskell2010
9587
type: exitcode-stdio-1.0
96-
97-
-- For GHC.Generics
98-
if !impl(ghc >= 7.6)
99-
build-depends: ghc-prim

prettyprinter-ansi-terminal/src/Prettyprinter/Render/Terminal/Internal.hs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,7 @@ import Prettyprinter
5353
import Prettyprinter.Render.Util.Panic
5454

5555
#if !(SEMIGROUP_MONOID_SUPERCLASS)
56-
import Data.Semigroup
57-
#endif
58-
59-
#if !(MIN_VERSION_base(4,6,0))
60-
modifyIORef' :: IORef a -> (a -> a) -> IO ()
61-
modifyIORef' ref f = do
62-
x <- readIORef ref
63-
let x' = f x
64-
x' `seq` writeIORef ref x'
56+
import Data.Semigroup (Semigroup(..))
6557
#endif
6658

6759
-- $setup

prettyprinter-compat-annotated-wl-pprint/src/Text/PrettyPrint/Annotated/Leijen.hs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ module Text.PrettyPrint.Annotated.Leijen {-# DEPRECATED "Compatibility module fo
1717

1818
) where
1919

20-
#if MIN_VERSION_base(4,8,0)
2120
import Prelude hiding ((<$>))
22-
#else
23-
import Prelude
24-
#endif
2521

26-
#if !(MONOID_IN_PRELUDE)
27-
import Data.Monoid hiding ((<>))
22+
#if !(LIFTA2_IN_PRELUDE)
23+
import Control.Applicative (liftA2)
2824
#endif
2925

30-
import Control.Applicative hiding (empty, (<$>))
3126
import qualified Data.Text as T
3227
import qualified Data.Text.IO as T
3328
import System.IO

prettyprinter-compat-ansi-wl-pprint/prettyprinter-compat-ansi-wl-pprint.cabal

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,3 @@ library
3333
, text >= 1.2
3434
, prettyprinter >= 1.7.0
3535
, prettyprinter-ansi-terminal >= 1.1
36-
37-
if !impl(ghc >= 8.0) && !impl(mhs)
38-
build-depends: semigroups >= 0.1

prettyprinter-compat-ansi-wl-pprint/src/Text/PrettyPrint/ANSI/Leijen.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ module Text.PrettyPrint.ANSI.Leijen {-# DEPRECATED "Compatibility module for use
1919

2020
) where
2121

22-
#if MIN_VERSION_base(4,8,0)
2322
import Prelude hiding ((<$>))
24-
#else
25-
import Prelude
26-
#endif
2723

2824
import qualified Data.Text.Lazy as TL
2925
import System.IO

prettyprinter-compat-wl-pprint/prettyprinter-compat-wl-pprint.cabal

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,3 @@ library
3131
base >= 4.9 && < 5
3232
, text >= 1.2
3333
, prettyprinter >= 1.7.0
34-
35-
if !impl(ghc >= 8.0) && !impl(mhs)
36-
build-depends: semigroups >= 0.1

prettyprinter-compat-wl-pprint/src/Text/PrettyPrint/Leijen.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ module Text.PrettyPrint.Leijen {-# DEPRECATED "Compatibility module for users of
1616

1717

1818

19-
#if MIN_VERSION_base(4,8,0)
2019
import Prelude hiding ((<$>))
21-
#else
22-
import Prelude
23-
#endif
2420

2521
import qualified Data.Text.Lazy as TL
2622
import System.IO

prettyprinter-convert-ansi-wl-pprint/prettyprinter-convert-ansi-wl-pprint.cabal

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,3 @@ test-suite doctest
4545
, doctest >= 0.9
4646
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
4747
default-language: Haskell2010
48-
if impl (ghc < 7.10)
49-
buildable: False
50-
-- Doctest does not support searching through directories in old versions

prettyprinter/bench/Fusion.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import Prettyprinter
1818
import Prettyprinter.Render.Text
1919
import qualified Text.PrettyPrint.ANSI.Leijen as WL
2020

21-
#if !(APPLICATIVE_MONAD)
22-
import Control.Applicative
23-
#endif
24-
2521

2622

2723
main :: IO ()
@@ -47,12 +43,14 @@ benchOptimize = env randomShortWords benchmark_
4743
randomShortWords' :: Int -> State StdGen [Text]
4844
randomShortWords' n = replicateM n randomShortWord
4945

46+
-- Note: 'split' is deprecated in random >= 1.2 in favor of 'splitGen'.
47+
-- We could use 'splitGen' when support for GHC < 9.0 is dropped.
5048
randomShortWord :: State StdGen Text
5149
randomShortWord = do
5250
g <- get
5351
let (l, g') = randomR (0, 5) g
5452
(gNew, gFree) = split g'
55-
xs = take l (randoms gFree)
53+
xs = take l (randoms gFree :: [Char])
5654
put gNew
5755
pure (T.pack xs)
5856

0 commit comments

Comments
 (0)