Skip to content

Commit

Permalink
Support building with GHC 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
borsboom committed Apr 15, 2018
1 parent 53df9e0 commit dccd1f8
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 36 deletions.
8 changes: 6 additions & 2 deletions src/Data/Aeson/Extended.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ data WarningParserMonoid = WarningParserMonoid
{ wpmExpectedFields :: !(Set Text)
, wpmWarnings :: [JSONWarning]
} deriving Generic
instance Semigroup WarningParserMonoid where
(<>) = mappenddefault
instance Monoid WarningParserMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)
instance IsString WarningParserMonoid where
fromString s = mempty { wpmWarnings = [fromString s] }

Expand All @@ -153,9 +155,11 @@ data WithJSONWarnings a = WithJSONWarnings a [JSONWarning]
deriving (Eq, Generic, Show)
instance Functor WithJSONWarnings where
fmap f (WithJSONWarnings x w) = WithJSONWarnings (f x) w
instance Monoid a => Semigroup (WithJSONWarnings a) where
(<>) = mappenddefault
instance Monoid a => Monoid (WithJSONWarnings a) where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

-- | Warning output from 'WarningParser'.
data JSONWarning = JSONUnrecognizedFields String [Text]
Expand Down
11 changes: 8 additions & 3 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ data W = W
, wParents :: !ParentMap
-- ^ Which packages a given package depends on, along with the package's version
} deriving Generic
instance Semigroup W where
(<>) = mappenddefault
instance Monoid W where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

type M = RWST -- TODO replace with more efficient WS stack on top of StackT
Ctx
Expand Down Expand Up @@ -1148,8 +1150,11 @@ extendDepsPath ident dp = DepsPath
newtype MonoidMap k a = MonoidMap (Map k a)
deriving (Eq, Ord, Read, Show, Generic, Functor)

instance (Ord k, Monoid a) => Monoid (MonoidMap k a) where
mappend (MonoidMap mp1) (MonoidMap mp2) = MonoidMap (M.unionWith mappend mp1 mp2)
instance (Ord k, Semigroup a) => Semigroup (MonoidMap k a) where
MonoidMap mp1 <> MonoidMap mp2 = MonoidMap (M.unionWith (<>) mp1 mp2)

instance (Ord k, Monoid a, Semigroup a) => Monoid (MonoidMap k a) where
mappend = (<>)
mempty = MonoidMap mempty

-- Switch this to 'True' to enable some debugging putStrLn in this module
Expand Down
3 changes: 2 additions & 1 deletion src/Stack/Ls.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand All @@ -14,10 +15,10 @@ import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Reader (MonadReader)
import Control.Monad (when)
import Data.Aeson
import Stack.Prelude
import Stack.Types.Runner
import qualified Data.Aeson.Types as A
import qualified Data.List as L
import Data.Monoid
import Data.Text hiding (pack, intercalate)
import qualified Data.Text as T
import qualified Data.Text.IO as T
Expand Down
7 changes: 6 additions & 1 deletion src/Stack/PackageIndex.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
Expand Down Expand Up @@ -400,7 +401,11 @@ getPackageCaches = do
result <- liftM mconcat $ forM (clIndices cl) $ \index -> do
fp <- configPackageIndexCache (indexName index)
PackageCache pis <-
#if MIN_VERSION_template_haskell(2,13,0)
$(versionedDecodeOrLoad (storeVersionConfig "pkg-v5" "LLL6OCcimOqRm3r0JmsSlLHcaLE="
#else
$(versionedDecodeOrLoad (storeVersionConfig "pkg-v5" "A607WaDwhg5VVvZTxNgU9g52DO8="
#endif
:: VersionConfig (PackageCache ())))
fp
(populateCache index)
Expand Down
4 changes: 3 additions & 1 deletion src/Stack/Setup/Installed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ data ExtraDirs = ExtraDirs
, edInclude :: ![Path Abs Dir]
, edLib :: ![Path Abs Dir]
} deriving (Show, Generic)
instance Semigroup ExtraDirs where
(<>) = mappenddefault
instance Monoid ExtraDirs where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

installDir :: (MonadReader env m, MonadThrow m)
=> Path Abs Dir
Expand Down
16 changes: 11 additions & 5 deletions src/Stack/Types/BuildPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,15 @@ data DepInfo = DepInfo
instance Store DepInfo
instance NFData DepInfo

instance Monoid DepInfo where
mempty = DepInfo mempty (fromVersionRange C.anyVersion)
DepInfo a x `mappend` DepInfo b y = DepInfo
instance Semigroup DepInfo where
DepInfo a x <> DepInfo b y = DepInfo
(mappend a b)
(intersectVersionIntervals x y)

instance Monoid DepInfo where
mempty = DepInfo mempty (fromVersionRange C.anyVersion)
mappend = (<>)

data Component = CompLibrary
| CompExecutable
| CompTestSuite
Expand All @@ -390,10 +393,13 @@ newtype ModuleInfo = ModuleInfo
instance Store ModuleInfo
instance NFData ModuleInfo

instance Semigroup ModuleInfo where
ModuleInfo x <> ModuleInfo y =
ModuleInfo (Map.unionWith Set.union x y)

instance Monoid ModuleInfo where
mempty = ModuleInfo mempty
mappend (ModuleInfo x) (ModuleInfo y) =
ModuleInfo (Map.unionWith Set.union x y)
mappend = (<>)

moduleInfoVC :: VersionConfig ModuleInfo
moduleInfoVC = storeVersionConfig "mi-v2" "8ImAfrwMVmqoSoEpt85pLvFeV3s="
Expand Down
29 changes: 19 additions & 10 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,12 @@ data GlobalOptsMonoid = GlobalOptsMonoid
, globalMonoidStackYaml :: !(First FilePath) -- ^ Override project stack.yaml
} deriving (Show, Generic)

