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

Remove autoSeedVar, use Boolean to distinguish suggested or autoSeed (backport #4252) #4262

Merged
merged 4 commits into from
Jul 10, 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
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ lazy val unipublish =
ProblemFilters.exclude[ReversedMissingMethodProblem]("chisel3.internal.firrtl.ir#LitArg.cloneWithValue"),
// chisel3.Bits is sealed
ProblemFilters.exclude[ReversedMissingMethodProblem]("chisel3.Bits._padLit"),
// hasAutoSeed was package private
ProblemFilters.exclude[DirectMissingMethodProblem]("chisel3.*.hasAutoSeed"),
// _circuit was package private
ProblemFilters.exclude[DirectMissingMethodProblem]("chisel3.*._circuit"),
ProblemFilters.exclude[DirectMissingMethodProblem]("chisel3.*._circuit_=")
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/chisel3/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ abstract class Data extends HasId with NamedComponent with SourceInfoDoc {
override def autoSeed(name: String): this.type = {
topBindingOpt match {
// Ports are special in that the autoSeed will keep the first name, not the last name
case Some(PortBinding(m)) if hasAutoSeed && Builder.currentModule.contains(m) => this
case _ => super.autoSeed(name)
case Some(PortBinding(m)) if hasSeed && Builder.currentModule.contains(m) => this
case _ => super.autoSeed(name)
}
}

Expand Down
20 changes: 10 additions & 10 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,16 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
override def hashCode: Int = super.hashCode()
override def equals(that: Any): Boolean = super.equals(that)

// Contains suggested seed (user-decided seed)
// Did the user suggest a name? This overrides names suggested by the compiler plugin.
private var _nameIsSuggested: Boolean = false
// Contains name seed (either user suggested or generated by the plugin).
private var suggested_seedVar: String = null // using nullable var for better memory usage
private def suggested_seed: Option[String] = Option(suggested_seedVar)

// Contains the seed computed automatically by the compiler plugin
private var auto_seedVar: String = null // using nullable var for better memory usage
private def auto_seed: Option[String] = Option(auto_seedVar)

// Prefix for use in naming
// - Defaults to prefix at time when object is created
// - Overridden when [[suggestSeed]] or [[autoSeed]] is called
// - Note that suggestSeed does *not* prevent autoSeed from changing this
private var naming_prefix: Prefix = Builder.getPrefix

/** Takes the last seed suggested. Multiple calls to this function will take the last given seed, unless
Expand All @@ -155,7 +154,9 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
private[chisel3] def autoSeed(seed: String): this.type = forceAutoSeed(seed)
// Bypass the overridden behavior of autoSeed in [[Data]], apply autoSeed even to ports
private[chisel3] def forceAutoSeed(seed: String): this.type = {
auto_seedVar = seed
if (!_nameIsSuggested) {
suggested_seedVar = seed
}
naming_prefix = Builder.getPrefix
this
}
Expand All @@ -182,10 +183,11 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
* @return this object
*/
def suggestName(seed: => String): this.type = {
if (suggested_seed.isEmpty) {
if (!_nameIsSuggested) {
suggested_seedVar = seed
// Only set the prefix if a seed hasn't been suggested
naming_prefix = Builder.getPrefix
_nameIsSuggested = true
}
this
}
Expand All @@ -204,13 +206,11 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
*
* @return the current calculation of a name, if it exists
*/
private[chisel3] def seedOpt: Option[String] = suggested_seed.orElse(auto_seed)
private[chisel3] def seedOpt: Option[String] = suggested_seed

/** @return Whether either autoName or suggestName has been called */
def hasSeed: Boolean = seedOpt.isDefined

private[chisel3] def hasAutoSeed: Boolean = auto_seed.isDefined

// Uses a namespace to convert suggestion into a true name
// Will not do any naming if the reference already assigned.
// (e.g. tried to suggest a name to part of a Record)
Expand Down
Loading