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

Make some usages of suggestName runtime deprecated #2556

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b6addc7
suggestName: add some runtime deprecations
mwachs5 Jun 2, 2022
08543f3
no more _computedName
mwachs5 Jun 19, 2022
236a4fd
post merge cleanups
mwachs5 Jun 19, 2022
eaedd38
Deleted a bunch of chiselName and TransitName to get tests to pass be…
mwachs5 Jun 19, 2022
87f0e41
Add back the check for suggestName after module close
mwachs5 Jun 24, 2022
f0d2499
Add another case that we can name IOs
mwachs5 Jun 24, 2022
a175c1d
scalafmt
mwachs5 Jun 24, 2022
aceaae4
scalafmt
mwachs5 Jun 27, 2022
3918123
Add back the @chiselName
mwachs5 Jun 28, 2022
dbb9078
SuggestNameSpec: use something other than Queue to avoid issues with …
mwachs5 Jun 28, 2022
cd07ede
I don't need to suggestName on clock/reset do I?
mwachs5 Jun 28, 2022
a0d145d
Revert "I don't need to suggestName on clock/reset do I?"
mwachs5 Jun 28, 2022
a8b296f
Update core/src/main/scala/chisel3/internal/Builder.scala
mwachs5 Jun 30, 2022
412a8d1
Arbiter restore chiselName
mwachs5 Jul 1, 2022
bbc0d0a
restore nowarn annotation in Decoupled, that should be deleted in a s…
mwachs5 Jul 1, 2022
d7a1782
Update core/src/main/scala/chisel3/internal/Builder.scala
mwachs5 Jul 1, 2022
898ae25
Update core/src/main/scala/chisel3/internal/Builder.scala
mwachs5 Jul 1, 2022
5f25d90
Update core/src/main/scala/chisel3/internal/Builder.scala
mwachs5 Jul 1, 2022
5a11980
Update core/src/main/scala/chisel3/internal/Builder.scala
mwachs5 Jul 1, 2022
0075c25
Update src/test/scala/chiselTests/naming/SuggestNameSpec.scala
mwachs5 Jul 1, 2022
7b84a38
Merge remote-tracking branch 'origin/suggest-name-errors' into sugges…
mwachs5 Jul 1, 2022
db9152f
checkpoint: one test fails
mwachs5 Jul 1, 2022
7cf0c42
scalafmt
mwachs5 Jul 1, 2022
ce18389
fix numbering
mwachs5 Jul 1, 2022
7158448
scalafmt
mwachs5 Jul 1, 2022
e60b9bd
get the builder context check to work
mwachs5 Jul 1, 2022
9772b29
scalafmt
mwachs5 Jul 1, 2022
67ce7d8
avoid any allocations in seedOpt check
mwachs5 Jul 1, 2022
fa28909
Merge branch 'master' into suggest-name-errors
mwachs5 Jul 2, 2022
47d88ce
Update core/src/main/scala/chisel3/internal/Builder.scala
mwachs5 Jul 2, 2022
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: 2 additions & 2 deletions core/src/main/scala/chisel3/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ object Module extends SourceInfoDoc {
*/
abstract class Module(implicit moduleCompileOptions: CompileOptions) extends RawModule {
// Implicit clock and reset pins
final val clock: Clock = IO(Input(Clock())).suggestName("clock")
final val reset: Reset = IO(Input(mkReset)).suggestName("reset")
final val clock: Clock = IO(Input(Clock()))._suggestNameInternal("clock")
final val reset: Reset = IO(Input(mkReset))._suggestNameInternal("reset")
mwachs5 marked this conversation as resolved.
Show resolved Hide resolved

// TODO It's hard to remove these deprecated override methods because they're used by
// Chisel.QueueCompatibility which extends chisel3.Queue which extends chisel3.Module
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/experimental/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ package object experimental {
gen.elements.toSeq.reverse.map {
case (name, data) =>
val p = IO(coerceDirection(chiselTypeClone(data).asInstanceOf[Data]))
p.suggestName(name)
p._suggestNameInternal(name)
p

}
Expand Down
79 changes: 61 additions & 18 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,42 @@ private[chisel3] trait HasId extends InstanceId {
this
}

// Private internal version of suggestName that tells you if the name changed
// Returns Some(old name, old prefix) if name changed, None otherwise
private[chisel3] def _suggestNameCheck(seed: => String): Option[(String, Prefix)] = {
val oldSeed = this.seedOpt
val oldPrefix = this.naming_prefix
suggestName(seed)
if (oldSeed.nonEmpty && (oldSeed != this.seedOpt || oldPrefix != this.naming_prefix)) {
Some(oldSeed.get -> oldPrefix)
} else None
}

/** Takes the first seed suggested. Multiple calls to this function will be ignored.
def _suggestNameInternal(seed: => String): this.type = {
if (suggested_seed.isEmpty) suggested_seed = Some(seed)
naming_prefix = Builder.getPrefix
this
}

/** Takes the first seed suggested. Multiple calls to this function will be ignored (and will become an error in future).
* If the final computed name conflicts with another name, it may get uniquified by appending
* a digit at the end.
*
* Is a higher priority than [[autoSeed]], in that regardless of whether [[autoSeed]]
* was called, [[suggestName]] will always take precedence.
*
* @note calling this after the name has already been computed will become an error in the future.
*
* @param seed The seed for the name of this component
* @return this object
*/
def suggestName(seed: => String): this.type = {
if (suggested_seed.isEmpty) suggested_seed = Some(seed)
naming_prefix = Builder.getPrefix
this
require(Builder.hasDynamicContext, s"suggestName (${seed}) should only be called from a Builder context.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should also be a deprecation rather than error (for purposes of backporting to 3.5.x). It currently just silently does nothing: https://scastie.scala-lang.org/nfiyNDBaSJWx4GKY4cxxOg

Copy link
Contributor Author

@mwachs5 mwachs5 Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i thought I had a unit test for this error case so I am surprised it silently does nothing: https://github.com/chipsalliance/chisel3/pull/2556/files#diff-9155256ee3cccc6b7e3ad38ee0a25473c9fd3296beb5bc9f1f59cb658522db50R52

this case says it does do something, at least in my case...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I will make it a deprecation error, but still confused about why you say it silently does nothing given the test for it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, by currently I mean in Chisel 3.5.3 it does nothing (see my Scastie). I'm saying it should be a warning in 3.5.4 and an error in 3.6.0.

if (suggested_seed.isDefined) {
Builder.deprecated(
s"Calling .suggestName(\"$seed\"), when already called with \"${suggested_seed.get}\", will become an error in Chisel 3.6"
)
}
if (!HasId.canBeNamed(this)) {
Builder.deprecated(
s"Calling .suggestName(\"$seed\") on \"$this\" (which cannot actually be named) will become an error in Chisel 3.6"
)
}
if (_parent.map(_.isClosed).getOrElse(false)) { // not sure what it means to have no parent
mwachs5 marked this conversation as resolved.
Show resolved Hide resolved
Builder.deprecated(
s"Calling .suggestName(\"$seed\") on ${this} when the containing module \"${_parent.get.name}\" has already completed elaboration will become an error in Chisel 3.6"
)
}
_suggestNameInternal(seed)
}

// Internal version of .suggestName that can override a user-suggested name
Expand All @@ -163,11 +174,12 @@ private[chisel3] trait HasId extends InstanceId {
// This could be called with user prefixes, ignore them
noPrefix {
suggested_seed = Some(seed)
this.suggestName(seed)
this._suggestNameInternal(seed)
}
}

/** Computes the name of this HasId, if one exists
*
* @param defaultSeed Optionally provide default seed for computing the name
* @return the name, if it can be computed
*/
Expand All @@ -178,10 +190,22 @@ private[chisel3] trait HasId extends InstanceId {
}

/** This resolves the precedence of [[autoSeed]] and [[suggestName]]
*
* @note It will become an error in the future to suggestName the same thing that autoSeed would have assigned
*
* @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.zip(auto_seed).foreach {
case (suggested, auto) =>
if (suggested == auto) {
mwachs5 marked this conversation as resolved.
Show resolved Hide resolved
Builder.deprecated(
s"calling .suggestName(\"${suggested}\") had no effect as it is the same as the automatically given name, this will become an error in 3.6"
)
}
}
suggested_seed.orElse(auto_seed)
}

/** @return Whether either autoName or suggestName has been called */
def hasSeed: Boolean = seedOpt.isDefined
Expand Down Expand Up @@ -268,7 +292,26 @@ private[chisel3] trait HasId extends InstanceId {
}
}

/** Holds the implementation of toNamed for Data and MemBase */
private[chisel3] object HasId {

/** Utility for things that (currently) appear to be nameable but actually cannot be */
private def canBeNamed(id: HasId): Boolean = id match {
case d: Data =>
d.binding match {
case Some(_: ConstrainedBinding) => true
case _ => false
}
case b: BaseModule => true
case m: MemBase[_] => true
// These names don't affect hardware
case _: VerificationStatement => false
// While the above should be comprehensive, since this is used in warning we want to be careful
// to never accidentally have a match error
case _ => false
}
}

/** Holds the implementation of to for Data and MemBase */
mwachs5 marked this conversation as resolved.
Show resolved Hide resolved
private[chisel3] trait NamedComponent extends HasId {

/** Returns a FIRRTL ComponentName that references this object
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/internal/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class NamingContext extends NamingContextInterface {
closed = true
for ((ref, suffix) <- items) {
// First name the top-level object
chisel3.internal.Builder.nameRecursively(prefix + suffix, ref, (id, name) => id.suggestName(name))
chisel3.internal.Builder.nameRecursively(prefix + suffix, ref, (id, name) => id._suggestNameInternal(name))

// Then recurse into descendant contexts
if (descendants.containsKey(ref)) {
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/chisel3/util/Arbiter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class RRArbiter[T <: Data](val gen: T, val n: Int) extends LockingRRArbiter[T](g
* consumer.io.in <> arb.io.out
* }}}
*/
@chiselName
mwachs5 marked this conversation as resolved.
Show resolved Hide resolved
class Arbiter[T <: Data](val gen: T, val n: Int) extends Module {
val io = IO(new ArbiterIO(gen, n))

Expand Down
1 change: 0 additions & 1 deletion src/main/scala/chisel3/util/Decoupled.scala
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ object Queue {
* consumer.io.in <> Queue(producer.io.out, 16)
* }}}
*/
@nowarn("cat=deprecation&msg=TransitName")
mwachs5 marked this conversation as resolved.
Show resolved Hide resolved
@chiselName
def apply[T <: Data](
enq: ReadyValidIO[T],
Expand Down
Loading