Skip to content

Commit

Permalink
Consistent approach to position of deriving
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Dec 28, 2022
1 parent ceea033 commit 503ef24
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 46 deletions.
3 changes: 2 additions & 1 deletion src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ data W = W
-- ^ Warnings
, wParents :: !ParentMap
-- ^ Which packages a given package depends on, along with the package's version
} deriving Generic
}
deriving Generic

instance Semigroup W where
(<>) = mappenddefault
Expand Down
5 changes: 4 additions & 1 deletion src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2143,10 +2143,13 @@ singleBench beopts benchesToRun ac ee task installedMap = do
cabal CloseOnException KeepTHLoading ("bench" : args)

data ExcludeTHLoading = ExcludeTHLoading | KeepTHLoading

data ConvertPathsToAbsolute = ConvertPathsToAbsolute | KeepPathsAsIs

-- | special marker for expected failures in curator builds, using those
-- we need to keep log handle open as build continues further even after a failure
data KeepOutputOpen = KeepOpen | CloseOnException deriving Eq
data KeepOutputOpen = KeepOpen | CloseOnException
deriving Eq

-- | Strip Template Haskell "Loading package" lines and making paths absolute.
mungeBuildOutput :: forall m. MonadIO m
Expand Down
3 changes: 2 additions & 1 deletion src/Stack/BuildPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ type DepErrors = Map PackageName DepError
data DepError = DepError
{ deVersion :: !(Maybe Version)
, deNeededBy :: !(Map PackageName VersionRange)
} deriving Show
}
deriving Show

-- | Combine two 'DepError's for the same 'Version'.
combineDepError :: DepError -> DepError -> DepError
Expand Down
3 changes: 2 additions & 1 deletion src/Stack/Dot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ data DotPayload = DotPayload
-- ^ The license the package was released under.
, payloadLocation :: Maybe PackageLocation
-- ^ The location of the package.
} deriving (Eq, Show)
}
deriving (Eq, Show)

-- | Create the dependency graph and also prune it as specified in the dot
-- options. Returns a set of local names and a map from package names to
Expand Down
6 changes: 4 additions & 2 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ data GhciOpts = GhciOpts
, ghciHidePackages :: !(Maybe Bool)
, ghciNoBuild :: !Bool
, ghciOnlyMain :: !Bool
} deriving Show
}
deriving Show

-- | Necessary information to load a package or its components.
--
Expand All @@ -133,7 +134,8 @@ data GhciPkgInfo = GhciPkgInfo
, ghciPkgMainIs :: !(Map NamedComponent [Path Abs File])
, ghciPkgTargetFiles :: !(Maybe [Path Abs File])
, ghciPkgPackage :: !Package
} deriving Show
}
deriving Show

-- | Loaded package description and related info.
data GhciPkgDesc = GhciPkgDesc
Expand Down
6 changes: 4 additions & 2 deletions src/Stack/Lock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ instance Exception LockException where
data LockedLocation a b = LockedLocation
{ llOriginal :: a
, llCompleted :: b
} deriving (Eq, Show)
}
deriving (Eq, Show)

instance (ToJSON a, ToJSON b) => ToJSON (LockedLocation a b) where
toJSON ll =
Expand Down Expand Up @@ -73,7 +74,8 @@ instance FromJSON (WithJSONWarnings (Unresolved SingleRPLI)) where
data Locked = Locked
{ lckSnapshotLocations :: [LockedLocation RawSnapshotLocation SnapshotLocation]
, lckPkgImmutableLocations :: [LockedLocation RawPackageLocationImmutable PackageLocationImmutable]
} deriving (Eq, Show)
}
deriving (Eq, Show)

instance ToJSON Locked where
toJSON Locked {..} =
Expand Down
12 changes: 8 additions & 4 deletions src/Stack/Ls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ data SnapshotOpts = SnapshotOpts
{ soptViewType :: LsView
, soptLtsSnapView :: Bool
, soptNightlySnapView :: Bool
} deriving (Eq, Show, Ord)
}
deriving (Eq, Show, Ord)

data ListStylesOpts = ListStylesOpts
{ coptBasic :: Bool
, coptSGR :: Bool
, coptExample :: Bool
} deriving (Eq, Ord, Show)
}
deriving (Eq, Ord, Show)

newtype ListToolsOpts = ListToolsOpts
{ toptFilter :: String
Expand Down Expand Up @@ -178,12 +180,14 @@ data Snapshot = Snapshot
{ snapId :: Text
, snapTitle :: Text
, snapTime :: Text
} deriving (Show, Eq, Ord)
}
deriving (Show, Eq, Ord)

data SnapshotData = SnapshotData
{ _snapTotalCounts :: Integer
, snaps :: [[Snapshot]]
} deriving (Show, Eq, Ord)
}
deriving (Show, Eq, Ord)

