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

Widen support to GHC-7.4...GHC-8.8 #74

Merged
merged 2 commits into from
May 17, 2019
Merged
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
3 changes: 3 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
- ignore: {name: "Use first"}
- ignore: {name: "Use second"}

# Use LambdaCase -- we cannot, GHC-7.6+ feature
- ignore: {name: "Use lambda-case"}

# Not all 3-liners should be deduplicated
- ignore: {name: Reduce duplication, within: Data.Text.Prettyprint.Doc.Render.Terminal.Internal}

Expand Down
3 changes: 2 additions & 1 deletion aux/version-compatibility-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#define MONOID_IN_PRELUDE MIN_VERSION_base(4,8,0)
#define NATURAL_IN_BASE MIN_VERSION_base(4,8,0)

#define MONAD_FAIL MIN_VERSION_base(4,9,0)
#define SEMIGROUP_IN_BASE MIN_VERSION_base(4,9,0)

#define NO_FAIL_IN_MONAD_MONAD_FAIL MIN_VERSION_base(4,13,0)

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ library
default-language: Haskell2010
other-extensions:
CPP
, LambdaCase
, OverloadedStrings


build-depends:
base >= 4.7 && < 5
base >= 4.5 && < 5
, ansi-terminal >= 0.4.0
, text >= 1.2
, prettyprinter >= 1.1.1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

#include "version-compatibility-macros.h"
Expand All @@ -26,7 +25,19 @@ import System.IO (Handle, hPutChar, stdout)
import Data.Text.Prettyprint.Doc
import Data.Text.Prettyprint.Doc.Render.Util.Panic

#if !MIN_VERSION_base(4,6,0)
modifyIORef' :: IORef a -> (a -> a) -> IO ()
modifyIORef' ref f = do
x <- readIORef ref
let x' = f x
x' `seq` writeIORef ref x'

modifySTRef' :: STRef s a -> (a -> a) -> ST s ()
modifySTRef' ref f = do
x <- readSTRef ref
let x' = f x
x' `seq` writeSTRef ref x'
#endif

-- $setup
--
Expand Down Expand Up @@ -110,15 +121,15 @@ renderLazy sdoc = runST (do
outputRef <- newSTRef mempty

let push x = modifySTRef' styleStackRef (x :)
unsafePeek = readSTRef styleStackRef >>= \case
unsafePeek = readSTRef styleStackRef >>= \tok -> case tok of
[] -> panicPeekedEmpty
x:_ -> pure x
unsafePop = readSTRef styleStackRef >>= \case
unsafePop = readSTRef styleStackRef >>= \tok -> case tok of
[] -> panicPeekedEmpty
x:xs -> writeSTRef styleStackRef xs >> pure x
writeOutput x = modifySTRef outputRef (<> x)

let go = \case
let go = \sds -> case sds of
SFail -> panicUncaughtFail
SEmpty -> pure ()
SChar c rest -> do
Expand All @@ -142,7 +153,7 @@ renderLazy sdoc = runST (do
writeOutput (TLB.fromText (styleToRawText newStyle))
go rest
go sdoc
readSTRef styleStackRef >>= \case
readSTRef styleStackRef >>= \stack -> case stack of
[] -> panicStyleStackFullyConsumed
[_] -> fmap TLB.toLazyText (readSTRef outputRef)
xs -> panicStyleStackNotFullyConsumed (length xs) )
Expand Down Expand Up @@ -172,14 +183,14 @@ renderIO h sdoc = do
styleStackRef <- newIORef [mempty]

let push x = modifyIORef' styleStackRef (x :)
unsafePeek = readIORef styleStackRef >>= \case
unsafePeek = readIORef styleStackRef >>= \tok -> case tok of
[] -> panicPeekedEmpty
x:_ -> pure x
unsafePop = readIORef styleStackRef >>= \case
unsafePop = readIORef styleStackRef >>= \tok -> case tok of
[] -> panicPeekedEmpty
x:xs -> writeIORef styleStackRef xs >> pure x

let go = \case
let go = \sds -> case sds of
SFail -> panicUncaughtFail
SEmpty -> pure ()
SChar c rest -> do
Expand All @@ -204,7 +215,7 @@ renderIO h sdoc = do
T.hPutStr h (styleToRawText newStyle)
go rest
go sdoc
readIORef styleStackRef >>= \case
readIORef styleStackRef >>= \stack -> case stack of
[] -> panicStyleStackFullyConsumed
[_] -> pure ()
xs -> panicStyleStackNotFullyConsumed (length xs)
Expand Down Expand Up @@ -288,12 +299,12 @@ styleToRawText = T.pack . ANSI.setSGRCode . stylesToSgrs
]

