From fd53af8642237998e23456a3fd1648ac84607db0 Mon Sep 17 00:00:00 2001 From: Wesley W. Terpstra Date: Wed, 1 Jun 2016 16:09:20 -0700 Subject: Fix a fairly serious bug whereby Vec's could incorrectly compare as equal (#204) * chiselTests: include an example of two empty Vectors killing FIRRTL * Aggregate: fix a bug whereby Vec[T] was using equals/hashCode of Seq In Chisel, two vectors are NOT equal just if their contents are equal. For example, two empty vectors should not be considered equal. This patch makes Vec use the HasId._id for equality like other Chisel types. Without this fix, Bundle.namedElts.seen: HashSet[Data]() will eliminate one of the named vectors and emit bad IR. --- chiselFrontend/src/main/scala/Chisel/Aggregate.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'chiselFrontend/src') diff --git a/chiselFrontend/src/main/scala/Chisel/Aggregate.scala b/chiselFrontend/src/main/scala/Chisel/Aggregate.scala index 197135d7..1eef5d69 100644 --- a/chiselFrontend/src/main/scala/Chisel/Aggregate.scala +++ b/chiselFrontend/src/main/scala/Chisel/Aggregate.scala @@ -174,9 +174,13 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int) /** A trait for [[Vec]]s containing common hardware generators for collection * operations. */ -trait VecLike[T <: Data] extends collection.IndexedSeq[T] { +trait VecLike[T <: Data] extends collection.IndexedSeq[T] with HasId { def apply(idx: UInt): T + // IndexedSeq has its own hashCode/equals that we must not use + override def hashCode: Int = super[HasId].hashCode + override def equals(that: Any): Boolean = super[HasId].equals(that) + @deprecated("Use Vec.apply instead", "chisel3") def read(idx: UInt): T -- cgit v1.2.3