-
Notifications
You must be signed in to change notification settings - Fork 614
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
Refine autonaming to have more intuitive behavior #1660
Conversation
Last name in an Expression wins, while the first Statement to name wins. This is done via checking the _id of HasIds during autonaming and only applying a name if the HasId was created in the scope of autonaming. There is no change to .autoSeed or .suggestName behavior. Behavior of chisel3-plugins from before this change is maintained.
👍 for the algorithm/behavior as documented in the comments |
Marked |
In a randomish sampling, I found this behavior to be correct. In some cases a temporary name would get overridden to a better, non-temporary name; however, it could also result in overriding names in a bad way. For example: class Example extends MultiIOModule {
def extractBelow(from: UInt, idx: Int): UInt = {
val x = from
x(idx, 0)
}
val in = IO(Input(UInt(16.W)))
val out = IO(Output(UInt(16.W)))
// If foo is a field of Example, reflective naming hides the bug
if (true) {
val foo = Reg(UInt(16.W))
foo := in
out := extractBelow(foo, 15)
}
} With v3.4.0 gives:
(Scastie: https://scastie.scala-lang.org/T6mdGw3LQOSNc2yEyUMy5w) See how the class Example extends MultiIOModule {
def extractBelow(from: UInt, idx: Int): UInt = {
val x = from
x(idx, 0)
}
val in = IO(Input(UInt(16.W)))
val out = IO(Output(UInt(16.W)))
// If foo is a field of Example, reflective naming hides the bug
if (true) {
val foo = Reg(UInt(16.W))
foo := in
out := extractBelow(foo +& 1.U, 15) // <---- difference here
}
} With v3.4.0 gives:
(Scastie: https://scastie.scala-lang.org/3FoJCFOmRUK5iYteYkkvjg) In this case, it's nice that the sum gets the name
The loss of |
@azidar I've done an initial updating of the docs, but I have not yet added a description of "Outer Expression, First Statement". I would appreciate review of the code and tests while I finish up the docs. |
private [chisel3] def autoSeed(seed: String): this.type = { | ||
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 = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the plan to remove autoseed in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, a good question for the dev meeting
val tpe = inferType(tpt) | ||
val fieldsOfInterest: List[Boolean] = tpe.typeArgs.map(shouldMatchData) | ||
// Only transform if at least one field is of interest | ||
if (fieldsOfInterest.reduce(_ || _)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this never empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If none of the fields are <: Data
then it will be empty, eg.
val (a, b) = ("hi", 3)
* Refine autonaming to have more intuitive behavior Last name in an Expression wins, while the first Statement to name wins. This is done via checking the _id of HasIds during autonaming and only applying a name if the HasId was created in the scope of autonaming. There is no change to .autoSeed or .suggestName behavior. Behavior of chisel3-plugins from before this change is maintained. * Update docs with naming plugin changes (cherry picked from commit 1260f7c)
* Refine autonaming to have more intuitive behavior (#1660) * Refine autonaming to have more intuitive behavior Last name in an Expression wins, while the first Statement to name wins. This is done via checking the _id of HasIds during autonaming and only applying a name if the HasId was created in the scope of autonaming. There is no change to .autoSeed or .suggestName behavior. Behavior of chisel3-plugins from before this change is maintained. * Update docs with naming plugin changes (cherry picked from commit 1260f7c) * Waive binary incompatibility false positive in 2.11 Co-authored-by: Jack Koenig <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Last name in an Expression wins, while the first Statement to name wins.
This is done via checking the _id of HasIds during autonaming and only
applying a name if the HasId was created in the scope of autonaming.
There is no change to
.autoSeed
or.suggestName
behavior.Behavior of chisel3-plugins from before this change is maintained. More precisely, assuming this PR is released with Chisel v3.4.1, if you use Chisel v3.4.1 with the v3.4.0 (or v3.4.0-RC3) plugin, you'll get the v3.4.0 behavior.
The bulk of the work here was making
unapply
continue to work because it previously worked via overriding names. Now, a signal will only be named byautoNameRecursively
orautoNameRecursivelyProduct
calls that wrap theExpression
within which theData
is created.Fixes #1603
Contributor Checklist
docs/src
?Type of Improvement
API Impact
This changes the naming behavior to what I've been calling "Outer Expression, First Statement" wins. For example:
Intuitively, the name of this port should be
debug
. It is useful that things built within the anonymous function should havedebug
as a prefix in addition to their val name (eg.debug_delay
), but becausefoo
is returned, the outer name should win (debug
). It is also intuitive thatdebug
wins overbar
sincedebug
is the name of the declaration rather than an alias.Prior to this PR, the port would be named
debug_foo
and if it were a non-port, it would be namedbar
. This PR unifies the behavior of ports and non-ports into what is (in my opinion) more intuitive.Backend Code Generation Impact
Change in naming algorithm
Desired Merge Strategy
Release Notes
Change naming priority to "Outer Expression, First Statement"
Reviewer Checklist (only modified by reviewer)
Please Merge
?