-
Notifications
You must be signed in to change notification settings - Fork 574
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
Autoclonetype will clone args that are of type data #768
Conversation
@@ -18,6 +18,7 @@ class ArbiterIO[T <: Data](gen: T, n: Int) extends Bundle { | |||
val in = Flipped(Vec(n, Decoupled(gen))) | |||
val out = Decoupled(gen) | |||
val chosen = Output(UInt(log2Ceil(n).W)) | |||
override def cloneType: this.type = new ArbiterIO(gen, n).asInstanceOf[this.type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think we should change the constructor arguments to private val gen: T, val n: Int
to take advantage of autoclonetype rather than implementing a clonetype.
I ran into an interesting issue trying to get all of this working in rocket-chip. If you override clonetype and then someone extends the class, you get runtime exceptions. This occurs in rocket-chip with QueueIO
extended here.
I think we should change all of the library types to use autoclonetype
Good points, converted to use autoclonetype. I don't like private vals (from my view of a new-user wtfs/min metric - which may or may not reflect reality), but I can see how clonetype + subclasses could cause even more unintuitive errors. |
@@ -14,7 +14,10 @@ import chisel3.internal.naming.chiselName // can't use chisel3_ version because | |||
* @param gen data type | |||
* @param n number of inputs | |||
*/ | |||
class ArbiterIO[T <: Data](gen: T, n: Int) extends Bundle { | |||
class ArbiterIO[T <: Data](private val gen: T, val n: Int) extends Bundle { | |||
// gen is a val to allow autoclonetype to work, but private to not be detected as a Bundle field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just link to the issue? (and just make this a one line comment) (1) It's easier to search for parts of the code related to the issue. (2) It's easier to get updates if someone sees this in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, shortened the comment and linked the relevant issue.
@jackkoenig making Decoupled use autoclonetype turns out to break rocket-chip, since there's a use of a bound |
@ucbjrl test seems to be failing because something is causing sbt to go crazy, apparently wiping the
|
I'd like to add that there are reasons you might not want Forgive me if previous discussions have raised this point, but couldn't we use the bindings system? If a |
retest this please |
@grebe How do you access I'm not sure how the bindings system could handle this, is your suggestion that if you instantiate |
The issue with bindings is that Bundle fields aren't consistently bound. Some fields might have Input or Output bindings, but some might have none, for example class MyBundle extends Bundle {
val field = UInt(8.W)
} (where |
retest this please. |
@jackkoenig I think right now we actually match on something that the prototype is used to make, i.e. if a field is @ducky64 is it legal to have an unbound element in a |
@grebe When you wrap the Bundle in |
These are unlikely to be extended and relying on autoclonetype has iffy behavior with hardware types in compatibility code
retest this please |
It's failing because of the sbt dependency bug 🙄
|
retest this please - after |
Short-term (until 3.1.1/3.2) patch for [RFC] What does it mean to be a Bundle? #765 to work better with autoclonetype
This does not attempt to give an informative error message for
MixedDirectionAggregateException
, because the exception will not be raised in all cases (for example, if the Bundle contents were not directioned), it will require significant heuristic code to catch what seems to be a very uncommon edge case, sufficient debugging information is already printed, and an API addition for 3.1.1/3.2 should remove ambiguity.Also makes ArbiterIO cloneable through a cloneType implementation.
Type of change
Impact
Development Phase
Release Notes
Autoclonetype will work with Bundle that have fields defined in their constructors.
I personally don't think that's good style. as it raises the learning curve needed, but apparently it has users.
See [RFC] What does it mean to be a Bundle? #765 for proposals for 3.1.1/3.2, where we may add an explicit (but optional) Field(...) construct to Bundle.