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 8.4 compatibility. #186

Merged
merged 6 commits into from
Feb 12, 2018
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
14 changes: 5 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ matrix:
packages:
- ghc-8.2.1
- cabal-install-1.24
- env: GHCVER=8.4.1 CABALVER=head GHCHEAD=true
- env: GHCVER=8.4.1 CABALVER=head
addons:
apt:
sources:
Expand All @@ -53,20 +53,16 @@ matrix:
- ghc-8.4.1
- cabal-install-head
allow_failures:
- env: GHCVER=8.4.1 CABALVER=head GHCHEAD=true
- env: GHCVER=8.4.1 CABALVER=head

before_install:
- export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- ghc --version
- cabal --version
- travis_retry cabal update
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
- ALLOW_NEWER=''
- if ${GHCHEAD-false} ; then ALLOW_NEWER='--allow-newer' ; fi
- cabal install --enable-tests --only-dep $ALLOW_NEWER
- cabal install --enable-tests --only-dep

script:
- WERROR='--ghc-options=-Werror'
- if ${GHCHEAD-false} ; then WERROR='' ; fi
- (cd ghci-wrapper && cabal configure --enable-tests $WERROR $ALLOW_NEWER && cabal build && cabal test)
- cabal configure --enable-tests $WERROR $ALLOW_NEWER && cabal build && cabal test
- (cd ghci-wrapper && cabal configure --enable-tests --ghc-options=-Werror && cabal build && cabal test)
- cabal configure --enable-tests --ghc-options=-Werror && cabal build && cabal test
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Changes in NEXT
- GHC 8.4 compatibility.

Changes in 0.13.0
- Add `--preserve-it` for allowing the `it` variable to be preserved between examples

Expand Down
10 changes: 5 additions & 5 deletions doctest.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: 69dd6d1ecadc8f87149ce07099560f936552a152651e21b775a0e513aaaaf79a
-- hash: 963cf1ec79ce30b2c464e5e64a64f5b9f0cba107029eb8fdc5333229775060c9

name: doctest
version: 0.14.0
Expand Down Expand Up @@ -63,7 +63,7 @@ library
, deepseq
, directory
, filepath
, ghc >=7.0 && <8.4
, ghc >=7.0 && <8.6
, ghc-paths >=0.1.0.9
, process
, syb >=0.3
Expand All @@ -85,7 +85,7 @@ executable doctest
, directory
, doctest
, filepath
, ghc >=7.0 && <8.4
, ghc >=7.0 && <8.6
, ghc-paths >=0.1.0.9
, process
, syb >=0.3
Expand All @@ -106,7 +106,7 @@ test-suite doctests
, directory
, doctest
, filepath
, ghc >=7.0 && <8.4
, ghc >=7.0 && <8.6
, ghc-paths >=0.1.0.9
, process
, syb >=0.3
Expand Down Expand Up @@ -164,7 +164,7 @@ test-suite spec
, deepseq
, directory
, filepath
, ghc >=7.0 && <8.4
, ghc >=7.0 && <8.6
, ghc-paths >=0.1.0.9
, hspec >=1.5.1
, mockery
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ghc-options: -Wall
dependencies:
- base == 4.*
- base-compat >= 0.7.0
- ghc >= 7.0 && < 8.4
- ghc >= 7.0 && < 8.6
- syb >= 0.3
- code-page >= 0.1
- deepseq
Expand Down
16 changes: 13 additions & 3 deletions src/Extract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ data Module a = Module {
instance NFData a => NFData (Module a) where
rnf (Module name setup content) = name `deepseq` setup `deepseq` content `deepseq` ()

#if __GLASGOW_HASKELL__ < 803
type GhcPs = RdrName

needsTemplateHaskellOrQQ :: ModuleGraph -> Bool
needsTemplateHaskellOrQQ = needsTemplateHaskell

mapMG :: (ModSummary -> ModSummary) -> ModuleGraph -> ModuleGraph
mapMG = map
#endif

-- | Parse a list of modules.
parse :: [String] -> IO [TypecheckedModule]
parse args = withGhc args $ \modules_ -> withTempOutputDir $ do
Expand All @@ -86,7 +96,7 @@ parse args = withGhc args $ \modules_ -> withTempOutputDir $ do
mapM (`guessTarget` Nothing) modules >>= setTargets
mods <- depanal [] False

mods' <- if needsTemplateHaskell mods then enableCompilation mods else return mods
mods' <- if needsTemplateHaskellOrQQ mods then enableCompilation mods else return mods

let sortedMods = flattenSCCs (topSortModuleGraph False mods' Nothing)
reverse <$> mapM (parseModule >=> typecheckModule >=> loadModule) sortedMods
Expand All @@ -103,7 +113,7 @@ parse args = withGhc args $ \modules_ -> withTempOutputDir $ do
modifySessionDynFlags enableComp
-- We need to update the DynFlags of the ModSummaries as well.
let upd m = m { ms_hspp_opts = enableComp (ms_hspp_opts m) }
let modGraph' = map upd modGraph
let modGraph' = mapMG upd modGraph
return modGraph'

-- copied from Haddock/GhcUtils.hs
Expand Down Expand Up @@ -236,7 +246,7 @@ extractDocStrings = everythingBut (++) (([], False) `mkQ` fromLHsDecl
#endif
)
where
fromLHsDecl :: Selector (LHsDecl RdrName)
fromLHsDecl :: Selector (LHsDecl GhcPs)
fromLHsDecl (L loc decl) = case decl of

-- Top-level documentation has to be treated separately, because it has
Expand Down
18 changes: 16 additions & 2 deletions src/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ module Runner (
import Prelude hiding (putStr, putStrLn, error)

#if __GLASGOW_HASKELL__ < 710
import Data.Monoid
import Data.Monoid hiding ((<>))
import Control.Applicative
#endif
#if MIN_VERSION_base(4,9,0) && !MIN_VERSION_base(4,11,0)
import Data.Semigroup
#endif

import Control.Monad hiding (forM_)
import Text.Printf (printf)
Expand Down Expand Up @@ -46,10 +49,21 @@ instance Show Summary where
show (Summary examples tried errors failures) =
printf "Examples: %d Tried: %d Errors: %d Failures: %d" examples tried errors failures

appendSummary :: Summary -> Summary -> Summary
appendSummary (Summary x1 x2 x3 x4) (Summary y1 y2 y3 y4) = Summary (x1 + y1) (x2 + y2) (x3 + y3) (x4 + y4)

-- | Sum up summaries.
instance Monoid Summary where
mempty = Summary 0 0 0 0
(Summary x1 x2 x3 x4) `mappend` (Summary y1 y2 y3 y4) = Summary (x1 + y1) (x2 + y2) (x3 + y3) (x4 + y4)
#if MIN_VERSION_base(4,9,0)
mappend = (<>)

-- | Sum up summaries.
instance Semigroup Summary where
(<>) = appendSummary
#else
mappend = appendSummary
#endif

-- | Run all examples from a list of modules.
runModules :: Bool -> Bool -> Interpreter -> [Module [Located DocTest]] -> IO Summary
Expand Down