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 4 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
3 changes: 3 additions & 0 deletions Cabal-syntax/src/Distribution/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ data AbiTag
instance Binary AbiTag
instance Structured AbiTag

instance NFData AbiTag where
rnf = genericRnf
Copy link
Member

Choose a reason for hiding this comment

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

When Generic is derived, just instance NFData AbiTag is sufficient.
Are there reasons to be more explicit?


instance Pretty AbiTag where
pretty NoAbiTag = Disp.empty
pretty (AbiTag tag) = Disp.text tag
Expand Down
14 changes: 14 additions & 0 deletions Cabal/src/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ data Compiler = Compiler
instance Binary Compiler
instance Structured Compiler

instance NFData Compiler where
rnf = genericRnf

showCompilerId :: Compiler -> String
showCompilerId = prettyShow . compilerId

Expand Down Expand Up @@ -207,6 +210,9 @@ data PackageDBX fp
instance Binary fp => Binary (PackageDBX fp)
instance Structured fp => Structured (PackageDBX fp)

instance NFData fp => NFData (PackageDBX fp) where
rnf = genericRnf

-- | Parse a PackageDB stack entry
--
-- @since 3.7.0.0
Expand Down Expand Up @@ -307,6 +313,8 @@ data OptimisationLevel
instance Binary OptimisationLevel
instance Structured OptimisationLevel

instance NFData OptimisationLevel where
rnf = genericRnf
instance Parsec OptimisationLevel where
parsec = parsecOptimisationLevel

Expand Down Expand Up @@ -356,6 +364,9 @@ data DebugInfoLevel
instance Binary DebugInfoLevel
instance Structured DebugInfoLevel

instance NFData DebugInfoLevel where
rnf = genericRnf

instance Parsec DebugInfoLevel where
parsec = parsecDebugInfoLevel

Expand Down Expand Up @@ -609,6 +620,9 @@ data ProfDetailLevel
instance Binary ProfDetailLevel
instance Structured ProfDetailLevel

instance NFData ProfDetailLevel where
rnf = genericRnf

instance Parsec ProfDetailLevel where
parsec = parsecProfDetailLevel

Expand Down
6 changes: 6 additions & 0 deletions Cabal/src/Distribution/Simple/InstallDirs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ data InstallDirs dir = InstallDirs
instance Binary dir => Binary (InstallDirs dir)
instance Structured dir => Structured (InstallDirs dir)

instance NFData dir => NFData (InstallDirs dir) where
rnf = genericRnf

instance (Semigroup dir, Monoid dir) => Monoid (InstallDirs dir) where
mempty = gmempty
mappend = (<>)
Expand Down Expand Up @@ -399,6 +402,9 @@ newtype PathTemplate = PathTemplate [PathComponent]
instance Binary PathTemplate
instance Structured PathTemplate

instance NFData PathTemplate where
rnf = genericRnf

type PathTemplateEnv = [(PathTemplateVariable, PathTemplate)]

-- | Convert a 'FilePath' to a 'PathTemplate' including any template vars.
Expand Down
6 changes: 6 additions & 0 deletions Cabal/src/Distribution/Simple/InstallDirs/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ data PathComponent
instance Binary PathComponent
instance Structured PathComponent

instance NFData PathComponent where
rnf = genericRnf

data PathTemplateVariable
= -- | The @$prefix@ path variable
PrefixVar
Expand Down Expand Up @@ -69,6 +72,9 @@ data PathTemplateVariable
instance Binary PathTemplateVariable
instance Structured PathTemplateVariable

instance NFData PathTemplateVariable where
rnf = genericRnf

instance Show PathTemplateVariable where
show PrefixVar = "prefix"
show LibNameVar = "libname"
Expand Down
3 changes: 3 additions & 0 deletions Cabal/src/Distribution/Simple/Setup/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ data HaddockTarget = ForHackage | ForDevelopment deriving (Eq, Show, Generic)
instance Binary HaddockTarget
instance Structured HaddockTarget

instance NFData HaddockTarget where
rnf = genericRnf

instance Pretty HaddockTarget where
pretty ForHackage = Disp.text "for-hackage"
pretty ForDevelopment = Disp.text "for-development"
Expand Down
5 changes: 5 additions & 0 deletions Cabal/src/Distribution/Types/ParStrat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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: 3 additions & 0 deletions Cabal/src/Distribution/Verbosity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ instance Bounded Verbosity where
instance Binary Verbosity
instance Structured Verbosity

instance NFData Verbosity where
rnf = genericRnf

-- | In 'silent' mode, we should not print /anything/ unless an error occurs.
silent :: Verbosity
silent = mkVerbosity Silent
Expand Down
6 changes: 6 additions & 0 deletions Cabal/src/Distribution/Verbosity/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ data VerbosityLevel = Silent | Normal | Verbose | Deafening
instance Binary VerbosityLevel
instance Structured VerbosityLevel

instance NFData VerbosityLevel where
rnf = genericRnf

data VerbosityFlag
= VCallStack
| VCallSite
Expand All @@ -27,3 +30,6 @@ data VerbosityFlag

instance Binary VerbosityFlag
instance Structured VerbosityFlag

instance NFData VerbosityFlag where
rnf = genericRnf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ data ConstraintSource =
instance Binary ConstraintSource
instance Structured ConstraintSource

instance NFData ConstraintSource where
rnf = genericRnf

-- | Description of a 'ConstraintSource'.
showConstraintSource :: ConstraintSource -> String
showConstraintSource = prettyShow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ enableStanzas optionalStanzas = ComponentRequestedSpec
instance Binary OptionalStanza
instance Structured OptionalStanza

instance NFData OptionalStanza where
rnf = genericRnf

-------------------------------------------------------------------------------
-- OptionalStanzaSet
-------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ data PackageProperty
instance Binary PackageProperty
instance Structured PackageProperty

instance NFData PackageProperty where
rnf = genericRnf

instance Pretty PackageProperty where
pretty (PackagePropertyVersion verrange) = pretty verrange
pretty PackagePropertyInstalled = Disp.text "installed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ instance Ord ProjectConfigPath where
instance Binary ProjectConfigPath
instance Structured ProjectConfigPath

instance NFData ProjectConfigPath where
rnf = genericRnf

-- | Renders the path like this;
--
-- >D.config
Expand Down
33 changes: 33 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,39 @@ instance Structured AllowBootLibInstalls
instance Structured OnlyConstrained
instance Structured SolveExecutables

instance NFData ReorderGoals where
rnf = genericRnf

instance NFData CountConflicts where
rnf = genericRnf

instance NFData FineGrainedConflicts where
rnf = genericRnf

instance NFData IndependentGoals where
rnf = genericRnf

instance NFData PreferOldest where
rnf = genericRnf

instance NFData MinimizeConflictSet where
rnf = genericRnf

instance NFData AvoidReinstalls where
rnf = genericRnf

instance NFData ShadowPkgs where
rnf = genericRnf

instance NFData StrongFlags where
rnf = genericRnf

instance NFData AllowBootLibInstalls where
rnf = genericRnf

instance NFData OnlyConstrained where
rnf = genericRnf

instance Pretty OnlyConstrained where
pretty OnlyConstrainedAll = PP.text "all"
pretty OnlyConstrainedNone = PP.text "none"
Expand Down
3 changes: 3 additions & 0 deletions cabal-install/src/Distribution/Client/BuildReports/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ data ReportLevel = NoReports | AnonymousReports | DetailedReports
instance Binary ReportLevel
instance Structured ReportLevel

instance NFData ReportLevel where
rnf = genericRnf

instance Pretty ReportLevel where
pretty NoReports = Disp.text "none"
pretty AnonymousReports = Disp.text "anonymous"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ instance Semigroup ClientInstallFlags where
instance Binary ClientInstallFlags
instance Structured ClientInstallFlags

