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 Node objects between siblings (backport #4259) #4272

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ lazy val unipublish =
ProblemFilters.exclude[DirectMissingMethodProblem]("chisel3.*.hasAutoSeed"),
// _circuit was package private
ProblemFilters.exclude[DirectMissingMethodProblem]("chisel3.*._circuit"),
ProblemFilters.exclude[DirectMissingMethodProblem]("chisel3.*._circuit_=")
ProblemFilters.exclude[DirectMissingMethodProblem]("chisel3.*._circuit_="),
// setRef was package private
ProblemFilters.exclude[IncompatibleMethTypeProblem]("chisel3.*.setRef")
),
// Forward doc command to unidoc
Compile / doc := (ScalaUnidoc / doc).value,
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/scala/chisel3/Aggregate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ sealed class Vec[T <: Data] private[chisel3] (gen: => T, val length: Int) extend
// simpler.
private lazy val self: Seq[T] = {
val _self = Vector.fill(length)(gen)
val thisNode = Node(this) // Share the same Node for all elements.
for ((elt, i) <- _self.zipWithIndex)
elt.setRef(this, i)
elt.setRef(thisNode, i)
_self
}

Expand Down Expand Up @@ -382,7 +383,7 @@ sealed class Vec[T <: Data] private[chisel3] (gen: => T, val length: Int) extend
port.bind(ChildBinding(this), reconstructedResolvedDirection)

val i = Vec.truncateIndex(p, length)(UnlocatableSourceInfo)
port.setRef(this, i)
port.setRef(Node(this), i)

port
}
Expand Down Expand Up @@ -992,9 +993,10 @@ abstract class Record extends Aggregate {
!opaqueType || (_elements.size == 1 && _elements.head._1 == ""),
s"Opaque types must have exactly one element with an empty name, not ${_elements.size}: ${elements.keys.mkString(", ")}"
)
val thisNode = Node(this) // Share the same Node for all elements.
// Names of _elements have already been namespaced (and therefore sanitized)
for ((name, elt) <- _elements) {
elt.setRef(this, name, opaque = opaqueType)
elt.setRef(thisNode, name, opaque = opaqueType)
}
}

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
_refVar = imm
}
}
private[chisel3] def setRef(parent: HasId, name: String, opaque: Boolean = false): Unit = {
if (!opaque) setRef(Slot(Node(parent), name))
else setRef(OpaqueSlot(Node(parent)))
private[chisel3] def setRef(parent: Node, name: String, opaque: Boolean = false): Unit = {
if (!opaque) setRef(Slot(parent, name))
else setRef(OpaqueSlot(parent))
}

private[chisel3] def setRef(parent: HasId, index: Int): Unit = setRef(Index(Node(parent), ILit(index)))
private[chisel3] def setRef(parent: HasId, index: UInt): Unit = setRef(Index(Node(parent), index.ref))
private[chisel3] def setRef(parent: Node, index: Int): Unit = setRef(Index(parent, ILit(index)))
private[chisel3] def setRef(parent: Node, index: UInt): Unit = setRef(Index(parent, index.ref))
private[chisel3] def getRef: Arg = _ref.get
private[chisel3] def getOptionRef: Option[Arg] = _ref

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/chisel3/properties/Object.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.language.experimental.macros

import chisel3.{Module, RawModule, SpecifiedDirection}
import chisel3.experimental.{BaseModule, SourceInfo}
import chisel3.internal.firrtl.ir.{DefClass, DefObject}
import chisel3.internal.firrtl.ir.{DefClass, DefObject, Node}
import chisel3.internal.sourceinfo.InstTransform
import chisel3.internal.{throwException, Builder, HasId, NamedComponent, ObjectFieldBinding}

Expand Down Expand Up @@ -65,14 +65,14 @@ class DynamicObject private[chisel3] (val className: ClassType) extends HasId wi
*/
def getField[T](name: String)(implicit tpe: PropertyType[T]): Property[tpe.Type] = {
val field = Property[T]()
field.setRef(this, name)
field.setRef(Node(this), name)
field.bind(ObjectFieldBinding(_parent.get), SpecifiedDirection.Unspecified)
field
}

def getField[T](name: String, property: Property[T]): Property[T] = {
val field = property.cloneType
field.setRef(this, name)
field.setRef(Node(this), name)
field.bind(ObjectFieldBinding(_parent.get), SpecifiedDirection.Unspecified)
field
}
Expand Down
Loading