From a5f11dafaec1151e1611813a9f7de7e0b5de27ca 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 47430b01eb7..674b015be79 100644 --- a/core/src/main/scala/chisel3/Data.scala +++ b/core/src/main/scala/chisel3/Data.scala @@ -915,7 +915,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) { @@ -939,7 +940,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 4430389a2bc..574dd7f2179 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 { @@ -140,6 +143,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( @@ -168,6 +179,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(