convertIntensity :: Intensity -> ANSI.ColorIntensity
convertIntensity = \case
convertIntensity = \i -> case i of
Vivid -> ANSI.Vivid
Dull -> ANSI.Dull

convertColor :: Color -> ANSI.Color
convertColor = \case
convertColor = \c -> case c of
Black -> ANSI.Black
Red -> ANSI.Red
Green -> ANSI.Green
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ library
other-extensions: CPP

build-depends:
base >= 4.7 && < 5
base >= 4.5 && < 5
, text >= 1.2
, prettyprinter >= 1
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ module Text.PrettyPrint.Annotated.Leijen {-# DEPRECATED "Compatibility module fo

) where



#if MIN_VERSION_base(4,8,0)
import Prelude hiding ((<$>))
#else
import Prelude
#endif

#if !(MONOID_IN_PRELUDE)
import Data.Monoid hiding ((<>))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ library
default-language: Haskell2010
other-extensions:
CPP
, LambdaCase
, OverloadedStrings

build-depends:
base >= 4.7 && < 5 && < 5
base >= 4.5 && < 5 && < 5
, text >= 1.2
, prettyprinter >= 1
, prettyprinter-ansi-terminal >= 1.1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

module Text.PrettyPrint.ANSI.Leijen {-# DEPRECATED "Compatibility module for users of ansi-wl-pprint - use Data.Text.Prettyprint.Doc instead" #-} (

Doc, putDoc, hPutDoc, empty, char, text, (<>), nest, line, linebreak, group,
Expand All @@ -17,9 +19,11 @@ module Text.PrettyPrint.ANSI.Leijen {-# DEPRECATED "Compatibility module for use

) where



#if MIN_VERSION_base(4,8,0)
import Prelude hiding ((<$>))
#else
import Prelude
#endif

import Data.Monoid
import qualified Data.Text.Lazy as TL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ library
default-language: Haskell2010
other-extensions:
CPP
, LambdaCase
, OverloadedStrings

build-depends:
base >= 4.7 && < 5
base >= 4.5 && < 5
, text >= 1.2
, prettyprinter >= 1
6 changes: 6 additions & 0 deletions prettyprinter-compat-wl-pprint/src/Text/PrettyPrint/Leijen.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

module Text.PrettyPrint.Leijen {-# DEPRECATED "Compatibility module for users of wl-pprint - use Data.Text.Prettyprint.Doc instead" #-} (

Doc, putDoc, hPutDoc, empty, char, text, (<>), nest, line, linebreak, group,
Expand All @@ -14,7 +16,11 @@ module Text.PrettyPrint.Leijen {-# DEPRECATED "Compatibility module for users of



#if MIN_VERSION_base(4,8,0)
import Prelude hiding ((<$>))
#else
import Prelude
#endif

import Data.Monoid
import qualified Data.Text.Lazy as TL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ library
default-language: Haskell2010
other-extensions:
CPP
, LambdaCase
, OverloadedStrings

build-depends:
base >= 4.7 && < 5
base >= 4.5 && < 5
, text >= 1.2
, prettyprinter >= 1
, prettyprinter-ansi-terminal >= 1.1.1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE LambdaCase #-}

-- | Convert back and forth between the 'Old.Doc' type of the @ansi-wl-pprint@
-- and the 'New.Doc' of the prettyprinter package. Useful in order to use the
-- @prettyprinter@ library together with another library that produces
Expand Down Expand Up @@ -34,7 +32,7 @@ import qualified Text.PrettyPrint.ANSI.Leijen.Internal as Old

-- | @ansi-wl-pprint ───▷ prettyprinter@
fromAnsiWlPprint :: Old.Doc -> New.Doc NewTerm.AnsiStyle
fromAnsiWlPprint = \case
fromAnsiWlPprint = \doc -> case doc of
Old.Fail -> New.Fail
Old.Empty -> New.Empty
Old.Char c -> New.Char c
Expand Down Expand Up @@ -87,7 +85,7 @@ fromAnsiWlPprint = \case

-- | @prettyprinter ───▷ ansi-wl-pprint@
toAnsiWlPprint :: New.Doc NewTerm.AnsiStyle -> Old.Doc
toAnsiWlPprint = \case
toAnsiWlPprint = \doc -> case doc of
New.Fail -> Old.Fail
New.Empty -> Old.Empty
New.Char c -> Old.Char c
Expand Down
10 changes: 5 additions & 5 deletions prettyprinter/bench/LargeOutput.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

{-# OPTIONS_GHC -fno-warn-orphans #-}

module Main (main) where


import Prelude ()
import Prelude.Compat

import Control.DeepSeq
import Control.Monad
import Control.Monad.Compat
import Criterion
import Criterion.Main
import Data.Char
Expand Down Expand Up @@ -98,7 +98,7 @@ instance Pretty LambdaForm where
prettyExp = (<+> pretty body)

instance Pretty Expr where
pretty = \case
pretty = \expr -> case expr of
Let binds body ->
align (vsep [ "let" <+> align (pretty binds)
, "in" <+> pretty body ])
Expand Down Expand Up @@ -141,7 +141,7 @@ instance WL.Pretty LambdaForm where
prettyExp = (WL.<+> WL.pretty body)

instance WL.Pretty Expr where
pretty = \case
pretty = \expr -> case expr of
Let binds body ->
WL.align (WL.vsep [ "let" WL.<+> WL.align (WL.pretty binds)
, "in" WL.<+> WL.pretty body ])
Expand Down
22 changes: 16 additions & 6 deletions prettyprinter/prettyprinter.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,23 @@ library
other-extensions:
BangPatterns
, CPP
, LambdaCase
, OverloadedStrings
, QuasiQuotes
, DefaultSignatures
, ScopedTypeVariables

build-depends:
base >= 4.7 && < 5
base >= 4.5 && < 5
, text >= 1.2

if !impl(ghc >= 7.6)
build-depends: ghc-prim

if impl(ghc >= 8.0)
ghc-options: -Wcompat
if !impl(ghc >= 8.0)
build-depends: semigroups >= 0.1
build-depends: fail >= 4.9.0.0 && < 4.10
if !impl(ghc >= 7.10)
build-depends: void

Expand Down Expand Up @@ -141,7 +144,7 @@ benchmark fusion
hs-source-dirs: bench
main-is: Fusion.hs
build-depends:
base >= 4.7 && < 5
base >= 4.5 && < 5
, prettyprinter

, criterion >= 1.1
Expand All @@ -152,11 +155,11 @@ benchmark fusion
, ansi-wl-pprint >= 0.6
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
other-extensions: NumDecimals, OverloadedStrings
other-extensions: OverloadedStrings

benchmark faster-unsafe-text
build-depends:
base >= 4.7 && < 5
base >= 4.5 && < 5
, prettyprinter

, criterion >= 1.1
Expand All @@ -171,7 +174,8 @@ benchmark faster-unsafe-text

benchmark large-output
build-depends:
base >= 4.7 && < 5
base >= 4.5 && < 5
, base-compat >=0.10.5 && <0.11
, prettyprinter
, ansi-wl-pprint

Expand All @@ -186,3 +190,9 @@ benchmark large-output
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
default-language: Haskell2010
type: exitcode-stdio-1.0

if !impl(ghc >= 7.6)
build-depends: ghc-prim

if !impl(ghc >= 8.0)
build-depends: semigroups
Loading