Skip to content

Commit c118b5e

Browse files
committed
treewide: (Set.union->(<>))
1 parent 7a53466 commit c118b5e

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

src/Nix/Effects/Derivation.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ parsePath p = case Store.parsePath "/nix/store" (encodeUtf8 p) of
7171
writeDerivation :: (Framed e m, MonadStore m) => Derivation -> m Store.StorePath
7272
writeDerivation drv@Derivation{inputs, name} = do
7373
let (inputSrcs, inputDrvs) = inputs
74-
references <- Set.fromList <$> traverse parsePath (Set.toList $ Set.union inputSrcs $ Set.fromList $ Map.keys inputDrvs)
74+
references <- Set.fromList <$> traverse parsePath (Set.toList $ inputSrcs <> Set.fromList (Map.keys inputDrvs))
7575
path <- addTextToStore (Text.append name ".drv") (unparseDrv drv) (S.fromList $ Set.toList references) False
7676
parsePath $ toText $ unStorePath path
7777

src/Nix/TH.hs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,35 @@ freeVars e = case unFix e of
4848
(NLiteralPath _ ) -> mempty
4949
(NEnvPath _ ) -> mempty
5050
(NUnary _ expr ) -> freeVars expr
51-
(NBinary _ left right ) -> Set.union (freeVars left) (freeVars right)
51+
(NBinary _ left right ) -> ((<>) `on` freeVars) left right
5252
(NSelect expr path orExpr) ->
5353
Set.unions
5454
[ freeVars expr
5555
, pathFree path
5656
, maybe mempty freeVars orExpr
5757
]
58-
(NHasAttr expr path) -> Set.union (freeVars expr) (pathFree path)
58+
(NHasAttr expr path) -> freeVars expr <> pathFree path
5959
(NAbs (Param varname) expr) -> Set.delete varname (freeVars expr)
6060
(NAbs (ParamSet set _ varname) expr) ->
61-
Set.union
62-
-- Include all free variables from the expression and the default arguments
63-
(freeVars expr)
64-
-- But remove the argument name if existing, and all arguments in the parameter set
61+
-- Include all free variables from the expression and the default arguments
62+
freeVars expr <>
63+
-- But remove the argument name if existing, and all arguments in the parameter set
64+
Set.difference
65+
(Set.unions $ freeVars <$> mapMaybe snd set)
6566
(Set.difference
66-
(Set.unions $ freeVars <$> mapMaybe snd set)
67-
(Set.difference
68-
(maybe mempty one varname)
69-
(Set.fromList $ fmap fst set)
70-
)
67+
(maybe mempty one varname)
68+
(Set.fromList $ fmap fst set)
7169
)
7270
(NLet bindings expr ) ->
73-
Set.union
74-
(freeVars expr)
75-
(Set.difference
76-
(bindFreeVars bindings)
77-
(bindDefs bindings)
78-
)
71+
freeVars expr <>
72+
Set.difference
73+
(bindFreeVars bindings)
74+
(bindDefs bindings)
7975
(NIf cond th el ) -> Set.unions $ freeVars <$> [cond, th, el]
8076
-- Evaluation is needed to find out whether x is a "real" free variable in `with y; x`, we just include it
8177
-- This also makes sense because its value can be overridden by `x: with y; x`
82-
(NWith set expr ) -> Set.union (freeVars set ) (freeVars expr)
83-
(NAssert assertion expr ) -> Set.union (freeVars assertion) (freeVars expr)
78+
(NWith set expr ) -> ((<>) `on` freeVars) set expr
79+
(NAssert assertion expr ) -> ((<>) `on` freeVars) assertion expr
8480
(NSynHole _ ) -> mempty
8581

8682
where
@@ -100,7 +96,7 @@ freeVars e = case unFix e of
10096
bind1Free :: Binding NExpr -> Set VarName
10197
bind1Free (Inherit Nothing keys _) = Set.fromList $ mapMaybe staticKey keys
10298
bind1Free (Inherit (Just scope) _ _) = freeVars scope
103-
bind1Free (NamedVar path expr _) = Set.union (pathFree path) (freeVars expr)
99+
bind1Free (NamedVar path expr _) = pathFree path <> freeVars expr
104100

105101
staticKey :: NKeyName r -> Maybe VarName
106102
staticKey (StaticKey varname) = pure varname

src/Nix/Type/Infer.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ instance FreeTypeVars Type where
610610
ftv (TVar a ) = one a
611611
ftv (TSet _ a ) = Set.unions $ ftv <$> M.elems a
612612
ftv (TList a ) = Set.unions $ ftv <$> a
613-
ftv (t1 :~> t2) = ftv t1 `Set.union` ftv t2
613+
ftv (t1 :~> t2) = ftv t1 <> ftv t2
614614
ftv (TMany ts ) = Set.unions $ ftv <$> ts
615615

616616
instance FreeTypeVars TVar where
@@ -620,10 +620,10 @@ instance FreeTypeVars Scheme where
620620
ftv (Forall as t) = ftv t `Set.difference` Set.fromList as
621621

622622
instance FreeTypeVars a => FreeTypeVars [a] where
623-
ftv = foldr (Set.union . ftv) mempty
623+
ftv = foldr ((<>) . ftv) mempty
624624

625625
instance (Ord a, FreeTypeVars a) => FreeTypeVars (Set.Set a) where
626-
ftv = foldr (Set.union . ftv) mempty
626+
ftv = foldr ((<>) . ftv) mempty
627627

628628
-- * class @ActiveTypeVars@
629629

@@ -633,12 +633,12 @@ class ActiveTypeVars a where
633633
-- ** Instances
634634

635635
instance ActiveTypeVars Constraint where
636-
atv (EqConst t1 t2 ) = ftv t1 `Set.union` ftv t2
637-
atv (ImpInstConst t1 ms t2) = ftv t1 `Set.union` (ftv ms `Set.intersection` ftv t2)
638-
atv (ExpInstConst t s ) = ftv t `Set.union` ftv s
636+
atv (EqConst t1 t2 ) = ftv t1 <> ftv t2
637+
atv (ImpInstConst t1 ms t2) = ftv t1 <> (ftv ms `Set.intersection` ftv t2)
638+
atv (ExpInstConst t s ) = ftv t <> ftv s
639639

640640
instance ActiveTypeVars a => ActiveTypeVars [a] where
641-
atv = foldr (Set.union . atv) mempty
641+
atv = foldr ((<>) . atv) mempty
642642

643643
-- * Other
644644

0 commit comments

Comments
 (0)