Skip to content

add curried MuxLookup.apply, deprecate old apply#3095

Merged
jackkoenig merged 5 commits intomainfrom
better-mux-lookup
Mar 17, 2023
Merged

add curried MuxLookup.apply, deprecate old apply#3095
jackkoenig merged 5 commits intomainfrom
better-mux-lookup

Conversation

@albertchen-sifive
Copy link
Contributor

fixes #2780

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

deprecates the current MuxLookup.apply and adds two overloads which behave the same as the old MuxLookup.apply but take two parameter lists instead. MuxLookup.fromEnum is replaced with the new MuxLookup.apply.

Backend Code Generation Impact

none, but should generate better source locators for MuxLookup.apply

Desired Merge Strategy

Squash

Release Notes

Add a new version of MuxLookup.apply that takes two parameter lists instead of one. This helps the scala compiler report better type errors.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (Bug fix: 3.5.x or 3.6.x depending on impact, API modification or big change: 5.0.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), clean up the commit message, and label with Please Merge.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

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.

Are you intentionally relaxing the constraint that the enumerated should all be of the same type?

assert(MuxLookup.fromEnum(TestEnum.c, 3.U)(incompleteMapping) === 2.U)
assert(MuxLookup(TestEnum.a, 3.U)(incompleteMapping) === 0.U)
assert(MuxLookup(TestEnum.b, 3.U)(incompleteMapping) === 3.U)
assert(MuxLookup(TestEnum.c, 3.U)(incompleteMapping) === 2.U)
Copy link
Contributor

Choose a reason for hiding this comment

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

Like a case where I define anotherEnum I should not be able to put AnotherEnum.c in for the default or any of the cases, I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed--we really need a testing flow for negative compile tests...

I have a prototype of the build flow to make this work, but we need some pithy way to express what we expect. Either a standalone FileCheck, a simpler custom similar thing, or perhaps Linux expect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ScalaTest has something similar, but macros don't work super well because they aren't full separate invocations of the compiler and thus can't take into account differing compile options

@jackkoenig
Copy link
Contributor

Since this deletes an API add in #3071 and that was backported to 3.6.x and 3.5.x, we need to backport this. As is, this won't be binary compatible because of the change to the deprecated apply method, but that can be fixed in the 3.5.x backport (we can just remove the use of the macro and it won't have a good source locator--it's fine).

@jackkoenig jackkoenig added this to the 3.5.x milestone Mar 17, 2023
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! Nice!

@jackkoenig jackkoenig enabled auto-merge (squash) March 17, 2023 05:25
@jackkoenig jackkoenig added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Mar 17, 2023
@jackkoenig
Copy link
Contributor

I pushed a commit that makes sure the do_ methods are properly segregated in the ScalaDoc to make it cleaner.

@jackkoenig jackkoenig mentioned this pull request Mar 17, 2023
16 tasks
@jackkoenig jackkoenig merged commit dcecabb into main Mar 17, 2023
@jackkoenig jackkoenig deleted the better-mux-lookup branch March 17, 2023 06:58
@mergify mergify bot added the Backported This PR has been backported label Mar 17, 2023
mergify bot pushed a commit that referenced this pull request Mar 17, 2023
* overload MuxLookup.apply for EnumType
* remove MuxLookup.fromEnum
* add source locators to MuxLookup.apply using macros

(cherry picked from commit dcecabb)
mergify bot pushed a commit that referenced this pull request Mar 17, 2023
* overload MuxLookup.apply for EnumType
* remove MuxLookup.fromEnum
* add source locators to MuxLookup.apply using macros

(cherry picked from commit dcecabb)
mergify bot added a commit that referenced this pull request Mar 17, 2023
* overload MuxLookup.apply for EnumType
* remove MuxLookup.fromEnum
* add source locators to MuxLookup.apply using macros

(cherry picked from commit dcecabb)

Co-authored-by: Albert Chen <40366337+albertchen-sifive@users.noreply.github.com>
mergify bot added a commit that referenced this pull request Mar 17, 2023
)

* add curried MuxLookup.apply, deprecate old apply (#3095)

* overload MuxLookup.apply for EnumType
* remove MuxLookup.fromEnum
* add source locators to MuxLookup.apply using macros

(cherry picked from commit dcecabb)

* remove deprecated annotation, remove macro

---------

Co-authored-by: Albert Chen <40366337+albertchen-sifive@users.noreply.github.com>
Co-authored-by: Albert Chen <albert.chen@sifive.com>
@jackkoenig jackkoenig added the Feature New feature, will be included in release notes label Apr 7, 2023
@sequencer sequencer mentioned this pull request Jun 20, 2023
14 tasks
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 Feature New feature, will be included in release notes 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.

Improve MuxLookup's type declaration to get better type errors

3 participants