From 99f745a01b2c93516b9bbc6c6558724a4ed80f92 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Fri, 19 Jan 2024 13:48:07 -0800 Subject: [PATCH] Support === on empty Aggregate --- 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 979b561b1b2..c65635182cf 100644 --- a/core/src/main/scala/chisel3/Data.scala +++ b/core/src/main/scala/chisel3/Data.scala @@ -908,7 +908,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) { @@ -932,7 +933,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 61ae2951e28..ce1cca94f87 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(