instance Semigroup GlobalOptsMonoid where
(<>) = mappenddefault

instance Monoid GlobalOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

-- | Default logging level should be something useful but not crazy.
defaultLogLevel :: LogLevel
Expand Down Expand Up @@ -771,9 +774,12 @@ data ConfigMonoid =
}
deriving (Show, Generic)

instance Semigroup ConfigMonoid where
(<>) = mappenddefault

instance Monoid ConfigMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

parseConfigMonoid :: Path Abs Dir -> Value -> Yaml.Parser (WithJSONWarnings ConfigMonoid)
parseConfigMonoid = withObjectWarnings "ConfigMonoid" . parseConfigMonoidObject
Expand Down Expand Up @@ -1676,6 +1682,16 @@ instance FromJSON (WithJSONWarnings SetupInfo) where

-- | For @siGHCs@ and @siGHCJSs@ fields maps are deeply merged.
-- For all fields the values from the last @SetupInfo@ win.
instance Semigroup SetupInfo where
l <> r =
SetupInfo
{ siSevenzExe = siSevenzExe r <|> siSevenzExe l
, siSevenzDll = siSevenzDll r <|> siSevenzDll l
, siMsys2 = siMsys2 r <> siMsys2 l
, siGHCs = Map.unionWith (<>) (siGHCs r) (siGHCs l)
, siGHCJSs = Map.unionWith (<>) (siGHCJSs r) (siGHCJSs l)
, siStack = Map.unionWith (<>) (siStack l) (siStack r) }

instance Monoid SetupInfo where
mempty =
SetupInfo
Expand All @@ -1686,14 +1702,7 @@ instance Monoid SetupInfo where
, siGHCJSs = Map.empty
, siStack = Map.empty
}
mappend l r =
SetupInfo
{ siSevenzExe = siSevenzExe r <|> siSevenzExe l
, siSevenzDll = siSevenzDll r <|> siSevenzDll l
, siMsys2 = siMsys2 r <> siMsys2 l
, siGHCs = Map.unionWith (<>) (siGHCs r) (siGHCs l)
, siGHCJSs = Map.unionWith (<>) (siGHCJSs r) (siGHCJSs l)
, siStack = Map.unionWith (<>) (siStack l) (siStack r) }
mappend = (<>)

-- | Remote or inline 'SetupInfo'
data SetupInfoLocation
Expand Down
20 changes: 16 additions & 4 deletions src/Stack/Types/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@ buildMonoidSplitObjsName = "split-objs"
buildMonoidSkipComponentsName :: Text
buildMonoidSkipComponentsName = "skip-components"

instance Semigroup BuildOptsMonoid where
(<>) = mappenddefault

instance Monoid BuildOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

-- | Which subset of packages to build
data BuildSubset
Expand Down Expand Up @@ -347,9 +350,12 @@ toMonoidCoverageArgName = "coverage"
toMonoidDisableRunArgName :: Text
toMonoidDisableRunArgName = "no-run-tests"

instance Semigroup TestOptsMonoid where
(<>) = mappenddefault

instance Monoid TestOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)



Expand All @@ -370,9 +376,12 @@ instance FromJSON (WithJSONWarnings HaddockOptsMonoid) where
(\o -> do hoMonoidAdditionalArgs <- o ..:? hoMonoidAdditionalArgsName ..!= []
return HaddockOptsMonoid{..})

instance Semigroup HaddockOptsMonoid where
(<>) = mappenddefault

instance Monoid HaddockOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

hoMonoidAdditionalArgsName :: Text
hoMonoidAdditionalArgsName = "haddock-args"
Expand Down Expand Up @@ -409,9 +418,12 @@ beoMonoidAdditionalArgsArgName = "benchmark-arguments"
beoMonoidDisableRunArgName :: Text
beoMonoidDisableRunArgName = "no-run-benchmarks"

