Repository: amaranth-lang/amaranth
Pull request #1204 (2024-03-15 10:30:06)

lib.wiring: remove unnecessary flipping in `Signature.flatten`
The nested signature is already flipped, which means that its `flatten` method has performed the flipping on member flows already.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/1204?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 89.42%. Comparing base [(`27ca963`)](https://app.codecov.io/gh/amaranth-lang/amaranth/commit/27ca96383eedd68758dec50f0548299b5f932c6f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang) to head [(`3fb26f0`)](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/1204?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang).
> Report is 3 commits behind head on main.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #1204      +/-   ##
==========================================
- Coverage   89.44%   89.42%   -0.03%     
==========================================
  Files          43       43              
  Lines        9069     9067       -2     
  Branches     2151     2150       -1     
==========================================
- Hits         8112     8108       -4     
- Misses        781      783       +2     
  Partials      176      176              
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/1204?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang).


Patch:
diff --git a/amaranth/lib/wiring.py b/amaranth/lib/wiring.py
index 4d89139..632b0a2 100644
--- a/amaranth/lib/wiring.py
+++ b/amaranth/lib/wiring.py
@@ -798,8 +798,6 @@ class Signature(metaclass=SignatureMeta):
                     yield path, Member(member.flow, member.shape, init=member.init), value
                 elif member.is_signature:
                     for sub_path, sub_member, sub_value in member.signature.flatten(value):
-                        if member.flow == In:
-                            sub_member = sub_member.flip()
                         yield ((*path, *sub_path), sub_member, sub_value)
                 else:
                     assert False # :nocov:


Test patch:
diff --git a/tests/test_lib_wiring.py b/tests/test_lib_wiring.py
index 4bdfabe..b1471c0 100644
--- a/tests/test_lib_wiring.py
+++ b/tests/test_lib_wiring.py
@@ -373,8 +373,8 @@ class SignatureTestCase(unittest.TestCase):
         self.assertFlattenedSignature(sig.flatten(intf), [
             (("a", "p"), Out(1), intf.a.p),
             (("b", "q"), In (1), intf.b.q),
-            (("c", "r"), Out(1), intf.c.r),
-            (("d", "s"), In (1), intf.d.s),
+            (("c", "r"), In (1), intf.c.r),
+            (("d", "s"), Out(1), intf.d.s),
         ])
 
     def test_is_compliant_signature(self):