Skip to content

Commit 4e4085a

Browse files
wanda-phiwhitequark
authored andcommitted
Implement RFC 20: Deprecate non-FWFT FIFOs.
Tracking issue #875.
1 parent a60b996 commit 4e4085a

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

amaranth/lib/fifo.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""First-in first-out queues."""
22

3+
import warnings
4+
35
from .. import *
46
from ..asserts import *
57
from .._utils import log2_int
@@ -71,6 +73,10 @@ def __init__(self, *, width, depth, fwft=True):
7173
if not isinstance(depth, int) or depth < 0:
7274
raise TypeError("FIFO depth must be a non-negative integer, not {!r}"
7375
.format(depth))
76+
if not fwft:
77+
warnings.warn("support for FIFOs with `fwft=False` will be removed without a replacement; "
78+
"consider switching to `fwft=True` or copy the module into your project to continue using it",
79+
DeprecationWarning)
7480
self.width = width
7581
self.depth = depth
7682
self.fwft = fwft
@@ -117,7 +123,13 @@ class SyncFIFO(Elaboratable, FIFOInterface):
117123
w_attributes="")
118124

119125
def __init__(self, *, width, depth, fwft=True):
120-
super().__init__(width=width, depth=depth, fwft=fwft)
126+
if not fwft:
127+
warnings.warn("support for FIFOs with `fwft=False` will be removed without a replacement; "
128+
"consider switching to `fwft=True` or copy the module into your project to continue using it",
129+
DeprecationWarning)
130+
super().__init__(width=width, depth=depth)
131+
# Fix up fwft after initialization to avoid the warning from FIFOInterface.
132+
self.fwft = fwft
121133

122134
self.level = Signal(range(depth + 1))
123135

@@ -326,7 +338,7 @@ def elaborate(self, platform):
326338
m.d.comb += [
327339
Assert(produce < inner_depth),
328340
Assert(consume < inner_depth),
329-
]
341+
]
330342
with m.If(produce == consume):
331343
m.d.comb += Assert((inner_level == 0) | (inner_level == inner_depth))
332344
with m.If(produce > consume):

docs/changes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Apply the following changes to code written against Amaranth 0.3 to migrate it t
3333
* Replace uses of ``Record`` with :mod:`amaranth.lib.data` and :mod:`amaranth.lib.wiring`. The appropriate replacement depends on the use case. If ``Record`` was being used for data storage and accessing the bit-level representation, use :mod:`amaranth.lib.data`. If ``Record`` was being used for connecting design components together, use :mod:`amaranth.lib.wiring`.
3434
* Ensure the ``Pin`` instance returned by ``platform.request`` is not cast to value directly, but used for its fields. Replace code like ``leds = Cat(platform.request(led, n) for n in range(4))`` with ``leds = Cat(platform.request(led, n).o for n in range(4))`` (note the ``.o``).
3535
* Remove uses of ``amaranth.lib.scheduler.RoundRobin`` by inlining or copying the implementation of that class.
36+
* Remove uses of ``amaranth.lib.fifo.SyncFIFO(fwft=False)`` and ``amaranth.lib.fifo.FIFOInterface(fwft=False)`` by converting code to use ``fwft=True`` FIFOs or copying the implementation of those classes.
3637

3738
While code that uses the features listed as deprecated below will work in Amaranth 0.4, they will be removed in the next version.
3839

@@ -52,6 +53,7 @@ Implemented RFCs
5253
.. _RFC 15: https://amaranth-lang.org/rfcs/0015-lifting-shape-castables.html
5354
.. _RFC 18: https://amaranth-lang.org/rfcs/0018-reorganize-vendor-platforms.html
5455
.. _RFC 19: https://amaranth-lang.org/rfcs/0019-remove-scheduler.html
56+
.. _RFC 20: https://amaranth-lang.org/rfcs/0020-deprecate-non-fwft-fifos.html
5557
.. _RFC 22: https://amaranth-lang.org/rfcs/0022-valuecastable-shape.html
5658

5759

@@ -67,6 +69,7 @@ Implemented RFCs
6769
* `RFC 18`_: Reorganize vendor platforms
6870
* `RFC 19`_: Remove ``amaranth.lib.scheduler``
6971
* `RFC 15`_: Lifting shape-castable objects
72+
* `RFC 20`_: Deprecate non-FWFT FIFOs
7073
* `RFC 22`_: Define ``ValueCastable.shape()``
7174

7275

@@ -103,6 +106,8 @@ Standard library changes
103106
* Added: :mod:`amaranth.lib.data`. (`RFC 1`_)
104107
* Added: :mod:`amaranth.lib.crc`. (`RFC 6`_)
105108
* Deprecated: :mod:`amaranth.lib.scheduler`. (`RFC 19`_)
109+
* Deprecated: :class:`amaranth.lib.fifo.FIFOInterface` with ``fwft=False``. (`RFC 20`_)
110+
* Deprecated: :class:`amaranth.lib.fifo.SyncFIFO` with ``fwft=False``. (`RFC 20`_)
106111

107112

108113
Toolchain changes

tests/test_lib_fifo.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# amaranth: UnusedElaboratable=no
22

3+
import warnings
4+
35
from amaranth.hdl import *
46
from amaranth.asserts import *
57
from amaranth.sim import *
@@ -256,10 +258,14 @@ def test_sync_fwft_npot(self):
256258
self.check_sync_fifo(SyncFIFO(width=8, depth=5, fwft=True))
257259

258260
def test_sync_not_fwft_pot(self):
259-
self.check_sync_fifo(SyncFIFO(width=8, depth=4, fwft=False))
261+
with warnings.catch_warnings():
262+
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
263+
self.check_sync_fifo(SyncFIFO(width=8, depth=4, fwft=False))
260264

261265
def test_sync_not_fwft_npot(self):
262-
self.check_sync_fifo(SyncFIFO(width=8, depth=5, fwft=False))
266+
with warnings.catch_warnings():
267+
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
268+
self.check_sync_fifo(SyncFIFO(width=8, depth=5, fwft=False))
263269

264270
def test_sync_buffered_pot(self):
265271
self.check_sync_fifo(SyncFIFOBuffered(width=8, depth=4))

0 commit comments

Comments
 (0)