Skip to content

Conversation

@CSharperMantle
Copy link
Contributor

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • Feature (or new API)

Desired Merge Strategy

  • Squash: The PR will be squashed and merged (choose this if you have no preference).

Release Notes

The inferred width for a ChiselEnum using Value() now correctly accommodates both known-width values and the largest specified literal integer. Closes #4989.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels? (Select the most appropriate one based on the "Type of Improvement")
  • Did you mark the proper milestone (Bug fix: 3.6.x, 5.x, or 6.x depending on impact, API modification or big change: 7.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you do one of the following when ready to merge:
    • Squash: You/ the contributor Enable auto-merge (squash) and clean up the commit message.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@seldridge seldridge added the Bugfix Fixes a bug, will be included in release notes label Jul 25, 2025
@seldridge seldridge requested a review from jackkoenig July 25, 2025 16:28
Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

This isn't related to this PR, mostly a note to myself and @seldridge, but I noticed while reviewing:

You can still observe the smaller widths if you access them during the construction of the Enum object, e.g.

  object EnumWithKnownWidth extends ChiselEnum {
    val Member0 = Value(0.U(1.W))
    println(Member0.getWith)       // 1
    val Member1 = Value(1.U(2.W))
    println(Member0.getWith)       // 2
    val Member2 = Value(2.U(3.W))
    println(Member0.getWith)       // 3
    val Member3 = Value(3.U(4.W))
    println(Member0.getWith)       // 4

This is a bit of a footgun but probably not that big of a deal in the grand scheme. It's not possible to give the right answer early on, maybe we could error but that would require being able to detect when the object is done being constructed which might be possible with runtime reflection. Unsure.

@jackkoenig jackkoenig merged commit 6b7d034 into chipsalliance:main Jul 25, 2025
17 of 18 checks passed
@jackkoenig
Copy link
Contributor

Thank you @CSharperMantle!

@CSharperMantle
Copy link
Contributor Author

CSharperMantle commented Jul 26, 2025

You can still observe the smaller widths if you access them during the construction of the Enum object [...]

I think the original implementation of ChiselEnum before this patch also behaves like this. Its width grows during its constructor as new members with longer bit length are added.

So I guess a FIRRTL-level construct would be preferrable in terms of both aesthetics and "atomicity" like this.

CSharperMantle added a commit to untitl3d-la/untitl3d that referenced this pull request Jul 28, 2025
CSharperMantle added a commit to untitl3d-la/untitl3d that referenced this pull request Jul 28, 2025
woshiluo pushed a commit to untitl3d-la/untitl3d that referenced this pull request Jul 28, 2025
@jackkoenig jackkoenig added API Modification and removed Bugfix Fixes a bug, will be included in release notes labels Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect user-specified widths in ChiselEnum

3 participants