diff --git a/build.sbt b/build.sbt index b156ca175c5..b72a4b6e918 100644 --- a/build.sbt +++ b/build.sbt @@ -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_=") diff --git a/core/src/main/scala/chisel3/Data.scala b/core/src/main/scala/chisel3/Data.scala index 96e8d50af3c..5ba8d2067be 100644 --- a/core/src/main/scala/chisel3/Data.scala +++ b/core/src/main/scala/chisel3/Data.scala @@ -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) } } diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala index ab3c01cb863..f36a40905b3 100644 --- a/core/src/main/scala/chisel3/internal/Builder.scala +++ b/core/src/main/scala/chisel3/internal/Builder.scala @@ -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 @@ -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 } @@ -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 } @@ -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)