Skip to content

Commit a6f3230

Browse files
Define iterateI replicate-like, preventing space leaks (#3043)
Fixes #3042
1 parent 7db1405 commit a6f3230

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIXED: individual items of `iterateI` no longer retain a reference to the whole list, preventing space leaks. See [#3042](https://github.com/clash-lang/clash-compiler/issues/3042).

clash-prelude/src/Clash/Sized/Vector.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,10 +1802,11 @@ iterate SNat = iterateI
18021802
--
18031803
-- <<doc/iterate.svg>>
18041804
iterateI :: forall n a. KnownNat n => (a -> a) -> a -> Vec n a
1805-
iterateI f a = xs
1806-
where
1807-
xs = init (a `Cons` ws)
1808-
ws = map f (lazyV xs)
1805+
iterateI f = iterateU (toUNat (SNat @n))
1806+
where
1807+
iterateU :: forall m. UNat m -> a -> Vec m a
1808+
iterateU UZero _ = Nil
1809+
iterateU (USucc s) a = a `Cons` iterateU s (f a)
18091810
-- See: https://github.com/clash-lang/clash-compiler/pull/2511
18101811
{-# CLASH_OPAQUE iterateI #-}
18111812
{-# ANN iterateI (InlineYamlPrimitive [VHDL,Verilog,SystemVerilog] [I.__i|

0 commit comments

Comments
 (0)