-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add DataView #1955
Add DataView #1955
Conversation
No PR description or Scaladocs? |
The majority of public APIs (but not all) have ScalaDoc, and description is coming. This is a draft PR for a reason 🙂 |
Whoops right this is a draft PR. |
I feel like the Github UI could make it a little clearer, but oh well. Take a look at the tests if you're interested in what this does and why it's useful (or wait till I've written up some docs hah). |
After discussion with @azidar, we need to add a |
For anyone following along at home, this is nearing completion and I have "published" the initial version of the docs (see the links in the original PR comment). |
This is very smart solution to what I believe to be a problem during integration Chisel-based components. |
Note that the API has changed a little bit, I have updated the docs with the changes. |
This is done and ready for merging. There are some follow on things to enhance this and I'm sure there are bugs but it'd be nice to get this on |
68d20ef
to
69fcec1
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.
Very minor changes.
A+, definitely going to be an amazing feature, and you knocked it out of the park with the tests and documentation, as well as the quality of the implementation. Excited to see this in the wild!
|
||
object Foo { | ||
implicit def view[T <: Data]: DataView[Foo[T], Bar[T]] = { | ||
DataView(f => new Bar(f.foo.cloneType), _.foo -> _.bar) |
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.
gosh darn it, this is why I want 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.
It's not clear if Field
would actually fix this because Field
would require that something is an unbound type and this would fail that without the .cloneType
. I admit I don't have a good solution here but I agree this is a wart.
DataView is a mechanism for "viewing" Scala objects as a subtype of `Data`. Often, this is useful for viewing one subtype of `Data`, as another. One can think about a DataView as a cross between a customizable cast and an untagged union. A DataView has a Target type `T`, and a View type `V`. DataView requires that an implementation of `DataProduct` is available for Target types. DataProduct is a type class that provides a way to iterate on `Data` children of objects of implementing types. If a DataView is provided for a type T to a type V, then the function .viewAs[V] (of type T => V) is available. The object (of type T) returned by .viewAs is called a "View" and can be used as both an rvalue and an lvalue. Unlike when using an .asTypeOf cast, connecting to a "View" will connect to the associated field or fields of the underlying Target. DataView also enables .viewAsSupertype which is available for viewing Bundles as a parent Bundle type. It is similar to .viewAs but requires a prototype object of the Target type which will be cloned in order to create the returned View. .viewAsSupertype maps between the corresponding fields of the parent and child Bundle types.
It does not work in Scala 2.12 due to diverging implicit expansion with identityView. It *does* work in Scala 2.13.
🎉 |
Uses sbt-ci-release for automation
Introducing
DataView
🙂The documentation is complete. Here are the outputs of mdoc:
This is a large addition, but keep in mind that 1590 lines of change are documentation and tests (~70%)
TODO
DataProduct.contains
PartialDataView
.toTarget
on views.viewAs[T]
instead of.viewAs(new T)
val foo = (new MyHW).viewAs(new OtherType)
, currently the hardware gets a temporary nameFollow on PR work
DataViews
likeHWTuple
-- done in Implement DataViews for Seq and Tuple #2277FlatIO
withDataView
-- sketch: https://scastie.scala-lang.org/DOVFDr0XQNi4pWre8X7IzQandThen
DataViews
. This works in Scala 2.13 but leads to diverging implicit expansion in 2.12 (because of identityView).readOnlyView
using viewsDataProduct.lookup
(to get aString
name for fields that may have a bug)Aggregate
as aUInt
or vice versa).asTypeOf
)cloneViewToContext
to share implementation with.viewAs
Contributor Checklist
docs/src
?Type of Improvement
API Impact
Important API Expansion (not necessarily "large" since it is focused, but it is a pretty big feature)
Backend Code Generation Impact
No impact
Desired Merge Strategy
Release Notes
DataView is a mechanism for "viewing" Scala objects as a subtype of
Data
. Often, this is useful for viewing one subtype ofData
, asanother. One can think about a DataView as a cross between a
customizable cast and an untagged union.
A DataView has a Target type
T
, and a View typeV
. DataView requiresthat an implementation of
DataProduct
is available for Target types.DataProduct is a type class that provides a way to iterate on
Data
children of objects of implementing types.
If a DataView is provided for a type T to a type V, then the function
.viewAs[V] (of type T => V) is available. The object (of type T) returned
by .viewAs is called a "View" and can be used as both an rvalue and an
lvalue. Unlike when using an .asTypeOf cast, connecting to a "View" will
connect to the associated field or fields of the underlying Target.
DataView also enables .viewAsSupertype which is available for viewing
Bundles as a parent Bundle type. It is similar to .viewAs but requires
a prototype object of the Target type which will be cloned in order to
create the returned View. .viewAsSupertype maps between the
corresponding fields of the parent and child Bundle types.
Reviewer Checklist (only modified by reviewer)
Please Merge
?