instance FromJSON Snapshot where
parseJSON o@(Array _) = parseSnapshot o
Expand Down
17 changes: 12 additions & 5 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,8 @@ data GlobalOptsMonoid = GlobalOptsMonoid
, globalMonoidTermWidth :: !(First Int) -- ^ Terminal width override
, globalMonoidStackYaml :: !(First FilePath) -- ^ Override project stack.yaml
, globalMonoidLockFileBehavior :: !(First LockFileBehavior) -- ^ See 'globalLockFileBehavior'
} deriving Generic
}
deriving Generic

instance Semigroup GlobalOptsMonoid where
(<>) = mappenddefault
Expand Down Expand Up @@ -1825,7 +1826,8 @@ data DownloadInfo = DownloadInfo
, downloadInfoContentLength :: Maybe Int
, downloadInfoSha1 :: Maybe ByteString
, downloadInfoSha256 :: Maybe ByteString
} deriving Show
}
deriving Show

instance FromJSON (WithJSONWarnings DownloadInfo) where
parseJSON = withObjectWarnings "DownloadInfo" parseDownloadInfoFromObject
Expand Down Expand Up @@ -1964,15 +1966,17 @@ instance FromJSON PvpBounds where
newtype DockerEntrypoint = DockerEntrypoint
{ deUser :: Maybe DockerUser
-- ^ UID/GID/etc of host user, if we wish to perform UID/GID switch in container
} deriving (Read, Show)
}
deriving (Read, Show)

-- | Docker host user info
data DockerUser = DockerUser
{ duUid :: UserID -- ^ uid
, duGid :: GroupID -- ^ gid
, duGroups :: [GroupID] -- ^ Supplemental groups
, duUmask :: FileMode -- ^ File creation mask }
} deriving (Read, Show)
}
deriving (Read, Show)

data GhcOptionKey
= GOKOldEverything
Expand Down Expand Up @@ -2221,9 +2225,12 @@ data ExtraDirs = ExtraDirs
{ edBins :: ![Path Abs Dir]
, edInclude :: ![Path Abs Dir]
, edLib :: ![Path Abs Dir]
} deriving (Show, Generic)
}
deriving (Show, Generic)

instance Semigroup ExtraDirs where
(<>) = mappenddefault

instance Monoid ExtraDirs where
mempty = memptydefault
mappend = (<>)
Expand Down
42 changes: 25 additions & 17 deletions src/Stack/Types/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ data BuildOptsCLI = BuildOptsCLI
, boptsCLIOnlyConfigure :: !Bool
, boptsCLICommand :: !BuildCommand
, boptsCLIInitialBuildSteps :: !Bool
} deriving Show
}
deriving Show

-- | Command sum type for conditional arguments.
data BuildCommand
Expand Down Expand Up @@ -219,7 +220,8 @@ data BuildOptsMonoid = BuildOptsMonoid
, buildMonoidSkipComponents :: ![Text]
, buildMonoidInterleavedOutput :: !FirstTrue
, buildMonoidDdumpDir :: !(First Text)
} deriving (Show, Generic)
}
deriving (Show, Generic)

instance FromJSON (WithJSONWarnings BuildOptsMonoid) where
parseJSON = withObjectWarnings "BuildOptsMonoid"
Expand Down Expand Up @@ -358,13 +360,14 @@ data BuildSubset

-- | Options for the 'FinalAction' 'DoTests'
data TestOpts =
TestOpts {toRerunTests :: !Bool -- ^ Whether successful tests will be run gain
,toAdditionalArgs :: ![String] -- ^ Arguments passed to the test program
,toCoverage :: !Bool -- ^ Generate a code coverage report
,toDisableRun :: !Bool -- ^ Disable running of tests
,toMaximumTimeSeconds :: !(Maybe Int) -- ^ test suite timeout in seconds
,toAllowStdin :: !Bool -- ^ Whether to allow standard input
} deriving (Eq, Show)
TestOpts { toRerunTests :: !Bool -- ^ Whether successful tests will be run gain
, toAdditionalArgs :: ![String] -- ^ Arguments passed to the test program
, toCoverage :: !Bool -- ^ Generate a code coverage report
, toDisableRun :: !Bool -- ^ Disable running of tests
, toMaximumTimeSeconds :: !(Maybe Int) -- ^ test suite timeout in seconds
, toAllowStdin :: !Bool -- ^ Whether to allow standard input
}
deriving (Eq, Show)

defaultTestOpts :: TestOpts
defaultTestOpts = TestOpts
Expand All @@ -384,7 +387,8 @@ data TestOptsMonoid =
, toMonoidDisableRun :: !FirstFalse
, toMonoidMaximumTimeSeconds :: !(First (Maybe Int))
, toMonoidAllowStdin :: !FirstTrue
} deriving (Show, Generic)
}
deriving (Show, Generic)

