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

Add isOneOf method to ChiselEnum #1966

Merged
merged 6 commits into from
Jul 8, 2021
Merged

Conversation

chiplet
Copy link
Contributor

@chiplet chiplet commented Jun 18, 2021

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

  • new feature/API

API Impact

  • Adds user-facing isOneOf method to ChiselEnum value type (EnumType).

Backend Code Generation Impact

  • No impact

Desired Merge Strategy

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

Release Notes

  • Added isOneOf method to ChiselEnum to reduce boilerplate when checking if the current value is in a set of given values.

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?

@CLAassistant
Copy link

CLAassistant commented Jun 18, 2021

CLA assistant check
All committers have signed the CLA.

@ekiwi
Copy link
Contributor

ekiwi commented Jun 18, 2021

This is a great start and thanks for picking up this issue, @chiplet !

The next step would be to add some tests for the new method here: https://github.com/chipsalliance/chisel3/blob/master/src/test/scala/chiselTests/StrongEnum.scala

If you are using IntelliJ, you should see a green arrow next to each test that lets you run it. If you are using sbt directly, the sbt testOnly command can be used to execute individual tests. In you case something like: sbt testOnly chiselTests.StrongEnumSpec should execute all tests in the StrongEnumSpec class.

Please let me know if you have any questions. And please let me know if you need me to run the continuous integration tests. Github now requires us to give first-time contributors the OK to run CI tests. Apparently they had some problems with people mining bitcoins :(

@chiplet
Copy link
Contributor Author

chiplet commented Jul 6, 2021

I've now added a test for the new method. The most use cases should be covered, but I'm not sure about how isOneOf should behave with the non increasing enum example found in the tests.

object NonIncreasingEnum extends ChiselEnum {
   val x = Value(2.U)
   val y = Value(2.U)
}

Should NonIncreasingEnum.x.isOneOf(NonIncreasingEnum.y) evaluate to true or false?

@ekiwi You could try running the CI tests now 👍

@chiplet
Copy link
Contributor Author

chiplet commented Jul 6, 2021

When starting to develop the tests I forgot the stop() call which resulted in the tester creating around 1.5GB large dump.vcd file under test_run_dir for each run. Should there be e.g. some sort of a timeout to prevent this?

Copy link
Contributor

@mwachs5 mwachs5 left a comment

Choose a reason for hiding this comment

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

can you add some description of this to the website docs for ChiselEnum?

@ekiwi
Copy link
Contributor

ekiwi commented Jul 6, 2021

Should NonIncreasingEnum.x.isOneOf(NonIncreasingEnum.y) evaluate to true or false?

I think it should be true.

They way to think about this, is that x and y are aliases and thus it should be possible to use them interchangeably.

@chiplet
Copy link
Contributor Author

chiplet commented Jul 7, 2021

Should NonIncreasingEnum.x.isOneOf(NonIncreasingEnum.y) evaluate to true or false?

I think it should be true.

They way to think about this, is that x and y are aliases and thus it should be possible to use them interchangeably.

Upon closer inspection there's a test that disallows instantiating non-increasing enums so NonIncreasingEnum.x.isOneOf(NonIncreasingEnum.y) doesn't even compile.

@chiplet
Copy link
Contributor Author

chiplet commented Jul 7, 2021

can you add some description of this to the website docs for ChiselEnum?

You mean in this file /docs/src/explanations/chisel-enum.md right?

I think currently the ChiselEnum naming and organization are quite confusing. I've seen the names StrongEnum, ChiselEnum and EnumFactory floating around and it was very unclear to me where to find the documentation for ChiselEnum when I was starting to use it. For example, when trying to search for ChiselEnum the API docs (like this) there are currently no results. The same applies when searching for StrongEnum. EnumFactory is the only class that can be found from the API doc, but even it doesn't contain any scaladoc comments. Maybe it's worth opening a new issue regarding this.

@ekiwi
Copy link
Contributor

ekiwi commented Jul 7, 2021

Maybe it's worth opening a new issue regarding this.

I think the only thing that needs to be solved in this issue regarding documentation would be to add some simple javadoc comment to the two methods. (/** this method does ... */).

Besides that it would be great if you could rebase your commit on the latest master branch and resolve any conflicts.

Looking good!

@chiplet chiplet changed the title WIP: Add isOneOf method to ChiselEnum Add isOneOf method to ChiselEnum Jul 8, 2021
@chiplet
Copy link
Contributor Author

chiplet commented Jul 8, 2021

I've added the related documentation and rebased to latest upstream commit so AFAIK this should be ready to merge.

@chiplet chiplet marked this pull request as ready for review July 8, 2021 12:15
Copy link
Contributor

@ekiwi ekiwi left a comment

Choose a reason for hiding this comment

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

This is an awesome first contribution! 🚢

It will be auto-merged once the CI passes. Thanks!

@ekiwi ekiwi added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Jul 8, 2021
@ekiwi ekiwi added this to the 3.4.x milestone Jul 8, 2021
@mergify mergify bot merged commit bb520b8 into chipsalliance:master Jul 8, 2021
mergify bot pushed a commit that referenced this pull request Jul 8, 2021
* Add @ekiwi's code as a starting point

* Add test for ChiselEnum isOneOf method

* Make isOneOfTester naming consistent with other testers

* Add scaladoc comments for isOneOf

* Add isOneOf tests that use the method that takes variable number of args

* Add guide level documentation example for isOneOf

(cherry picked from commit bb520b8)
@mergify mergify bot added the Backported This PR has been backported label Jul 8, 2021
@chiplet chiplet deleted the is-one-of branch July 8, 2021 16:05
mergify bot added a commit that referenced this pull request Jul 9, 2021
* Add `isOneOf` method to `ChiselEnum` (#1966)

* Add @ekiwi's code as a starting point

* Add test for ChiselEnum isOneOf method

* Make isOneOfTester naming consistent with other testers

* Add scaladoc comments for isOneOf

* Add isOneOf tests that use the method that takes variable number of args

* Add guide level documentation example for isOneOf

(cherry picked from commit bb520b8)

* Turn on autoclonetype2 for mdocs

Co-authored-by: Verneri Hirvonen <11316555+chiplet@users.noreply.github.com>
Co-authored-by: Jack Koenig <koenig@sifive.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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 Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants