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

Fix ChiselEnum warnings and use Logger for warnings instead of println #1999

Merged
merged 3 commits into from
Jul 2, 2021

Conversation

jackkoenig
Copy link
Contributor

@jackkoenig jackkoenig commented Jul 1, 2021

Add ChiselEnum.safe factory method and avoid warning

Previously, ChiselEnum would warn any time a UInt is converted to an
Enum. There was no way to suppress this warning. Now there is a factory
method (.safe) that does not warn and returns (Enum, Bool) where the
Bool is the result of calling .isValid on an Enum object. The regular
UInt cast is also now smarter and will not warn if all bitvectors of the
width of the Enum are legal states.

I also added a useful testing utility to capture Logging information

I need to update the mdoc to include this information (and a few stylistic changes), will push another commit with that.

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 state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • bug fix
  • new feature/API

API Impact

Adds ChiselEnum.safe for safely casting from UInt to an Enum

Backend Code Generation Impact

No impact

Desired Merge Strategy

  • Rebase

Release Notes

Stop warning when casting from UInt to a ChiselEnum if all bitvectors of the given width are legal states. Also provide ChiselEnum.safe for safely casting from UInt to an enum if some states are illegal.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (3.2.x, 3.3.x, 3.4.x, 3.5.0) ?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

It also uses the same logger as the Builder so that if we ever refactor
that to be passed as an argument, it will be the same logger for both
Builder and warning reporting.
@jackkoenig jackkoenig added this to the 3.2.x milestone Jul 1, 2021
core/src/main/scala/chisel3/StrongEnum.scala Outdated Show resolved Hide resolved
core/src/main/scala/chisel3/StrongEnum.scala Outdated Show resolved Hide resolved
* @param n the UInt to cast
* @return the equivalent Enum to the value of the cast UInt
*/
def apply(n: UInt)(implicit sourceInfo: SourceInfo, connectionCompileOptions: CompileOptions): Type = castImpl(n, warn = true)
Copy link
Member

Choose a reason for hiding this comment

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

I like the clear use of warn = true. 👍

deprecations.foreach { case ((message, sourceLoc), count) =>
println(s"${ErrorLog.depTag} $sourceLoc ($count calls): $message")
logger.warn(s"${ErrorLog.depTag} $sourceLoc ($count calls): $message")
Copy link
Member

Choose a reason for hiding this comment

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

❤️ ❤️ ❤️

Previously, ChiselEnum would warn any time a UInt is converted to an
Enum. There was no way to suppress this warning. Now there is a factory
method (`.safe`) that does not warn and returns (Enum, Bool) where the
Bool is the result of calling .isValid on an Enum object. The regular
UInt cast is also now smarter and will not warn if all bitvectors of the
width of the Enum are legal states.
@jackkoenig
Copy link
Contributor Author

I pushed some docs updates too.

@jackkoenig jackkoenig merged commit 4b7499f into master Jul 2, 2021
@mergify mergify bot added the Backported This PR has been backported label Jul 2, 2021
@jackkoenig jackkoenig deleted the fix-chiselenum-warnings branch July 6, 2021 23:21
mergify bot added a commit that referenced this pull request Jul 7, 2021
…n (backport #1999) (#2002)

* Change Chisel warnings to use logger instead of println

It also uses the same logger as the Builder so that if we ever refactor
that to be passed as an argument, it will be the same logger for both
Builder and warning reporting.

(cherry picked from commit 04caf39)

* Add ChiselEnum.safe factory method and avoid warning

Previously, ChiselEnum would warn any time a UInt is converted to an
Enum. There was no way to suppress this warning. Now there is a factory
method (`.safe`) that does not warn and returns (Enum, Bool) where the
Bool is the result of calling .isValid on an Enum object. The regular
UInt cast is also now smarter and will not warn if all bitvectors of the
width of the Enum are legal states.

(cherry picked from commit 5fe539c)

# Conflicts:
#	src/test/scala/chiselTests/ChiselSpec.scala

* Update docs for ChiselEnum

(cherry picked from commit bfb77d4)

* Resolve merge conflicts and waive false bincompat issue

Co-authored-by: Jack Koenig <koenig@sifive.com>
jackkoenig added a commit that referenced this pull request Feb 28, 2023
sbt-ci-release changes the commands required to publish to Sonatype.
While this may be a desirable change at some point, it is inconsistent
with other repos. Reverting for the time being.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported This PR has been backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants