-
-
Notifications
You must be signed in to change notification settings - Fork 791
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
No more syntex for serde_derive #548
Conversation
Running |
For some reason serde_codegen by itself builds three times as fast this way, which I didn't expect. I guess quasi_macros is slow?
|
fewer generics? |
I did some testing with rusoto in rusoto/rusoto#364 (comment) to see how performance of this PR compares with the current serde_macros (runtime performance, after they have been compiled). They come out about even which is great. |
Conflicts: serde_codegen/Cargo.toml serde_codegen_internals/Cargo.toml serde_derive/Cargo.toml
Conflicts: serde_codegen/src/ser.rs
There is a lot of work left here but let's take a moment to celebrate 9a86e68 the first syntex-free green build. |
Conflicts: serde_codegen/Cargo.toml
@oli-obk @erickt this is ready for review. There were a few places that I uncovered strange behavior in the old codegen (just unusually placed semicolons / parentheses / braces) that I went out of my way to preserve. I left comments and I can clean that up in a separate PR. I confirmed that this PR expands the test suite byte-for-byte identical to master. I filed #562 to follow up. I filed #561 as another follow-up task. I don't think that needs to block this PR. |
Awesome progress @dtolnay! |
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 is totally great. I have no complaints that should be seen as blockers. Let's do this!
Some(quote!(::<#(ty_param_idents),*>)) | ||
}; | ||
|
||
let phantom_exprs = (0 .. num_phantoms).map(|_| quote!(::std::marker::PhantomData)); |
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.
std::iter::repeat(quote!(::std::marker::PhantomData)).take(num_phantoms)
runs the expanded quote
code only once. Not really relevant though.
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.
Done.
struct __Visitor #generics ( #(phantom_types),* ) #where_clause; | ||
}, | ||
quote!(__Visitor <#(all_params),*> ), | ||
quote!(__Visitor #ty_param_idents ( #(phantom_exprs),* )), |
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 expansion magic
extern crate aster; | ||
extern crate quasi; | ||
// The `quote!` macro requires deep recursion. | ||
#![recursion_limit = "192"] |
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'm through with serde_codegen
. Big 👍 on the quote!
call readability.
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 agree. I love how've much simpler everything looks.
use std::cell::RefCell; | ||
|
||
#[derive(Default)] | ||
pub struct Ctxt { |
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'm not very happy with the Ctxt
structure and it's usage. I'd much rather have regular Result
type error reporting, but we can leave that to a future refactoring. Maybe the code gets horribly cluttered with Result
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 filed #563 to follow up in a future refactoring.
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 wasn't amazing. Great work.
extern crate aster; | ||
extern crate quasi; | ||
// The `quote!` macro requires deep recursion. | ||
#![recursion_limit = "192"] |
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 agree. I love how've much simpler everything looks.
$type_ident::$variant_ident(ref __simple_value) => $block | ||
) | ||
quote! { | ||
// The braces are unnecessary but quasi used to put them in. We |
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.
If I recall correctly, quote_block required the extra braces, so shouldn't be a problem to remove them later.
Conflicts: serde_macros/tests/compile-fail/reject-unknown-attributes.rs
rustc_macro_derive
rust-lang/rust#36211Follow-up tasks: