Skip to content

Commit 0ee5de0

Browse files
committed
hdl.ast: deprecate Sample, Past, Rose, Fell, Stable.
See #526.
1 parent 9ec7f5b commit 0ee5de0

File tree

8 files changed

+40
-6
lines changed

8 files changed

+40
-6
lines changed

amaranth/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def context_like():
7272
def decorator_like(*args, **kwargs):
7373
with warnings.catch_warnings():
7474
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
75-
f(*args, **kwargs)
75+
return f(*args, **kwargs)
7676
return decorator_like
7777

7878

amaranth/hdl/ast.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from .. import tracer
1010
from .._utils import *
11+
from .._utils import _ignore_deprecated
1112
from .._unused import *
1213

1314

@@ -1333,6 +1334,7 @@ def wrapper_memoized(self, *args, **kwargs):
13331334
return wrapper_memoized
13341335

13351336

1337+
# TODO(amaranth-0.5): remove
13361338
@final
13371339
class Sample(Value):
13381340
"""Value from the past.
@@ -1341,6 +1343,7 @@ class Sample(Value):
13411343
of the ``domain`` clock back. If that moment is before the beginning of time, it is equal
13421344
to the value of the expression calculated as if each signal had its reset value.
13431345
"""
1346+
@deprecated("instead of using `Sample`, create a register explicitly")
13441347
def __init__(self, expr, clocks, domain, *, src_loc_at=0):
13451348
super().__init__(src_loc_at=1 + src_loc_at)
13461349
self.value = Value.cast(expr)
@@ -1367,20 +1370,32 @@ def __repr__(self):
13671370
self.value, "<default>" if self.domain is None else self.domain, self.clocks)
13681371

13691372

1373+
# TODO(amaranth-0.5): remove
1374+
@deprecated("instead of using `Past`, create a register explicitly")
13701375
def Past(expr, clocks=1, domain=None):
1371-
return Sample(expr, clocks, domain)
1376+
with _ignore_deprecated():
1377+
return Sample(expr, clocks, domain)
13721378

13731379

1380+
# TODO(amaranth-0.5): remove
1381+
@deprecated("instead of using `Stable`, create registers and comparisons explicitly")
13741382
def Stable(expr, clocks=0, domain=None):
1375-
return Sample(expr, clocks + 1, domain) == Sample(expr, clocks, domain)
1383+
with _ignore_deprecated():
1384+
return Sample(expr, clocks + 1, domain) == Sample(expr, clocks, domain)
13761385

13771386

1387+
# TODO(amaranth-0.5): remove
1388+
@deprecated("instead of using `Rose`, create registers and comparisons explicitly")
13781389
def Rose(expr, clocks=0, domain=None):
1379-
return ~Sample(expr, clocks + 1, domain) & Sample(expr, clocks, domain)
1390+
with _ignore_deprecated():
1391+
return ~Sample(expr, clocks + 1, domain) & Sample(expr, clocks, domain)
13801392

13811393

1394+
# TODO(amaranth-0.5): remove
1395+
@deprecated("instead of using `Fell`, create registers and comparisons explicitly")
13821396
def Fell(expr, clocks=0, domain=None):
1383-
return Sample(expr, clocks + 1, domain) & ~Sample(expr, clocks, domain)
1397+
with _ignore_deprecated():
1398+
return Sample(expr, clocks + 1, domain) & ~Sample(expr, clocks, domain)
13841399

13851400

13861401
@final

amaranth/hdl/xfrm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from collections import OrderedDict
33
from collections.abc import Iterable
44

5-
from .._utils import flatten
5+
from .._utils import flatten, _ignore_deprecated
66
from .. import tracer
77
from .ast import *
88
from .ast import _StatementList
@@ -526,6 +526,7 @@ class SampleDomainInjector(ValueTransformer, StatementTransformer):
526526
def __init__(self, domain):
527527
self.domain = domain
528528

529+
@_ignore_deprecated
529530
def on_Sample(self, value):
530531
if value.domain is not None:
531532
return value
@@ -555,6 +556,7 @@ def _name_reset(self, value):
555556
else:
556557
raise NotImplementedError # :nocov:
557558

559+
@_ignore_deprecated
558560
def on_Sample(self, value):
559561
if value in self.sample_cache:
560562
return self.sample_cache[value]

tests/test_hdl_ast.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from amaranth.hdl.ast import *
55

66
from .utils import *
7+
from amaranth._utils import _ignore_deprecated
78

89

910
class UnsignedEnum(Enum):
@@ -1187,27 +1188,32 @@ def test_recurse(self):
11871188

11881189

11891190
class SampleTestCase(FHDLTestCase):
1191+
@_ignore_deprecated
11901192
def test_const(self):
11911193
s = Sample(1, 1, "sync")
11921194
self.assertEqual(s.shape(), unsigned(1))
11931195

1196+
@_ignore_deprecated
11941197
def test_signal(self):
11951198
s1 = Sample(Signal(2), 1, "sync")
11961199
self.assertEqual(s1.shape(), unsigned(2))
11971200
s2 = Sample(ClockSignal(), 1, "sync")
11981201
s3 = Sample(ResetSignal(), 1, "sync")
11991202

1203+
@_ignore_deprecated
12001204
def test_wrong_value_operator(self):
12011205
with self.assertRaisesRegex(TypeError,
12021206
(r"^Sampled value must be a signal or a constant, not "
12031207
r"\(\+ \(sig \$signal\) \(const 1'd1\)\)$")):
12041208
Sample(Signal() + 1, 1, "sync")
12051209

1210+
@_ignore_deprecated
12061211
def test_wrong_clocks_neg(self):
12071212
with self.assertRaisesRegex(ValueError,
12081213
r"^Cannot sample a value 1 cycles in the future$"):
12091214
Sample(Signal(), -1, "sync")
12101215

1216+
@_ignore_deprecated
12111217
def test_wrong_domain(self):
12121218
with self.assertRaisesRegex(TypeError,
12131219
r"^Domain name must be a string or None, not 0$"):

tests/test_hdl_dsl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from amaranth.lib.enum import Enum
99

1010
from .utils import *
11+
from amaranth._utils import _ignore_deprecated
1112

1213

1314
class DSLTestCase(FHDLTestCase):
@@ -131,6 +132,7 @@ def test_reset_signal(self):
131132
)
132133
""")
133134

135+
@_ignore_deprecated
134136
def test_sample_domain(self):
135137
m = Module()
136138
i = Signal()

tests/test_hdl_xfrm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from amaranth.hdl.mem import *
1010

1111
from .utils import *
12+
from amaranth._utils import _ignore_deprecated
1213

1314

1415
class DomainRenamerTestCase(FHDLTestCase):
@@ -216,6 +217,7 @@ def setUp(self):
216217
self.o2 = Signal()
217218
self.o3 = Signal()
218219

220+
@_ignore_deprecated
219221
def test_lower_signal(self):
220222
f = Fragment()
221223
f.add_statements(
@@ -238,6 +240,7 @@ def test_lower_signal(self):
238240
self.assertEqual(len(f.drivers["sync"]), 2)
239241
self.assertEqual(len(f.drivers["pix"]), 1)
240242

243+
@_ignore_deprecated
241244
def test_lower_const(self):
242245
f = Fragment()
243246
f.add_statements(

tests/test_lib_fifo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from amaranth.lib.fifo import *
77

88
from .utils import *
9+
from amaranth._utils import _ignore_deprecated
910

1011

1112
class FIFOTestCase(FHDLTestCase):
@@ -60,6 +61,7 @@ def test_async_buffered_depth_wrong(self):
6061
r"requested exact depth 16 is not$")):
6162
AsyncFIFOBuffered(width=8, depth=16, exact_depth=True)
6263

64+
6365
class FIFOModel(Elaboratable, FIFOInterface):
6466
"""
6567
Non-synthesizable first-in first-out queue, implemented naively as a chain of registers.
@@ -128,6 +130,7 @@ def __init__(self, fifo, r_domain, w_domain):
128130
self.r_domain = r_domain
129131
self.w_domain = w_domain
130132

133+
@_ignore_deprecated
131134
def elaborate(self, platform):
132135
m = Module()
133136
m.submodules.dut = dut = self.fifo
@@ -168,6 +171,7 @@ def __init__(self, fifo, *, r_domain, w_domain, bound):
168171
self.w_domain = w_domain
169172
self.bound = bound
170173

174+
@_ignore_deprecated
171175
def elaborate(self, platform):
172176
m = Module()
173177
m.submodules.dut = fifo = self.fifo

tests/test_sim.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from amaranth.sim import *
1212

1313
from .utils import *
14+
from amaranth._utils import _ignore_deprecated
1415

1516

1617
class SimulatorUnitTestCase(FHDLTestCase):
@@ -811,6 +812,7 @@ def process():
811812
sim.add_clock(1e-6)
812813
sim.add_sync_process(process)
813814

815+
@_ignore_deprecated
814816
def test_sample_helpers(self):
815817
m = Module()
816818
s = Signal(2)

0 commit comments

Comments
 (0)