@@ -27,7 +27,7 @@ module Clash.Rewrite.Util
2727import Control.Concurrent.Supply (splitSupply )
2828import Control.DeepSeq
2929import Control.Exception (throw )
30- import Control.Lens ((%=) , (+=) , ( ^.) )
30+ import Control.Lens ((%=) , (^.) )
3131import qualified Control.Lens as Lens
3232import qualified Control.Monad as Monad
3333import 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
187189applyDebug 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 =
0 commit comments