Skip to content

Commit 0eb6265

Browse files
Alex McKennaalex-mckenna
authored andcommitted
Report changes in constantSpec / reduceNonRepPrim
These transformations were previously not reporting all times when they were applied / changed the input term. However, the check for this was only enabled with DebugApplied or higher, which meant CI would not identify these mistakes (as CI uses DebugSilent). Fixes #1851
1 parent e7d7a47 commit 0eb6265

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

clash-lib/src/Clash/Normalize/PrimitiveReductions.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ reduceIterateI (TransformContext is0 ctx) n aTy vTy f0 a = do
485485
-- in
486486
-- (a :> el1 :> el2 :> el3 :> ..)
487487
--
488-
pure (Letrec (zip elementIds elems) vec)
488+
changed (Letrec (zip elementIds elems) vec)
489489

490490
-- | Replace an application of the @Clash.Sized.Vector.traverse#@ primitive on
491491
-- vectors of a known length @n@, by the fully unrolled recursive "definition"

clash-lib/src/Clash/Normalize/Transformations/Specialize.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ module Clash.Normalize.Transformations.Specialize
2222

2323
import qualified Control.Lens as Lens
2424
import Control.Monad.Extra (orM)
25+
import qualified Control.Monad.Writer as Writer (listen)
2526
import qualified Data.Either as Either
27+
import qualified Data.Monoid as Monoid (getAny)
2628
import GHC.Stack (HasCallStack)
2729

2830
import Clash.Core.FreeVars (termFreeTyVars, typeFreeVars)
@@ -44,7 +46,7 @@ import Clash.Rewrite.Combinators (topdownR)
4446
import Clash.Rewrite.Types
4547
( TransformContext(..), bindings, censor, customReprs, tcCache
4648
, typeTranslator, workFreeBinders)
47-
import Clash.Rewrite.Util (mkDerivedName, mkTmBinderFor, setChanged)
49+
import Clash.Rewrite.Util (mkDerivedName, mkTmBinderFor, setChanged, changed)
4850
import Clash.Rewrite.WorkFree (isWorkFree)
4951
import Clash.Normalize.Types (NormRewrite, NormalizeSession)
5052
import Clash.Normalize.Util
@@ -234,11 +236,13 @@ constantSpec ctx@(TransformContext is0 tfCtx) e@(App e1 e2)
234236
else do
235237
-- Parts of e2 are constant
236238
let is1 = extendInScopeSetList is0 (fst <$> csrNewBindings specInfo)
237-
Letrec newBindings
238-
<$> specializeNorm
239-
(TransformContext is1 tfCtx)
240-
(App e1 (csrNewTerm specInfo))
239+
(body, isSpec) <- Writer.listen $ specializeNorm
240+
(TransformContext is1 tfCtx)
241+
(App e1 (csrNewTerm specInfo))
241242

243+
if Monoid.getAny isSpec
244+
then changed (Letrec newBindings body)
245+
else return e
242246
else
243247
-- e2 has no constant parts
244248
return e

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ applyDebug lvl _transformations _fromLimit name exprOld hasChanged exprNew =
275275
]
276276
) (return ())
277277

278-
Monad.when (lvl >= DebugApplied && not hasChanged && not (exprOld `aeqTerm` exprNew)) $
278+
Monad.when (lvl >= DebugSilent && not hasChanged && not (exprOld `aeqTerm` exprNew)) $
279279
error $ $(curLoc) ++ "Expression changed without notice(" ++ name ++ "): before"
280280
++ before ++ "\nafter:\n" ++ after
281281

0 commit comments

Comments
 (0)