Skip to content

Commit fb128e5

Browse files
author
Alex McKenna
committed
Remove transformCounter
As per the TODO, transformCounter is removed and where needed obtained by summing the transformations in transformCounters.
1 parent 7d503e1 commit fb128e5

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

clash-lib/src/Clash/Normalize.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ runNormalization env supply globals typeTrans peEval eval rcsMap topEnts =
125125
(mkVarSet topEnts)
126126

127127
rwState = RewriteState
128-
0
129128
mempty -- transformCounters Map
130129
globals
131130
supply

clash-lib/src/Clash/Rewrite/Types.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ data RewriteStep
7777
-- | State of a rewriting session
7878
data RewriteState extra
7979
= RewriteState
80-
-- TODO Given we now keep transformCounters, this should just be 'fold'
81-
-- over that map, otherwise the two counts could fall out of sync.
82-
{ _transformCounter :: {-# UNPACK #-} !Word
83-
-- ^ Total number of applied transformations
84-
, _transformCounters :: HashMap Text Word
80+
{ _transformCounters :: HashMap Text Word
8581
-- ^ Map that tracks how many times each transformation is applied
8682
, _bindings :: !BindingMap
8783
-- ^ Global binders

clash-lib/src/Clash/Rewrite/Util.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Clash.Rewrite.Util
2727
import Control.Concurrent.Supply (splitSupply)
2828
import Control.DeepSeq
2929
import Control.Exception (throw)
30-
import Control.Lens ((%=), (+=), (^.))
30+
import Control.Lens ((%=), (^.))
3131
import qualified Control.Lens as Lens
3232
import qualified Control.Monad as Monad
3333
import qualified Control.Monad.State.Strict as State
@@ -151,7 +151,9 @@ apply = \s rewrite ctx expr0 -> do
151151

152152
(!expr1,anyChanged) <- Writer.listen (rewrite ctx expr0)
153153
let hasChanged = Monoid.getAny anyChanged
154-
Monad.when hasChanged (transformCounter += 1)
154+
155+
Monad.when hasChanged $
156+
transformCounters %= HashMap.insertWith (const succ) (Text.pack s) 1
155157

156158
-- NB: When -fclash-debug-history is on, emit binary data holding the recorded rewrite steps
157159
let rewriteHistFile = dbg_historyFile opts
@@ -185,7 +187,7 @@ applyDebug
185187
-- ^ New expression
186188
-> RewriteMonad extra Term
187189
applyDebug name exprOld hasChanged exprNew = do
188-
nTrans <- Lens.use transformCounter
190+
nTrans <- sum <$> Lens.use transformCounters
189191
opts <- Lens.view debugOpts
190192

191193
let from = fromMaybe 0 (dbg_transformationsFrom opts)
@@ -196,11 +198,9 @@ applyDebug name exprOld hasChanged exprNew = do
196198
| nTrans <= from ->
197199
pure exprNew
198200
| otherwise ->
199-
go opts
201+
go (pred nTrans) opts
200202
where
201-
go opts = traceIf (hasDebugInfo TryTerm name opts) ("Tried: " ++ name ++ " on:\n" ++ before) $ do
202-
nTrans <- pred <$> Lens.use transformCounter
203-
203+
go nTrans opts = traceIf (hasDebugInfo TryTerm name opts) ("Tried: " ++ name ++ " on:\n" ++ before) $ do
204204
Monad.when (dbg_countTransformations opts && hasChanged) $ do
205205
transformCounters %= HashMap.insertWith (const succ) (Text.pack name) 1
206206

@@ -285,7 +285,7 @@ runRewriteSession r s m = do
285285
traceIf (dbg_countTransformations (opt_debug (envOpts (_clashEnv r))))
286286
("Clash: Transformations:\n" ++ Text.unpack (showCounters (s' ^. transformCounters))) $
287287
traceIf (None < dbg_transformationInfo (opt_debug (envOpts (_clashEnv r))))
288-
("Clash: Applied " ++ show (s' ^. transformCounter) ++ " transformations")
288+
("Clash: Applied " ++ show (s' ^. transformCounters . Lens.to sum) ++ " transformations")
289289
pure a
290290
where
291291
showCounters =

clash-lib/tests/Test/Clash/Rewrite.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ instance Default RewriteEnv where
7575

7676
instance Default extra => Default (RewriteState extra) where
7777
def = RewriteState
78-
{ _transformCounter=0
79-
, _transformCounters=mempty
78+
{ _transformCounters=mempty
8079
, _bindings=emptyVarEnv
8180
, _uniqSupply=unsafePerformIO newSupply
8281
, _curFun=error "_curFun: NYI"

0 commit comments

Comments
 (0)