Skip to content

Add NFData instances #11097

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cabal-syntax/src/Distribution/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ data AbiTag
deriving (Eq, Generic, Show, Read)

instance Binary AbiTag
instance NFData AbiTag
instance Structured AbiTag

instance Pretty AbiTag where
Expand Down
5 changes: 5 additions & 0 deletions Cabal/src/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ data Compiler = Compiler
deriving (Eq, Generic, Show, Read)

instance Binary Compiler
instance NFData Compiler
instance Structured Compiler

showCompilerId :: Compiler -> String
Expand Down Expand Up @@ -205,6 +206,7 @@ data PackageDBX fp
deriving (Eq, Generic, Ord, Show, Read, Functor, Foldable, Traversable)

instance Binary fp => Binary (PackageDBX fp)
instance NFData fp => NFData (PackageDBX fp)
instance Structured fp => Structured (PackageDBX fp)

-- | Parse a PackageDB stack entry
Expand Down Expand Up @@ -305,6 +307,7 @@ data OptimisationLevel
deriving (Bounded, Enum, Eq, Generic, Read, Show)

instance Binary OptimisationLevel
instance NFData OptimisationLevel
instance Structured OptimisationLevel

instance Parsec OptimisationLevel where
Expand Down Expand Up @@ -354,6 +357,7 @@ data DebugInfoLevel
deriving (Bounded, Enum, Eq, Generic, Read, Show)

instance Binary DebugInfoLevel
instance NFData DebugInfoLevel
instance Structured DebugInfoLevel

instance Parsec DebugInfoLevel where
Expand Down Expand Up @@ -607,6 +611,7 @@ data ProfDetailLevel
deriving (Eq, Generic, Read, Show)

instance Binary ProfDetailLevel
instance NFData ProfDetailLevel
instance Structured ProfDetailLevel

instance Parsec ProfDetailLevel where
Expand Down
2 changes: 2 additions & 0 deletions Cabal/src/Distribution/Simple/InstallDirs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ data InstallDirs dir = InstallDirs
deriving (Eq, Read, Show, Functor, Generic)

instance Binary dir => Binary (InstallDirs dir)
instance NFData dir => NFData (InstallDirs dir)
instance Structured dir => Structured (InstallDirs dir)

instance (Semigroup dir, Monoid dir) => Monoid (InstallDirs dir) where
Expand Down Expand Up @@ -397,6 +398,7 @@ newtype PathTemplate = PathTemplate [PathComponent]
deriving (Eq, Ord, Generic)

instance Binary PathTemplate
instance NFData PathTemplate
instance Structured PathTemplate

type PathTemplateEnv = [(PathTemplateVariable, PathTemplate)]
Expand Down
2 changes: 2 additions & 0 deletions Cabal/src/Distribution/Simple/InstallDirs/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data PathComponent
deriving (Eq, Ord, Generic)

instance Binary PathComponent
instance NFData PathComponent
instance Structured PathComponent

data PathTemplateVariable
Expand Down Expand Up @@ -67,6 +68,7 @@ data PathTemplateVariable
deriving (Eq, Ord, Generic)

instance Binary PathTemplateVariable
instance NFData PathTemplateVariable
instance Structured PathTemplateVariable

instance Show PathTemplateVariable where
Expand Down
1 change: 1 addition & 0 deletions Cabal/src/Distribution/Simple/Setup/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import qualified Text.PrettyPrint as Disp
data HaddockTarget = ForHackage | ForDevelopment deriving (Eq, Show, Generic)

instance Binary HaddockTarget
instance NFData HaddockTarget
instance Structured HaddockTarget

instance Pretty HaddockTarget where
Expand Down
1 change: 1 addition & 0 deletions Cabal/src/Distribution/Simple/Setup/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ data TestShowDetails = Never | Failures | Always | Streaming | Direct
deriving (Eq, Ord, Enum, Bounded, Generic, Show)

instance Binary TestShowDetails
instance NFData TestShowDetails
instance Structured TestShowDetails

knownTestShowDetails :: [TestShowDetails]
Expand Down
1 change: 1 addition & 0 deletions Cabal/src/Distribution/Types/DumpBuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data DumpBuildInfo
deriving (Read, Show, Eq, Ord, Enum, Bounded, Generic)

instance Binary DumpBuildInfo
instance NFData DumpBuildInfo
instance Structured DumpBuildInfo

instance Parsec DumpBuildInfo where
Expand Down
7 changes: 7 additions & 0 deletions Cabal/src/Distribution/Types/ParStrat.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Distribution.Types.ParStrat where

import Distribution.Compat.Prelude

-- | How to control parallelism, e.g. a fixed number of jobs or by using a system semaphore.
data ParStratX sem
= -- | Compile in parallel with the given number of jobs (`-jN` or `-j`).
Expand All @@ -10,6 +12,11 @@ data ParStratX sem
Serial
deriving (Show)

instance NFData sem => NFData (ParStratX sem) where
rnf (NumJobs m) = rnf m
rnf (UseSem s) = rnf s
rnf Serial = ()

