Repository navigation
Implement a #[vtable] macro - #322
Conversation
This comment has been minimized.
This comment has been minimized.
commented
May 29, 2021
|
Review of
|
commented
Jun 1, 2021
|
I see this pattern in #264 again so we definitely want a single macro abstraction for all vtables. |
commented
Jun 1, 2021
|
As you know, this is something that I wanted to do for
|
commented
Jun 1, 2021
I don't know if #264 need this, but #208 certainly do.
Are there reasons not to implement read_iter/write_iter? The current trait design essentially guarantees that it either both or none are supported. Without specialization, it makes no sense to support one but not another. If we really want to let the implementor decide, then generics should not be used. If we do want them to opt out (rather than opt in), we can just add a manual
I would suggest the opposite. I would also argue that it is also less complex than the current declarative macro. I got confused when I first saw the This procedural macro is simpler to use, less error prone, less code, less boilerplate, and generate a good documentation. 60 lines of boilerplate for each vtable and hours of debugging caused by forgetting to add the name of method to the |
commented
Jun 1, 2021
|
I don't understand why you're so against proc macros, but I want to make one point: any complexities in proc macros are used to reduce complexities elsewhere. As long as the reduced complexities outweigh the introduced complexities, we should definitely go for it. As for this case, given that there we are going to have at least 2 (maybe 3) trait users and a couple impl users of this macro, and certainly more in the future, I believe the macro certainly reduces the overall complexity. |
| const_items = "const USE_VTABLE_ATTR: () = ();".to_owned(); | ||
|
|
||
| for f in functions { | ||
| write!(const_items, "const HAS_{}: bool = true;", f.to_uppercase()).unwrap(); |
There was a problem hiding this comment.
line 66 adds a doc comment about the const value, which is missing in this line.
There was a problem hiding this comment.
It's intentional to have doc comment only in trait but not in impls.
fa059e1 to
bcb1aed
Compare
|
|
||
| #![allow(dead_code)] | ||
|
|
||
| use crate::prelude::*; |
There was a problem hiding this comment.
nit: are you including the prelude just for vtable? If so, I think it's better to add macros::vtable to the list below.
There was a problem hiding this comment.
I think it should generally be fine to include prelude. I could remove the Error and Result import so that this import is used more than just vtable.
There was a problem hiding this comment.
Even if you want to include prelude::*, you should add it to the line below for consistency.
Now, given the choice of adding macros::vtable or prelude::*, I think the former is preferable because we don't pollute the namespace with more symbols than needed. (prelude is meant for drivers.)
You're obviously welcome to disagree with our handling or prelude, but in that case I'd argue that you're unnecessarily conflating issues: let's open another PR or issue to discuss that if you'd like. I'm ready to merge this once we come to an agreement on the use clause.
Use a single `#[vtable]` macro to replace the current boilerplating of `ToUse`, `USE_NONE`, `declare_file_operations` required for declaring and implementing traits that maps to Linux's pure vtables and contains optional methods. Signed-off-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Gary Guo <gary@garyguo.net>
commented
Jul 5, 2022
|
Thank you, @nbdd0121! |
Use a single
#[vtable]macro to replace the current boilerplating ofToUse,USE_NONE, declare_file_operations` required for declaring and implementing traits that maps to Linux's pure vtables and contains optional methods.This'll be more natural and less noisy than the current approach, and it paves the way for other vtables such as the one in #208 so that we don't need a
ToUse,USE_NONEand a macro for each vtable trait.Little note that this just scans the tokens so cannot handle case like
but this is very rare. I think we can live with this for now; we can always migrate to proper parsing later if we ever get
synvendored.