Skip to content

Commit

Permalink
Merge pull request #115 from haskell/wip/cannonical-maxvars
Browse files Browse the repository at this point in the history
Make definition of Monoid MaxVars cannonical
  • Loading branch information
TeofilC authored Feb 25, 2025
2 parents d3949cc + b715e81 commit 56d2710
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
* Drop dependency on `array` ([#114](https://github.com/haskell/ghc-events/pull/114))
* Make definition of `Monoid MaxVars` cannonical ([#115](https://github.com/haskell/ghc-events/pull/115))


## 0.20.0.0 - 2024-11-25
Expand Down
13 changes: 10 additions & 3 deletions src/GHC/RTS/Events/Merge.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,22 @@ data MaxVars = MaxVars { mcapset :: !Word32
, mthread :: !ThreadId }
-- TODO introduce parallel RTS process and machine var.s

combineMaxVars :: MaxVars -> MaxVars -> MaxVars
combineMaxVars (MaxVars a b c) (MaxVars x y z) =
MaxVars (max a x) (b + y) (max c z)

#if MIN_VERSION_base(4,11,0)
instance Semigroup MaxVars where
(<>) = mappend
(<>) = combineMaxVars
#endif

instance Monoid MaxVars where
mempty = MaxVars 0 0 0
mappend (MaxVars a b c) (MaxVars x y z) =
MaxVars (max a x) (b + y) (max c z)
#if MIN_VERSION_base(4,11,0)
mappend = (<>)
#else
mappend = combineMaxVars
#endif
-- avoid space leaks:
mconcat = foldl' mappend mempty

Expand Down

0 comments on commit 56d2710

Please sign in to comment.