-- | Used by Cabal to indicate that we want to use this specific semaphore (created by cabal-install)
type ParStrat = ParStratX String

Expand Down
3 changes: 3 additions & 0 deletions Cabal/src/Distribution/Utils/NubList.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ instance (Ord a, Binary a) => Binary (NubList a) where

instance Structured a => Structured (NubList a)

instance (Ord a, NFData a) => NFData (NubList a) where
rnf (NubList xs) = rnf xs

-- | NubListR : A right-biased version of 'NubList'. That is @toNubListR
-- ["-XNoFoo", "-XFoo", "-XNoFoo"]@ will result in @["-XFoo", "-XNoFoo"]@,
-- unlike the normal 'NubList', which is left-biased. Built on top of
Expand Down
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Verbosity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ instance Bounded Verbosity where
maxBound = mkVerbosity maxBound

instance Binary Verbosity
instance Structured Verbosity
instance NFData Verbosity
instance Structured Verbosity

-- | In 'silent' mode, we should not print /anything/ unless an error occurs.
silent :: Verbosity
Expand Down
2 changes: 2 additions & 0 deletions Cabal/src/Distribution/Verbosity/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data VerbosityLevel = Silent | Normal | Verbose | Deafening
deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)

instance Binary VerbosityLevel
instance NFData VerbosityLevel
instance Structured VerbosityLevel

data VerbosityFlag
Expand All @@ -26,4 +27,5 @@ data VerbosityFlag
deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)

instance Binary VerbosityFlag
instance NFData VerbosityFlag
instance Structured VerbosityFlag
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ data ConstraintSource =
deriving (Show, Eq, Generic)

instance Binary ConstraintSource
instance NFData ConstraintSource
instance Structured ConstraintSource

-- | Description of a 'ConstraintSource'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enableStanzas optionalStanzas = ComponentRequestedSpec
}

instance Binary OptionalStanza
instance NFData OptionalStanza
instance Structured OptionalStanza

-------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ data PackageProperty
deriving (Eq, Show, Generic)

instance Binary PackageProperty
instance NFData PackageProperty
instance Structured PackageProperty

instance Pretty PackageProperty where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ instance Ord ProjectConfigPath where
bImporters = snd $ unconsProjectConfigPath pb

instance Binary ProjectConfigPath
instance NFData ProjectConfigPath
instance Structured ProjectConfigPath

-- | Renders the path like this;
Expand Down
12 changes: 12 additions & 0 deletions cabal-install-solver/src/Distribution/Solver/Types/Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ instance Structured AllowBootLibInstalls
instance Structured OnlyConstrained
instance Structured SolveExecutables

instance NFData ReorderGoals
instance NFData CountConflicts
instance NFData FineGrainedConflicts
instance NFData IndependentGoals
instance NFData PreferOldest
instance NFData MinimizeConflictSet
instance NFData AvoidReinstalls
instance NFData ShadowPkgs
instance NFData StrongFlags
instance NFData AllowBootLibInstalls
instance NFData OnlyConstrained

instance Pretty OnlyConstrained where
pretty OnlyConstrainedAll = PP.text "all"
pretty OnlyConstrainedNone = PP.text "none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data ReportLevel = NoReports | AnonymousReports | DetailedReports
deriving (Eq, Ord, Enum, Bounded, Show, Generic)

instance Binary ReportLevel
instance NFData ReportLevel
instance Structured ReportLevel

instance Pretty ReportLevel where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ instance Semigroup ClientInstallFlags where
(<>) = gmappend

instance Binary ClientInstallFlags
instance NFData ClientInstallFlags
instance Structured ClientInstallFlags

defaultClientInstallFlags :: ClientInstallFlags
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/Dependency/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ data Solver = Modular
instance Binary PreSolver
instance Binary Solver

instance NFData PreSolver

instance Structured PreSolver
instance Structured Solver

Expand Down
23 changes: 23 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ data ProjectFileParser
| CompareParser
deriving (Eq, Show, Generic)

instance NFData ProjectFileParser

defaultProjectFileParser :: ProjectFileParser
#ifdef LEGACY_COMPARISON
defaultProjectFileParser = CompareParser
Expand Down Expand Up @@ -355,13 +357,28 @@ instance Structured ProjectConfigProvenance
instance Structured PackageConfig
instance Structured ProjectFileParser

instance NFData ProjectConfigToParse where
rnf (ProjectConfigToParse bs) = rnf bs

instance NFData ProjectConfig
instance NFData ProjectConfigBuildOnly
instance NFData ProjectConfigShared

instance NFData ProjectConfigProvenance where
rnf Implicit = ()
rnf (Explicit path) = rnf path

instance NFData PackageConfig

-- | Newtype wrapper for 'Map' that provides a 'Monoid' instance that takes
-- the last value rather than the first value for overlapping keys.
newtype MapLast k v = MapLast {getMapLast :: Map k v}
deriving (Eq, Show, Functor, Generic, Binary)

instance (Structured k, Structured v) => Structured (MapLast k v)

instance (NFData k, NFData v) => NFData (MapLast k v)

instance Ord k => Monoid (MapLast k v) where
mempty = MapLast Map.empty
mappend = (<>)
Expand All @@ -378,6 +395,8 @@ newtype MapMappend k v = MapMappend {getMapMappend :: Map k v}

instance (Structured k, Structured v) => Structured (MapMappend k v)

instance (NFData k, NFData v) => NFData (MapMappend k v)

instance (Semigroup v, Ord k) => Monoid (MapMappend k v) where
mempty = MapMappend Map.empty
mappend = (<>)
Expand Down Expand Up @@ -462,6 +481,7 @@ data SolverSettings = SolverSettings
deriving (Eq, Show, Generic)

instance Binary SolverSettings
instance NFData SolverSettings
instance Structured SolverSettings

-- | Resolved configuration for things that affect how we build and not the
Expand Down Expand Up @@ -501,3 +521,6 @@ data BuildTimeSettings = BuildTimeSettings
, buildSettingProgPathExtra :: [FilePath]
, buildSettingHaddockOpen :: Bool
}
deriving (Generic)

instance NFData BuildTimeSettings
3 changes: 3 additions & 0 deletions cabal-install/src/Distribution/Client/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ data UserQualifier
deriving (Eq, Show, Generic)

instance Binary UserQualifier
instance NFData UserQualifier
instance Structured UserQualifier

-- | Version of 'ConstraintScope' that a user may specify on the
Expand All @@ -623,6 +624,7 @@ data UserConstraintScope
deriving (Eq, Show, Generic)

instance Binary UserConstraintScope
instance NFData UserConstraintScope
instance Structured UserConstraintScope

fromUserQualifier :: UserQualifier -> Qualifier
Expand All @@ -643,6 +645,7 @@ data UserConstraint
deriving (Eq, Show, Generic)

instance Binary UserConstraint
instance NFData UserConstraint
instance Structured UserConstraint

userConstraintPackageName :: UserConstraint -> PackageName
Expand Down
8 changes: 8 additions & 0 deletions cabal-install/src/Distribution/Client/Types/AllowNewer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ instance Structured RelaxedDep
instance Structured AllowNewer
instance Structured AllowOlder

instance NFData RelaxDeps
instance NFData RelaxDepMod
instance NFData RelaxDepScope
instance NFData RelaxDepSubject
instance NFData RelaxedDep
instance NFData AllowNewer
instance NFData AllowOlder

-- | Return 'True' if 'RelaxDeps' specifies a non-empty set of relaxations
--
-- Equivalent to @isRelaxDeps = (/= 'mempty')@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data InstallMethod
deriving (Eq, Show, Generic, Bounded, Enum)

instance Binary InstallMethod
instance NFData InstallMethod
instance Structured InstallMethod

-- | Last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data OverwritePolicy
deriving (Show, Eq, Generic, Bounded, Enum)

instance Binary OverwritePolicy
instance NFData OverwritePolicy
instance Structured OverwritePolicy

instance Parsec OverwritePolicy where
Expand Down
3 changes: 3 additions & 0 deletions cabal-install/src/Distribution/Client/Types/Repo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ data RemoteRepo = RemoteRepo
deriving (Show, Eq, Ord, Generic)

instance Binary RemoteRepo
instance NFData RemoteRepo
instance Structured RemoteRepo

instance Pretty RemoteRepo where
Expand Down Expand Up @@ -134,6 +135,7 @@ data LocalRepo = LocalRepo
deriving (Show, Eq, Ord, Generic)

instance Binary LocalRepo
instance NFData LocalRepo
instance Structured LocalRepo

-- | Note: doesn't parse 'localRepoSharedCache' field.
Expand Down Expand Up @@ -202,6 +204,7 @@ data Repo
deriving (Show, Eq, Ord, Generic)

instance Binary Repo
instance NFData Repo
instance Structured Repo

-- | Check if this is a remote repo
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/Types/SourceRepo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ deriving instance Show (f FilePath) => Show (SourceRepositoryPackage f)
deriving instance Binary (f FilePath) => Binary (SourceRepositoryPackage f)
deriving instance (Typeable f, Structured (f FilePath)) => Structured (SourceRepositoryPackage f)

instance (Typeable f, NFData (f FilePath)) => NFData (SourceRepositoryPackage f)

-- | Read from @cabal.project@
type SourceRepoList = SourceRepositoryPackage []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data WriteGhcEnvironmentFilesPolicy
deriving (Eq, Enum, Bounded, Generic, Show)

instance Binary WriteGhcEnvironmentFilesPolicy
instance NFData WriteGhcEnvironmentFilesPolicy
instance Structured WriteGhcEnvironmentFilesPolicy

instance Parsec WriteGhcEnvironmentFilesPolicy where
Expand Down
7 changes: 7 additions & 0 deletions changelog.d/pr-11097
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
synopsis: Add NFData instances
packages: [Cabal, cabal-install, cabal-install-solver, Cabal-syntax]
prs: 11097
---

Add NFData instances necessary for HLS plugins to function.
Loading