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

[Scala3] Redux: Convert cloneType to an extension method #4467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adkian-sifive
Copy link
Contributor

@adkian-sifive adkian-sifive commented Oct 15, 2024

Redux of #3771. Turns out we need this for Scala3 after all

Ran into errors related to this while adding Scala3 cross-compilation support. Here's a sample of what an error with Dotty looks like:

[error] -- [E007] Type Mismatch Error: chisel3/core/src/main/scala/chisel3/AggregateImpl.scala:838:4 
[error] 838 |    clone
[error]     |    ^^^^^
[error]     |    Found:    (clone : chisel3.Record & chisel3.RecordImpl)
[error]     |    Required: (RecordImpl.this : chisel3.Record & chisel3.RecordImpl)

I suspect this is due to the tightening of the type system in Scala3, specifically changes which make this.type a more stricter representation of the current instance. I think this SIP might have a more detailed specification of the related changes: https://docs.scala-lang.org/sips/42.type.html#related-scala-issues-resolved-by-the-literal-types-implementation

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

  • API Modification
  • Internal or build-related (includes code refactoring/cleanup)

Desired Merge Strategy

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

Release Notes

Move cloneType to an extension method in preparation for Scala3

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), 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.

This removes much of the use of this.type in Chisel which is necessary
to upgrade to Scala 3.
@adkian-sifive adkian-sifive added API Modification Scala 3 Changes related to upgrading to Scala 3 labels Oct 15, 2024
@jackkoenig
Copy link
Contributor

Turns out we need this for Scala3 after all

Can you explain more about why we need this? I know we saw errors related to it, but is there documentation or even a thread somewhere in Scala 3 development explaining the change?

@adkian-sifive
Copy link
Contributor Author

@jackkoenig updated the comment above with some more info

@@ -558,7 +556,7 @@ private[chisel3] trait AsyncResetImpl extends Element { self: AsyncReset =>

override def toString: String = stringAccessor("AsyncReset")

def cloneType: this.type = AsyncReset().asInstanceOf[this.type]
override def _cloneType: Data = AsyncReset()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
override def _cloneType: Data = AsyncReset()
override def _cloneType: AsyncReset = AsyncReset()

? perhaps? Why is this one different than the others

@@ -13,7 +13,7 @@ private[chisel3] trait ClockImpl extends Element {

override def toString: String = stringAccessor("Clock")

def cloneType: this.type = Clock().asInstanceOf[this.type]
override def _cloneType: Data = Clock()
Copy link
Contributor

Choose a reason for hiding this comment

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

why isn't this one Clock?


implicit class DataExtensions[T <: Data](self: T) {

/** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is an internal API, can we make it private to chisel?

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.

high level, why are we sometimes having the _cloneType return type be Data and other times we are having the explicit type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Modification Scala 3 Changes related to upgrading to Scala 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants