From 4072351267dc06f7d4ed8a98311e301a172af740 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 13 Oct 2021 11:51:37 +0100 Subject: [PATCH] clean up Cat and Repl after realising that Value.cast will pass through something that is already derived from Value (UserValue) unmodified --- nmigen/hdl/ast.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index 03d2be6..39fb33f 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -862,18 +862,13 @@ def Cat(*args, src_loc_at=0): lose the opportunity for "redirection" (Value.__Cat__ would always be called). """ - # flatten the args and convert to tuple (not a generator) - args = tuple(flatten(args)) + # rely on Value.cast leaving Value/UserValue unmodified + args = [Value.cast(v) for v in flatten(args)] # check if there are no arguments (zero-length Signal). if len(args) == 0: return _InternalCat(*args, src_loc_at=src_loc_at) - # determine if the first is a UserValue. - first, rest = args[0], args[1:] - if not isinstance(args[0], UserValue): - first = Value.cast(first) # ok to downcast to Value - # all other arguments are safe to downcast to Value - rest = map(Value.cast, rest) # assume first item defines the "handling" for all others + first, rest = args[0], args[1:] return first.__Cat__(*rest, src_loc_at=src_loc_at) @@ -927,8 +922,7 @@ class _InternalCat(Value): @final def Repl(value, count, *, src_loc_at=0): - if not isinstance(value, Value): # rare instances where integers are passed - value = Value.cast(value) + value = Value.cast(value) # relies on Value/UserValue returned unmodified return value.__Repl__(count, src_loc_at=src_loc_at) -- 2.30.2