-
Notifications
You must be signed in to change notification settings - Fork 572
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 FixedIORawModule, FixedIOBlackBox #3535
Conversation
b0e5589
to
2827487
Compare
960873d
to
b028444
Compare
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'm not in love with the PolymorphicIO
name. I feel like most Chisel modules could make the claim that they are polymorphic over their IOs. Isn't it more like a "FixedIO" module?
Anyways, no major issues, I approve.
* This module may have no additional IO created other than what is specified | ||
* by its `ioGenerator` abstract member. | ||
*/ | ||
sealed trait PolymorphicIOBaseModule[A <: Data] extends BaseModule { |
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.
Was going to suggest an abstract class here, but I take it back, I think a trait is better.
b028444
to
a42326e
Compare
"Fixed" is also a good idea. I think this will much better match what a user thinks about here. "The IO is fixed" vs. "The IO is polymorphic" (???). 👍 Changes to this in the rebase. |
* This module may have no additional IO created other than what is specified | ||
* by its `ioGenerator` abstract member. | ||
*/ | ||
sealed trait FixedIOBaseModule[A <: Data] extends BaseModule { |
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.
👍 on the FixedIO name
/** A generator of IO */ | ||
protected def ioGenerator: A | ||
|
||
final val io = FlatIO(ioGenerator) |
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.
couldn't the order of trait-mixing-in allow a user to get around this?
trait MySneakyIO {
val sneakyIO = IO(UInt(32.W))
}
class MyThing extends MySneakyIO with FixedIORawModule
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.
Fortunately, no because FixedIORawModule
/FixedIOExtModule
are classes and not traits. Those have to be the first thing you mix-in, i.e., they need to follow extends
.
A user will see the following compile-time error if they try the above:
[error] /repos/github.com/chipsalliance/chisel/src/test/scala/chiselTests/FixedIOModuleSpec.scala:55:43: class FixedIORawModule needs to be a trait to be mixed in
[error] class MyThing extends MySneakyIO with FixedIORawModule[Bool](Bool())
[error] ^
If they change the order to be legal Scala, they'll get a runtime error because the trait constructor body runs after IO creation is disallowed:
[info] java.lang.IllegalArgumentException: requirement failed: This module cannot have user-created IO
[info] at ... ()
[info] at chiselTests.FixedIOModuleSpec$MySneakyIO$1.$anonfun$sneakyIO$2(FixedIOModuleSpec.scala:52)
[info] at chisel3.experimental.prefix$.apply(prefix.scala:50)
[info] at chiselTests.FixedIOModuleSpec$MySneakyIO$1.$anonfun$sneakyIO$1(FixedIOModuleSpec.scala:52)
[info] at chisel3.internal.plugin.package$.autoNameRecursively(package.scala:33)
[info] at chiselTests.FixedIOModuleSpec$MySneakyIO$1.$init$(FixedIOModuleSpec.scala:52)
[info] at chiselTests.FixedIOModuleSpec$MyThing$1.<init>(FixedIOModuleSpec.scala:55)
[info] at chiselTests.FixedIOModuleSpec.$anonfun$new$9(FixedIOModuleSpec.scala:57)
[info] at ... ()
[info] at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)
Add a `private[chisel3]` ability to block further IO creation in a `BaseModule`. This is intended for advanced, in-tree APIs that need to disallow the creation of further IO by a user. This API has mutable state to track if more IO is allowed to be created, a method to get the value, and a method to set the module to disallow further IO creation. This one-way setting (h/t @jackkoenig) tries to keep this as locked down as possible. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add a new module hierarchy that promotes the type of the IO of that module to a type parameter. This module hierarchy includes: 1. FixedIOBaseModule 2. FixedIORawModule 3. FixedIOBlackBox Both (2) and (3) inherit from (1). These modules are all "fixed" in the type of their IO. It follows that no more IO are allowed to be created other than what is in the type. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
a42326e
to
a79a20e
Compare
nit: can you change the name of this PR because i think it shows up in the release notes? |
Add a
private[chisel3]
ability to block further IO creation in aBaseModule
. This is intended for advanced, in-tree APIs that need todisallow the creation of further IO by a user. This API has mutable state
to track if more IO is allowed to be created, a method to get the
value, and a method to set the module to disallow further IO creation.
This one-way setting (h/t @jackkoenig) tries to keep this as locked down
as possible.
Add a new module hierarchy that promotes the type of the IO of that module
to a type parameter. This module hierarchy includes:
Both (2) and (3) inherit from (1). These modules are all polymorphic in
their type of IO. It follows that no more IO are allowed to be created
other than what is in the type.
Release Notes
Add
FixedIORawModule
andFixedIOExtModule
that have a type parameter describing what their IO is. This is intended for advanced APIs which want to have guarantees about the IO will be. These share a common trait,FixedIOBaseModule
which can be used to allow for substitution of one for the other.