instance NFData ClientInstallFlags where
rnf = genericRnf

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

instance NFData PreSolver where
rnf = genericRnf

instance Pretty PreSolver where
pretty AlwaysModular = text "modular"

Expand Down
32 changes: 32 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,35 @@ instance Structured ProjectConfigProvenance
instance Structured PackageConfig
instance Structured ProjectFileParser

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

instance NFData ProjectConfig where
rnf = genericRnf

instance NFData ProjectConfigBuildOnly where
rnf = genericRnf

instance NFData ProjectConfigShared where
rnf = genericRnf

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

instance NFData PackageConfig where
rnf = genericRnf

-- | 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) where
rnf = genericRnf

instance Ord k => Monoid (MapLast k v) where
mempty = MapLast Map.empty
mappend = (<>)
Expand All @@ -378,6 +400,9 @@ 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) where
rnf = genericRnf

instance (Semigroup v, Ord k) => Monoid (MapMappend k v) where
mempty = MapMappend Map.empty
mappend = (<>)
Expand Down Expand Up @@ -464,6 +489,9 @@ data SolverSettings = SolverSettings
instance Binary SolverSettings
instance Structured SolverSettings

instance NFData SolverSettings where
rnf = genericRnf

-- | Resolved configuration for things that affect how we build and not the
-- value of the things we build. The idea is that this is easier to use than
-- the raw configuration because in the raw configuration everything is
Expand Down Expand Up @@ -501,3 +529,7 @@ data BuildTimeSettings = BuildTimeSettings
, buildSettingProgPathExtra :: [FilePath]
, buildSettingHaddockOpen :: Bool
}
deriving (Generic)

instance NFData BuildTimeSettings where
rnf = genericRnf
9 changes: 9 additions & 0 deletions cabal-install/src/Distribution/Client/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ data UserQualifier
instance Binary UserQualifier
instance Structured UserQualifier

instance NFData UserQualifier where
rnf = genericRnf

-- | Version of 'ConstraintScope' that a user may specify on the
-- command line.
data UserConstraintScope
Expand All @@ -625,6 +628,9 @@ data UserConstraintScope
instance Binary UserConstraintScope
instance Structured UserConstraintScope

instance NFData UserConstraintScope where
rnf = genericRnf

fromUserQualifier :: UserQualifier -> Qualifier
fromUserQualifier UserQualToplevel = QualToplevel
fromUserQualifier (UserQualSetup name) = QualSetup name
Expand All @@ -645,6 +651,9 @@ data UserConstraint
instance Binary UserConstraint
instance Structured UserConstraint

instance NFData UserConstraint where
rnf = genericRnf

userConstraintPackageName :: UserConstraint -> PackageName
userConstraintPackageName (UserConstraint scope _) = scopePN scope
where
Expand Down
21 changes: 21 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,27 @@ instance Structured RelaxedDep
instance Structured AllowNewer
instance Structured AllowOlder

instance NFData RelaxDeps where
rnf = genericRnf

instance NFData RelaxDepMod where
rnf = genericRnf

instance NFData RelaxDepScope where
rnf = genericRnf

instance NFData RelaxDepSubject where
rnf = genericRnf

instance NFData RelaxedDep where
rnf = genericRnf

instance NFData AllowNewer where
rnf = genericRnf

instance NFData AllowOlder where
rnf = genericRnf

-- | Return 'True' if 'RelaxDeps' specifies a non-empty set of relaxations
--
-- Equivalent to @isRelaxDeps = (/= 'mempty')@
Expand Down
3 changes: 3 additions & 0 deletions cabal-install/src/Distribution/Client/Types/InstallMethod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ data InstallMethod
instance Binary InstallMethod
instance Structured InstallMethod

instance NFData InstallMethod where
rnf = genericRnf

-- | Last
instance Semigroup InstallMethod where
_ <> x = x
Expand Down
Loading
Loading