instance FromJSON (WithJSONWarnings TestOptsMonoid) where
parseJSON = withObjectWarnings "TestOptsMonoid"
Expand Down Expand Up @@ -426,11 +430,13 @@ instance Monoid TestOptsMonoid where
-- | Haddock Options
newtype HaddockOpts =
HaddockOpts { hoAdditionalArgs :: [String] -- ^ Arguments passed to haddock program
} deriving (Eq, Show)
}
deriving (Eq, Show)

newtype HaddockOptsMonoid =
HaddockOptsMonoid {hoMonoidAdditionalArgs :: [String]
} deriving (Show, Generic)
HaddockOptsMonoid { hoMonoidAdditionalArgs :: [String]
}
deriving (Show, Generic)

defaultHaddockOpts :: HaddockOpts
defaultHaddockOpts = HaddockOpts {hoAdditionalArgs = []}
Expand All @@ -456,7 +462,8 @@ data BenchmarkOpts =
BenchmarkOpts
{ beoAdditionalArgs :: !(Maybe String) -- ^ Arguments passed to the benchmark program
, beoDisableRun :: !Bool -- ^ Disable running of benchmarks
} deriving (Eq, Show)
}
deriving (Eq, Show)

defaultBenchmarkOpts :: BenchmarkOpts
defaultBenchmarkOpts = BenchmarkOpts
Expand All @@ -466,9 +473,10 @@ defaultBenchmarkOpts = BenchmarkOpts

data BenchmarkOptsMonoid =
BenchmarkOptsMonoid
{ beoMonoidAdditionalArgs :: !(First String)
, beoMonoidDisableRun :: !(First Bool)
} deriving (Show, Generic)
{ beoMonoidAdditionalArgs :: !(First String)
, beoMonoidDisableRun :: !(First Bool)
}
deriving (Show, Generic)

instance FromJSON (WithJSONWarnings BenchmarkOptsMonoid) where
parseJSON = withObjectWarnings "BenchmarkOptsMonoid"
Expand Down
17 changes: 9 additions & 8 deletions src/Stack/Types/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,18 @@ data BuildInfoOpts = BuildInfoOpts
-- there are no multi-word options (see
-- https://github.com/commercialhaskell/stack/issues/1255)
, bioCabalMacros :: Path Abs File
} deriving Show
}
deriving Show

-- | Package build configuration
data PackageConfig =
PackageConfig {packageConfigEnableTests :: !Bool -- ^ Are tests enabled?
,packageConfigEnableBenchmarks :: !Bool -- ^ Are benchmarks enabled?
,packageConfigFlags :: !(Map FlagName Bool) -- ^ Configured flags.
,packageConfigGhcOptions :: ![Text] -- ^ Configured ghc options.
,packageConfigCabalConfigOpts :: ![Text] -- ^ ./Setup.hs configure options
,packageConfigCompilerVersion :: ActualCompiler -- ^ GHC version
,packageConfigPlatform :: !Platform -- ^ host platform
PackageConfig { packageConfigEnableTests :: !Bool -- ^ Are tests enabled?
, packageConfigEnableBenchmarks :: !Bool -- ^ Are benchmarks enabled?
, packageConfigFlags :: !(Map FlagName Bool) -- ^ Configured flags.
, packageConfigGhcOptions :: ![Text] -- ^ Configured ghc options.
, packageConfigCabalConfigOpts :: ![Text] -- ^ ./Setup.hs configure options
, packageConfigCompilerVersion :: ActualCompiler -- ^ GHC version
, packageConfigPlatform :: !Platform -- ^ host platform
}
deriving (Show, Typeable)

Expand Down
3 changes: 2 additions & 1 deletion test/integration/IntegrationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ main = runSimpleApp $ do
data Options = Options
{ optSpeed :: Maybe Speed
, optMatch :: Maybe String
} deriving Generic
}
deriving Generic

instance ParseRecord Options where
parseRecord = parseRecordWithModifiers modifiers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ infixr 0 ==>
a ==> b = not a || b


newtype QFilePathValidW = QFilePathValidW FilePath deriving Show
newtype QFilePathValidW = QFilePathValidW FilePath
deriving Show

instance Arbitrary QFilePathValidW where
arbitrary = fmap (QFilePathValidW . W.makeValid) arbitraryFilePath
shrink (QFilePathValidW x) = shrinkValid QFilePathValidW W.makeValid x

newtype QFilePathValidP = QFilePathValidP FilePath deriving Show
newtype QFilePathValidP = QFilePathValidP FilePath
deriving Show

instance Arbitrary QFilePathValidP where
arbitrary = fmap (QFilePathValidP . P.makeValid) arbitraryFilePath
shrink (QFilePathValidP x) = shrinkValid QFilePathValidP P.makeValid x

newtype QFilePath = QFilePath FilePath deriving Show
newtype QFilePath = QFilePath FilePath
deriving Show

instance Arbitrary QFilePath where
arbitrary = fmap QFilePath arbitraryFilePath
Expand Down

0 comments on commit 503ef24

Please sign in to comment.