instance Semigroup BenchmarkOptsMonoid where
(<>) = mappenddefault

instance Monoid BenchmarkOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

data FileWatchOpts
= NoFileWatch
Expand Down
6 changes: 5 additions & 1 deletion src/Stack/Types/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ instance FromJSON (WithJSONWarnings DockerOptsMonoid) where
..!= VersionRangeJSON anyVersion)
return DockerOptsMonoid{..})

-- | Left-biased combine Docker options
instance Semigroup DockerOptsMonoid where
(<>) = mappenddefault

-- | Left-biased combine Docker options
instance Monoid DockerOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

-- | Where to get the `stack` executable to run in Docker containers
data DockerStackExe
Expand Down
5 changes: 4 additions & 1 deletion src/Stack/Types/Image.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ instance FromJSON (WithJSONWarnings ImageOptsMonoid) where
{ ..
})

instance Semigroup ImageOptsMonoid where
(<>) = mappenddefault

instance Monoid ImageOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

instance FromJSON (WithJSONWarnings ImageDockerOpts) where
parseJSON = withObjectWarnings
Expand Down
6 changes: 5 additions & 1 deletion src/Stack/Types/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ instance FromJSON (WithJSONWarnings NixOptsMonoid) where
nixMonoidAddGCRoots <- First <$> o ..:? nixAddGCRootsArgName
return NixOptsMonoid{..})

-- | Left-biased combine Nix options
instance Semigroup NixOptsMonoid where
(<>) = mappenddefault

-- | Left-biased combine Nix options
instance Monoid NixOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)

-- | Nix enable argument name.
nixEnableArgName :: Text
Expand Down
5 changes: 4 additions & 1 deletion src/Stack/Types/PackageIndex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ newtype PackageCache index = PackageCache
(index, Maybe PackageDownload, NonEmpty ([CabalHash], OffsetSize))))
deriving (Generic, Eq, Show, Data, Typeable, Store, NFData)

instance Semigroup (PackageCache index) where
PackageCache x <> PackageCache y = PackageCache (HashMap.unionWith HashMap.union x y)

instance Monoid (PackageCache index) where
mempty = PackageCache HashMap.empty
mappend (PackageCache x) (PackageCache y) = PackageCache (HashMap.unionWith HashMap.union x y)
mappend = (<>)

-- | offset in bytes into the 01-index.tar file for the .cabal file
-- contents, and size in bytes of the .cabal file
Expand Down
5 changes: 4 additions & 1 deletion src/Stack/Types/Urls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ instance FromJSON (WithJSONWarnings UrlsMonoid) where
<*> o ..: "lts-build-plans"
<*> o ..: "nightly-build-plans"

instance Semigroup UrlsMonoid where
(<>) = mappenddefault

instance Monoid UrlsMonoid where
mempty = memptydefault
mappend = mappenddefault
mappend = (<>)
7 changes: 5 additions & 2 deletions src/Stack/Types/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ newtype IntersectingVersionRange =
IntersectingVersionRange { getIntersectingVersionRange :: Cabal.VersionRange }
deriving Show

instance Semigroup IntersectingVersionRange where
IntersectingVersionRange l <> IntersectingVersionRange r =
IntersectingVersionRange (l `Cabal.intersectVersionRanges` r)

instance Monoid IntersectingVersionRange where
mempty = IntersectingVersionRange Cabal.anyVersion
mappend (IntersectingVersionRange l) (IntersectingVersionRange r) =
IntersectingVersionRange (l `Cabal.intersectVersionRanges` r)
mappend = (<>)

-- | Attoparsec parser for a package version.
versionParser :: Parser Version
Expand Down
4 changes: 2 additions & 2 deletions src/Text/PrettyPrint/Leijen/Extended.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ import Text.PrettyPrint.Annotated.Leijen hiding ((<>), display)
instance Semigroup (Doc a) where
(<>) = (P.<>)
instance Monoid (Doc a) where
mappend = (P.<>)
mappend = (<>)
mempty = empty

--------------------------------------------------------------------------------
Expand All @@ -164,7 +164,7 @@ instance Display (Doc a) where
type AnsiDoc = Doc AnsiAnn

newtype AnsiAnn = AnsiAnn [SGR]
deriving (Eq, Show, Monoid)
deriving (Eq, Show, Semigroup, Monoid)

class HasAnsiAnn a where
getAnsiAnn :: a -> AnsiAnn
Expand Down

2 comments on commit dccd1f8

@ilovezfs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@borsboom Will there be a separate stack.yaml for building it with 8.4?

@borsboom
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, once all the dependencies compile with GHC 8.4 on all supported platforms I'll add back a stack-nightly.yaml. Currently fsnotify depends on an incompatible version of hinotify on Linux (haskell-fswatch/hfsnotify#77), but I think that's the last one.

Please sign in to comment.