Skip to content

Commit

Permalink
Share ChildBinding objects between siblings (#4238)
Browse files Browse the repository at this point in the history
(cherry picked from commit d499a88)
  • Loading branch information
jackkoenig authored and mergify[bot] committed Jul 2, 2024
1 parent 0938828 commit e088499
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core/src/main/scala/chisel3/Aggregate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ sealed class Vec[T <: Data] private[chisel3] (gen: => T, val length: Int) extend

val resolvedDirection = SpecifiedDirection.fromParent(parentDirection, specifiedDirection)
sample_element.bind(SampleElementBinding(this), resolvedDirection)
// Share same object for binding of all children.
val childBinding = ChildBinding(this)
for (child <- elementsIterator) { // assume that all children are the same
child.bind(ChildBinding(this), resolvedDirection)
child.bind(childBinding, resolvedDirection)
}

// Since all children are the same, we can just use the sample_element rather than all children
Expand Down Expand Up @@ -1065,18 +1067,20 @@ abstract class Record extends Aggregate {

checkForAndReportDuplicates()

// This check is for making sure that elements always returns the
// same object, which will not be the case if the user makes it a
// def inside the Record. Checking elementsIterator against itself
// is not useful for this check because it's a lazy val which will
// always return the same thing.
// Share same object for binding of all children.
val childBinding = ChildBinding(this)
for (((_, child), sameChild) <- this.elements.iterator.zip(this.elementsIterator)) {
// This check is for making sure that elements always returns the
// same object, which will not be the case if the user makes it a
// def inside the Record. Checking elementsIterator against itself
// is not useful for this check because it's a lazy val which will
// always return the same thing.
if (child != sameChild) {
throwException(
s"${this.className} does not return the same objects when calling .elements multiple times. Did you make it a def by mistake?"
)
}
child.bind(ChildBinding(this), resolvedDirection)
child.bind(childBinding, resolvedDirection)

// Update the flipped tracker based on the flipped-ness of this specific child element
_containsAFlipped |= child.containsAFlipped
Expand Down

0 comments on commit e088499

Please sign in to comment.