Skip to content

Commit a1cf3d1

Browse files
committed
remove spurious (second) update
thread nTrans differently
1 parent 15a06c8 commit a1cf3d1

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

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

+9-18
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ apply = \s rewrite ctx expr0 -> do
189189
error "apply: Normalizing from an unknown thread"
190190

191191
if isDebugging opts
192-
then applyDebug s expr0 hasChanged expr1
192+
then do
193+
countersV <- Lens.use transformCounters
194+
nTrans <- sum <$> MVar.readMVar countersV
195+
applyDebug s expr0 hasChanged expr1 nTrans
193196
else return expr1
194197
{-# INLINE apply #-}
195198

@@ -202,39 +205,27 @@ applyDebug
202205
-- ^ Whether the rewrite indicated change
203206
-> Term
204207
-- ^ New expression
208+
-> Word
205209
-> RewriteMonad extra Term
206-
applyDebug name exprOld hasChanged exprNew = do
207-
countersV <- Lens.use transformCounters
208-
counters <- MVar.takeMVar countersV
210+
applyDebug name exprOld hasChanged exprNew nTrans = do
209211
opts <- Lens.view debugOpts
210212

211-
let nTrans = sum counters
212213
let from = fromMaybe 0 (dbg_transformationsFrom opts)
213214
let limit = fromMaybe maxBound (dbg_transformationsLimit opts)
214215

215216
if | nTrans - from > limit -> do
216-
MVar.putMVar countersV counters
217217
error "-fclash-debug-transformations-limit exceeded"
218218
| nTrans <= from -> do
219-
MVar.putMVar countersV counters
220219
pure exprNew
221220
| otherwise ->
222-
go counters (pred nTrans) opts
221+
go (pred nTrans) opts
223222
where
224-
go counters nTrans opts = do
223+
go nTrans' opts = do
225224
ioLockV <- Lens.use ioLock
226225

227226
MVar.withMVar ioLockV $ \() ->
228227
traceWhen (hasDebugInfo TryTerm name opts) ("Tried: " ++ name ++ " on:\n" ++ before)
229228

230-
countersV <- Lens.use transformCounters
231-
232-
Monad.when (dbg_countTransformations opts && hasChanged) $
233-
MVar.putMVar countersV (HashMap.insertWith (const succ) (Text.pack name) 1 counters)
234-
235-
Monad.unless (dbg_countTransformations opts && hasChanged) $
236-
MVar.putMVar countersV counters
237-
238229
Monad.when (dbg_invariants opts && hasChanged) $ do
239230
tcm <- Lens.view tcCache
240231
let beforeTy = inferCoreTypeOf tcm exprOld
@@ -285,7 +276,7 @@ applyDebug name exprOld hasChanged exprNew = do
285276
++ before ++ "\nafter:\n" ++ after
286277

287278
MVar.withMVar ioLockV $ \() -> do
288-
traceWhen (hasDebugInfo AppliedName name opts && hasChanged) (name <> " {" <> show nTrans <> "}")
279+
traceWhen (hasDebugInfo AppliedName name opts && hasChanged) (name <> " {" <> show nTrans' <> "}")
289280
traceWhen (hasDebugInfo AppliedTerm name opts && hasChanged)
290281
("Changes when applying rewrite to:\n" ++ before ++ "\nResult:\n" ++ after ++ "\n")
291282
traceWhen (hasDebugInfo TryTerm name opts && not hasChanged)

0 commit comments

Comments
 (0)