Skip to content

Commit bde37fe

Browse files
committed
hdl.ast: deprecate UserValue in favor of ValueCastable.
Closes #527.
1 parent c9fd000 commit bde37fe

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

nmigen/hdl/ast.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,7 @@ def __repr__(self):
12371237
return "(proxy (array [{}]) {!r})".format(", ".join(map(repr, self.elems)), self.index)
12381238

12391239

1240+
# TODO(nmigen-0.4): remove
12401241
class UserValue(Value):
12411242
"""Value with custom lowering.
12421243
@@ -1257,6 +1258,7 @@ class UserValue(Value):
12571258
* Indexing or iterating through individual bits;
12581259
* Adding an assignment to the value to a ``Module`` using ``m.d.<domain> +=``.
12591260
"""
1261+
@deprecated("instead of `UserValue`, use `ValueCastable`", stacklevel=3)
12601262
def __init__(self, *, src_loc_at=0):
12611263
super().__init__(src_loc_at=1 + src_loc_at)
12621264
self.__lowered = None
@@ -1292,7 +1294,7 @@ class ValueCastable:
12921294
providing fixed semantics upfront, it is kept abstract for as long as possible, only being
12931295
cast to a concrete nMigen value when required.
12941296
1295-
Note that it is necessary to ensure that nMigen's view of representation of all values stays
1297+
Note that it is necessary to ensure that nMigen's view of representation of all values stays
12961298
internally consistent. The class deriving from ``ValueCastable`` must decorate the ``as_value``
12971299
method with the ``lowermethod`` decorator, which ensures that all calls to ``as_value``return the
12981300
same ``Value`` representation. If the class deriving from ``ValueCastable`` is mutable, it is

tests/test_hdl_ast.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,20 +1009,24 @@ def lower(self):
10091009

10101010
class UserValueTestCase(FHDLTestCase):
10111011
def test_shape(self):
1012-
uv = MockUserValue(1)
1013-
self.assertEqual(uv.shape(), unsigned(1))
1014-
self.assertIsInstance(uv.shape(), Shape)
1015-
uv.lowered = 2
1016-
self.assertEqual(uv.shape(), unsigned(1))
1017-
self.assertEqual(uv.lower_count, 1)
1012+
with warnings.catch_warnings():
1013+
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
1014+
uv = MockUserValue(1)
1015+
self.assertEqual(uv.shape(), unsigned(1))
1016+
self.assertIsInstance(uv.shape(), Shape)
1017+
uv.lowered = 2
1018+
self.assertEqual(uv.shape(), unsigned(1))
1019+
self.assertEqual(uv.lower_count, 1)
10181020

10191021
def test_lower_to_user_value(self):
1020-
uv = MockUserValue(MockUserValue(1))
1021-
self.assertEqual(uv.shape(), unsigned(1))
1022-
self.assertIsInstance(uv.shape(), Shape)
1023-
uv.lowered = MockUserValue(2)
1024-
self.assertEqual(uv.shape(), unsigned(1))
1025-
self.assertEqual(uv.lower_count, 1)
1022+
with warnings.catch_warnings():
1023+
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
1024+
uv = MockUserValue(MockUserValue(1))
1025+
self.assertEqual(uv.shape(), unsigned(1))
1026+
self.assertIsInstance(uv.shape(), Shape)
1027+
uv.lowered = MockUserValue(2)
1028+
self.assertEqual(uv.shape(), unsigned(1))
1029+
self.assertEqual(uv.lower_count, 1)
10261030

10271031

10281032
class MockValueCastableChanges(ValueCastable):

tests/test_hdl_xfrm.py

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

3+
import warnings
4+
35
from nmigen.hdl.ast import *
46
from nmigen.hdl.cd import *
57
from nmigen.hdl.ir import *
@@ -614,7 +616,9 @@ class UserValueTestCase(FHDLTestCase):
614616
def setUp(self):
615617
self.s = Signal()
616618
self.c = Signal()
617-
self.uv = MockUserValue(self.s)
619+
with warnings.catch_warnings():
620+
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
621+
self.uv = MockUserValue(self.s)
618622

619623
def test_lower(self):
620624
sync = ClockDomain()
@@ -645,6 +649,8 @@ class UserValueRecursiveTestCase(UserValueTestCase):
645649
def setUp(self):
646650
self.s = Signal()
647651
self.c = Signal()
648-
self.uv = MockUserValue(MockUserValue(self.s))
652+
with warnings.catch_warnings():
653+
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
654+
self.uv = MockUserValue(MockUserValue(self.s))
649655

650656
# inherit the test_lower method from UserValueTestCase because the checks are the same

0 commit comments

Comments
 (0)