-
Notifications
You must be signed in to change notification settings - Fork 609
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
[proposal] Bundle literals implementation #1057
Conversation
This seems like a pretty reasonable proposal to me. I think getting them out there with a minimum of boilerplate required of the Bundle definer makes the |
Can this work together/is this interoperable with a future |
@edwardcwang potentially: this expects a varargs function of That being said, I think if (and that's a reasonably big if) this goes through, the need for a |
Resolution from today's meeting was to document partial-initialization and DontCare semantics, and productionize this. The syntax seemed fine, and this is much preferable to the current way of constructing Bundle literals by defining a very low-level There was also discussion on naming ( |
This API appears to work in scastie class BundleLitTest {
val fieldA = 0
val fieldB = 1
def Lit(elems: (this.type => (Int, Int))*): this.type = {
for (elem <- elems) {
println(elem(this))
}
this
}
}
val a = new BundleLitTest
a.Lit(_.fieldA -> 10, _.fieldB -> 11)
|
Tested with 2.13 and dotty |
Ok, I've cleaned up the code and add test cases. Please review now. Some things that might need more discussion:
Future work would include:
|
My recommendation is that isLit = elements.forall(_.isLit)--yes, technically an API change, so should consult users. Same for eventual Vec lits. The current DontCare scheme sounds like the right way to go. Assigning a literal to another wire/reg should assign the entire thing--even if some fields are don't-cares. |
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.
This looks good to me.
Fix compile problem and go
retest this please |
Not sure what's going on with the compile error, it compiles fine for me and I don't see any new style violations. Potentially a transient bug in the build system, or at least that's what the Jenkins log indicates. |
We're adding some new machines to Jenkins slave network and some of the jobs impose incorrect constraints on their environment. This should be sorted out in the next day or two. |
retest this please |
@ducky64 Looks like this finally made it through the testing. Time to get it merged |
One additional thing we can do is to require an experimental import, eg |
Changed to:
|
import chisel3.testers.BasicTester | ||
import org.scalatest._ | ||
import chisel3.experimental.RawModule | ||
import chisel3.experimental.BundleLiteralConstructor._ |
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.
Suggestion to change chisel3.experimental.BundleLiteralConstructor
to chisel3.experimental.BundleLiteral
or chisel3.experimental.BundleLiterals
thoughts?
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 like the idea of chisel3.experimental.BundleLiterals
Potential implementation for Bundle literals, that doesn't use macro annotations and has passable syntax.
Example syntax:
For nested Bundles:
and more weirdly for anonymous inner Bundles (so probably not recommended syntax?):
The Lit constructor takes in a list of pairs (
->
) from fields to values, each each element being a function from a self-type object (the clone is used internally) to a field. This gives reasonable syntax (basically you have the additional_.
prefix over each field over what we could do with macro annotations) while being able to compile-time typecheck field accesses (so if you renamed fields, the typechecker would complain about trying to access an nonexistent field).Drawbacks compared to a macro annotation approach:
Data
. With macro annotations, we can (maybe?) generate a function signature based off the field type. Note that compile-time Chisel type checks are not perfect, the dynamictypeEquivalent
is much more accurate._.
prefix for each field._
in anonymous functions is a somewhat-flakey operator. This seems to work though. Originally, Lit has the argument signature(this.type => Data, Data)*
but the_
doesn't work there._
operator in the value part (since the argument signature is(this.type => (Data, Data))*
), but that will exception out inside the Lit constructor, since the Lit constructor calls the function on the newly cloned object (which obviously can't be referenced before).But not needing a macro annotation (and requiring annotated Bundles, or the dev time to develop the annotation that we haven't had yet) is a nice property...
If we like this API, these improvements are needed:
Related issue: Resolves #805
Type of change: other enhancement
Impact: API addition (no impact on existing code)
Development Phase: proposal
Release Notes