From 809251970698ee3ce92f91b815f4d6ca53f1bf6a Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Fri, 19 Jan 2024 15:07:28 -0800 Subject: [PATCH] Support === on empty Aggregate (#3747) (cherry picked from commit da6ae7dc00a06e36c6ae900902b432d4ea9527d9) --- core/src/main/scala/chisel3/Data.scala | 6 ++++-- .../scala/chiselTests/DataEqualitySpec.scala | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/chisel3/Data.scala b/core/src/main/scala/chisel3/Data.scala index 259e6545f57..b778693dd0c 100644 --- a/core/src/main/scala/chisel3/Data.scala +++ b/core/src/main/scala/chisel3/Data.scala @@ -939,7 +939,8 @@ object Data { thiz.elementsIterator .zip(that.elementsIterator) .map { case (thisData, thatData) => thisData === thatData } - .reduce(_ && _) + .reduceOption(_ && _) // forall but that isn't defined for Bool on Seq + .getOrElse(true.B) } case (thiz: Record, that: Record) => if (thiz.elements.size != that.elements.size) { @@ -963,7 +964,8 @@ object Data { ) } } - .reduce(_ && _) + .reduceOption(_ && _) // forall but that isn't defined for Bool on Seq + .getOrElse(true.B) } // This should be matching to (DontCare, DontCare) but the compiler wasn't happy with that case (_: DontCare.type, _: DontCare.type) => true.B diff --git a/src/test/scala/chiselTests/DataEqualitySpec.scala b/src/test/scala/chiselTests/DataEqualitySpec.scala index 8fbbaf945e6..2090581dfce 100644 --- a/src/test/scala/chiselTests/DataEqualitySpec.scala +++ b/src/test/scala/chiselTests/DataEqualitySpec.scala @@ -70,6 +70,9 @@ class DataEqualitySpec extends ChiselFlatSpec with Utils { val a = UInt(8.W) val b: Bundle = gen } + class MaybeEmptyBundle(x: Boolean) extends Bundle { + val a = Option.when(x)(UInt(8.W)) + } behavior.of("UInt === UInt") it should "pass with equal values" in { @@ -164,6 +167,14 @@ class DataEqualitySpec extends ChiselFlatSpec with Utils { ) } } + it should "support empty Vecs" in { + assertTesterPasses { + new EqualityTester( + Wire(Vec(0, UInt(8.W))), + Wire(Vec(0, UInt(8.W))) + ) + } + } it should "fail with equal sizes, differing values" in { assertTesterFails { new EqualityTester( @@ -192,6 +203,14 @@ class DataEqualitySpec extends ChiselFlatSpec with Utils { ) } } + it should "support empty Bundles" in { + assertTesterPasses { + new EqualityTester( + (new MaybeEmptyBundle(false)).Lit(), + (new MaybeEmptyBundle(false)).Lit() + ) + } + } it should "fail with equal type, differing values" in { assertTesterFails { new EqualityTester(