Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not inline let-bound recursive calls (copy #2844) #2850

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/2024-11-18T13_43_58+01_00_fix2839
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FIXED: Clash errored saying it cannot translate a globally recursive function in code that originally only contains let-bound (local) recursion [#2839](https://github.com/clash-lang/clash-compiler/issues/2839).
9 changes: 8 additions & 1 deletion clash-lib/src/Clash/Normalize/Transformations/Inline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ bindConstantVar = inlineBinders test
True -> return (i `notElemFreeVars` e)
_ -> do
tcm <- Lens.view tcCache
case isWorkFreeIsh tcm e of
(fn,_) <- Lens.use curFun
-- Don't inline things that perform work, it increases the circuit size.
--
-- Also don't inline globally recursive calls, it prevents the
-- recToLetRec transformation from transforming global recursion to
-- local recursion.
-- See https://github.com/clash-lang/clash-compiler/issues/2839
case isWorkFreeIsh tcm e && not (e == Var fn) of
True -> Lens.view inlineConstantLimit >>= \case
0 -> return True
n -> return (termSize e <= n)
Expand Down
1 change: 1 addition & 0 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ runClashTest = defaultMain $ clashTestRoot
, runTest "T2623CaseConFVs" def{hdlLoad=[],hdlSim=[],hdlTargets=[VHDL]}
, runTest "T2781" def{hdlLoad=[],hdlSim=[],hdlTargets=[VHDL]}
, runTest "T2628" def{hdlTargets=[VHDL], buildTargets=BuildSpecific ["TACacheServerStep"], hdlSim=[]}
, runTest "T2839" def{hdlLoad=[],hdlSim=[],hdlTargets=[VHDL]}
] <>
if compiledWith == Cabal then
-- This tests fails without environment files present, which are only
Expand Down
12 changes: 12 additions & 0 deletions tests/shouldwork/Issues/T2839.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module T2839 where

import Clash.Explicit.Prelude
import Clash.Explicit.Testbench

topEntity ::
Signal System (Unsigned 8)
topEntity = register clk noReset enableGen 100 0
where
cntr = register clk noReset enableGen (0 :: Unsigned 8) 0
done = (== 100) <$> cntr
clk = tbClockGen $ not <$> done
Loading