-
Notifications
You must be signed in to change notification settings - Fork 592
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
the cloneType and chiselCloneType hot mess 🔥 #653
Conversation
Should note (at least for now) the necessity of overriding cloneType for user-defined types (e.g. subclasses of Bundle). |
Resolution:
|
Alright I've merged master into this (@ducky64 if you could check my work that would be great because it was nontrivial). Master is now bumped on rocket-chip for the first time in months so we can more easily check this against big code bases! |
@jackkoenig changes look good. |
Okay so the only problem I see with this is pretty minor but I want to see if there's a better solution. Basically, this PR makes it to where if you are using chiselCloneType (be it in compatibility or regular chisel3 code) you get inferred existential types. This is just an annoying warning, but I don't understand why it now comes up but didn't before. It's also problematic if you default to erroring on warnings (you know, good practice). An example that illustrates the problem: import chisel3._
class MyTestSubModule extends Module {
val io = IO(new Bundle {
val in = Input(UInt(32.W))
val out = Output(UInt(32.W))
})
io.out := io.in
}
class MyTestModule extends Module {
val child = Module(new MyTestSubModule)
val io = IO(child.io.chiselCloneType)
io <> child.io
}
object Test extends App {
chisel3.Driver.execute(args, () => new MyTestModule)
} This simply passes through the IO of a child module. On master, there is no warning, on this branch we get the existential type warning for the io of the parent module (MyTestModule). Weirdly, if we change the io of the parent module to flip the child io type twice, the warning goes away: class MyTestModule extends Module {
val child = Module(new MyTestSubModule)
val io = IO(Flipped(Flipped(child.io.chiselCloneType)))
io <> child.io
} Is there any way we can remove this warning without forcing users to change their code or build configuration? |
Strange... chiselCloneType was moved to compatibility using PML, so instead of returning implicit class cloneTypeable[T<:Data](val target: T) extends AnyVal {
def chiselCloneType: target.type = {
DataMirror.internal.chiselTypeClone(target).asInstanceOf[target.type]
}
} Also interestingly, IO is defined as protected def IO[T<:Data](iodef: T): iodef.type = { while Flipped is defined as def apply[T<:Data](source: T): T = { Does redefining IO to return T (instead of iodef.type) help? Or does that also break things? I'm not sure why IO is defined that way... |
Changing IO to return class MyTestModule extends Module {
val child = Module(new MyTestSubModule)
val io = IO(new Bundle {
val port = child.io.chiselCloneType
})
io.port <> child.io
} However, changing |
I'm not sure why IO returns a structural type, but if it works with parameter types, we should change it to that. |
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.
@ducky64 Can you change def IO back to returning iodef.type otherwise I think this is good for RC1
Addresses #419
Overview:
Remaining issues:
this.type
is a nasty hack (see Invalid use ofthis.type
for clone methods #193) and to avoid the.asInstanceOf[this.type]
boilerplate needed in every cloneType implementation. It seems rocket-chip still has things that call cloneType directly so this causes compile errors. Only a small handful, though, so maybe this is something we could do? Otherwise, Scala does not seem to try implicit conversions on the wrong return type, so PML isn't a solution here.This should not be merged yet, this is just a starting point to think about these issues.