Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share ChildBinding objects between siblings #4238

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -215,8 +215,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 @@ -1066,18 +1068,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