-
-
Notifications
You must be signed in to change notification settings - Fork 129
Perfect-derive for miette Diagnostic
derive (adding required bounds automatically to the impl based on the generics usage)
#421
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
base: main
Are you sure you want to change the base?
Conversation
This should be mostly good, I'll add some tests but I'd appreciate a comment-type review in the meantime if possible :) |
ok tests are now there as well (thought I would do it later but I noticed |
Oh and I just noticed since I added an explicit to_owned instead of just relying on an implicit copy for the label (I think, should test, maybe add a unit test for that?) #377 should work just fine as well. Since |
Putting it behind a feature flag seems wise, yes. |
Hi, as I am in the process of moving right now I will probably only get back to this the next weekend or so, but my current plan for this is:
And finally, after all this is done I should probably prepare a change log entry, so I am going to do that as well. If that sounds like a reasonable plan feel free to let me know what you think (or any other things I should do) otherwise I would just go ahead with that plan once I've got some more time to work on this ( as I've mentioned probably around next weekend ) |
( accidentally pressed the close button, sorry for the noise ) |
e35e69e
to
ea48010
Compare
Hey just a quick update that I am still working on this, just life kinda got in the way and I didn't have as much time as I wished to work on this. Will try to get this to a review-able state soon tho :) |
This is implemented using a new TypeBoundsStore struct which tracks usage of types during parsing and stores required bounds for generics, trying to use some heuristics to remove unneeded bounds. Signed-off-by: Justus Fluegel <[email protected]> Signed-off-by: Justus Flügel <[email protected]>
Signed-off-by: Justus Fluegel <[email protected]> Signed-off-by: Justus Flügel <[email protected]>
5308723
to
629ae49
Compare
4851090
to
5017778
Compare
Codegen changesSummary of generated (derived) code changes from this pr, excluding additional while bounds included with the perfect-derive feature:
|
5017778
to
0451f59
Compare
Functional summarySo a functional summary of the changes introduced in this pr: The general idea of perfect-derive is to keep track of the types of fields of structs and enums and look at the context what they are used for inside the derive macro and then add trait bounds (additional where clause items) to the types automatically. To facilitate this, this pr introduces a At the point of implementation, where the struct fields are then used, we always add the where bounds to the store as if the type is generic, meaning for example When the Using the |
I hope the last 2 comments help a bit with reviewing this pr, I know it is not super small (~+750 lines overall) but I appreciate if you could take the time @zkat :) Thank you in advance |
Diagnostic
derive (adding required bounds automatically to the impl based on the generics usage)
One Idea I had to make this strictly non-breaking in the one small place where it theoretically could be, is to continue to emit the old declarations in the one place where it could be seen as breaking if the feature is not enabled, and then just disable that on the next breaking release. - if that is desired just let me know and I'll quickly patch that in as well :) |
0451f59
to
dc74a05
Compare
…ementation strictly more flexible using to_owned over clone Signed-off-by: Justus Fluegel <[email protected]> Signed-off-by: Justus Flügel <[email protected]>
Signed-off-by: Justus Flügel <[email protected]>
… can't format Signed-off-by: Justus Flügel <[email protected]>
Signed-off-by: Justus Flügel <[email protected]>
Signed-off-by: Justus Flügel <[email protected]>
…ble adding trait bounds Signed-off-by: Justus Flügel <[email protected]>
…he main docs page Signed-off-by: Justus Flügel <[email protected]>
dc74a05
to
0e95e81
Compare
Also: May I kindly request a ci re-run? :) |
Quick ping @zkat just if you have seen this? No worries if you currently don't have the time/will/... to look at this. |
I've seen it. I'm just a bit busy to look at it right this second, in the context of potentially moving miette to facet |
Thanks for taking the time to respond :) No worries if you are busy, take care of your more important things first, this (and I) can wait. |
This is an attempt to make the derive macro for
Diagnostic
work better with generics, allowing to write code like for exampleThis should for example make #162 just work, as well as things like
and the other supported attributes.
AFAIK the only gotcha with this implementation right now is that
#[related]
only works with concrete collection types and not with generic collections, but the type inside the collection can be generic. (meaning:Vec<T>
works but not any arbitraryC
whereC: IntoIter<Item: Diagnostic>
), and I think that is a current limitation of the rust compiler / the current Diagnostic trait design.Questions: Do we want to gate this behind a feature flag since it pulls in extra-traits from syn and performs a bunch of extra work?