@@ -189,7 +189,10 @@ apply = \s rewrite ctx expr0 -> do
189
189
error " apply: Normalizing from an unknown thread"
190
190
191
191
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
193
196
else return expr1
194
197
{-# INLINE apply #-}
195
198
@@ -202,39 +205,27 @@ applyDebug
202
205
-- ^ Whether the rewrite indicated change
203
206
-> Term
204
207
-- ^ New expression
208
+ -> Word
205
209
-> 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
209
211
opts <- Lens. view debugOpts
210
212
211
- let nTrans = sum counters
212
213
let from = fromMaybe 0 (dbg_transformationsFrom opts)
213
214
let limit = fromMaybe maxBound (dbg_transformationsLimit opts)
214
215
215
216
if | nTrans - from > limit -> do
216
- MVar. putMVar countersV counters
217
217
error " -fclash-debug-transformations-limit exceeded"
218
218
| nTrans <= from -> do
219
- MVar. putMVar countersV counters
220
219
pure exprNew
221
220
| otherwise ->
222
- go counters (pred nTrans) opts
221
+ go (pred nTrans) opts
223
222
where
224
- go counters nTrans opts = do
223
+ go nTrans' opts = do
225
224
ioLockV <- Lens. use ioLock
226
225
227
226
MVar. withMVar ioLockV $ \ () ->
228
227
traceWhen (hasDebugInfo TryTerm name opts) (" Tried: " ++ name ++ " on:\n " ++ before)
229
228
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
-
238
229
Monad. when (dbg_invariants opts && hasChanged) $ do
239
230
tcm <- Lens. view tcCache
240
231
let beforeTy = inferCoreTypeOf tcm exprOld
@@ -285,7 +276,7 @@ applyDebug name exprOld hasChanged exprNew = do
285
276
++ before ++ " \n after:\n " ++ after
286
277
287
278
MVar. withMVar ioLockV $ \ () -> do
288
- traceWhen (hasDebugInfo AppliedName name opts && hasChanged) (name <> " {" <> show nTrans <> " }" )
279
+ traceWhen (hasDebugInfo AppliedName name opts && hasChanged) (name <> " {" <> show nTrans' <> " }" )
289
280
traceWhen (hasDebugInfo AppliedTerm name opts && hasChanged)
290
281
(" Changes when applying rewrite to:\n " ++ before ++ " \n Result:\n " ++ after ++ " \n " )
291
282
traceWhen (hasDebugInfo TryTerm name opts && not hasChanged)
0 commit comments