-
Notifications
You must be signed in to change notification settings - Fork 615
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
Deprecate Module.io and BlackBox.io #1550
Conversation
This is a step toward unification of Module with MultiIOModule. The future of BlackBox is a bit less clear, but its existing API can be maintained without the io virtual method. The trickier API to maintain is auto-IO wrapping for compatibility Modules and BlackBoxes. This will probably require reflection to support once the io virtual method is removed.
Wow, I'm pleasantly surprised how simple the solution came out to be (assuming this doesn't break a giant chunk of code that we don't know about yet - though I agree with the arguments presented of why it shouldn't). I think this looks sane. Other CommentsWith regards to alternate solutions: I think it's worth thinking about useful properties of the current (anonymous Bundle) syntax in considering trade-offs. It:
Separately from the 2.12+ compatibility issue is whether to unify MultiIOModule and Module - and if this PR goes through, is probably more of a style guide issue. I think the arguments for Module are mainly that it centralizes all the IO in one Bundle, so you can do bulk operations on them (but importantly, this doesn't include clock and reset, but they're usually implicitly connected the same source). However, the issue there is that extending the interface in subclasses becomes a lot harder, since you have to modify io instead of just adding a new val - which is what MultiIOModule makes easierr. For BlackBox: doesn't ExtModule present a more MultiIOModule like interface, without the need for the .io single object and the naming hackiness? I don't know how much traction / usage it's seen, but it's a bit more elegant, or at least consistent? |
I cannot express how relieved I am at how simple it came out. This has been a big worry for a long time and it seems we get off basically scot-free.
Yeah I think it's important to look out for such issues on 3.4.0-RC1. Also if there is something we don't notice till after full release, it seems pretty easy to undo so I think the risk is low. I did try this with SiFive's codebase and only had like 10 warnings from it and they were all easily fixable cases. For example: I agree with your
This one is a little tricker because people like the |
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.
One suggestion for improved description
@@ -133,23 +133,27 @@ package experimental { | |||
* @note The parameters API is experimental and may change | |||
*/ | |||
abstract class BlackBox(val params: Map[String, Param] = Map.empty[String, Param])(implicit compileOptions: CompileOptions) extends BaseBlackBox { | |||
@deprecated("For type-safe interfaces, provide your own trait. For reflective API, use DataMirror", "Chisel 3.4") |
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.
Consider adding a bit more description here, something to the effect of "Module.io will be removed since it breaks in Scala 2.12+; you can still define io Bundles in your Modules, but cannot rely on a io field in every Module; for more details see (url here, possibly to this PR)"
And repeat below for Module.
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 idea, I more-or-less copied your suggestion.
* adding init macros * fix missing tick * adding more documentation; fixing up emitter tests * adding initial-guarding macro test * prefixing macros with FIRRTL * cleanup * typo fix Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Why?
I was experimenting with some stuff in Scala 2.13 and realized that
-Xsource:2.11
is no longer supported in 2.13. In fact, it was never recommended as an option to Scalac for anything but debugging, let alone our recommended way of supporting Scala 2.12. Thus I had a discussion on the Scala Contributors Gitter to figure out what to do.For a long time, we thought the issue only had to do with structural typing. This was incorrect, there were actually 2 different problems:
The thing that made this confusing was that fixing either (1) or (2) is sufficient to no longer need
-Xsource:2.11
, but we generally only talked about solutions to (1). To be more precise, if we stopped using the patternval io = IO(new Bundle { ... })
, we would no longer need-Xsource:2.11
in Scala 2.12.This solution could work as a ScalaFix rewrite rule:
Becomes
Unfortunately, due to (2) where Scala 3 is stricter, you would also need to annotate the type of
io
in Scala 3:While this is a solution, there is a massive downside that we have to encourage all of our users to rewrite all of their code (potentially ScalaFix assisted), and purge documentation of this bad style.
It turns out that removing
io
as a virtual method solves both (1) and (2). The exact same style of Modules with anonymousBundle
s forio
will work in Scala 2.12, 2.13, and 3.Implications
What does this actually do?
This deprecation warning only shows up for when
io
is used as a field ofModule
orBlackBox
itself. That is, only when relying on the common interface of those abstract classes will cause the warning. Some examples:Thus, this warning is actually fairly rare because most people either rely on more type-safe APIs (some common
trait
defining a more precise type forIO
), or useDataMirror.fullModulePorts
since they want to be able to get the IO fromMultiIOModules
andRawModules
as well.Module
The virtual method allowed us to use the type system to enforce the single-source of ports via
val io
. We can still enforce that throughDataMirror.fullModulePorts
if we want. We could alternatively unifyModule
andMultiIOModule
and relegateval io
to a stylistic choice.BlackBox
BlackBox
has special behavior where theio
prefix is dropped. While it's still an open-question for how to provide this behavior in a less hacky way, it needs to be maintained. Theio
virtual method is currently used to find the ports, but we could use theDataMirror.fullModulePorts
"reflective" API to find them and ensure theio
prefix is dropped.Compatibility-mode
import Chisel._
does not requireIO
wrapping ofio
forModule
andBlackBox
. It uses the virtual method to apply the binding to them. 2 possible solutions:io
Related issue:
Type of change: other enhancement
Impact: API modification
Development Phase: implementation
Release Notes
Deprecate
Module.io
andBlackBox.io
virtual methods