-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
Release 0.15 #476
Comments
@mystor @alexcrichton @SergioBenitez @sgrif @Arnavion @Eijebong @steveklabnik if you have some time to check it out and maybe upgrade some existing crates, let me know if you have feedback on the new design. I'll plan to cut the real release around Tuesday or Wednesday. |
I'm quite busy with the hyper update in servo right now but we're already lagging behind anywyay. |
I only use syn for custom derives via |
I'll look into updating |
Diesel has 2 errors:
The other is from the change to |
Thanks Sean! I published 0.15.0-rc2 which puts back the impl for FieldValue. Sorry about that. |
We now receive this error:
Not entirely sure where it's coming from, unlikely to be the parsing of the derive input (which looks like this)
The derive in question is here: |
Looks like it was from That line can be written as |
I just finished porting an (albeit simple) procedural macro to syn-next@0.15.0-rc3, it was very straightforward. The only problem that I encountered was my use of |
Diesel's test suite is green
…On Sun, Sep 2, 2018 at 4:10 PM Louis Person ***@***.***> wrote:
I just finished porting an (albeit simple) procedural macro to
***@***.***, it was very straightforward. The only problem that I
encountered was my use of custom_keyword!, and after a quick glance at
the documentation I couldn't find any replacement. My initial idea was to
define one type per keyword, implement syn::token::Token for each of them
and peek them on a lookahead. However the syn::token::Token is sealed
making this impossible. I ended up parsing an Ident and matching its
string representation manually, but this doesn't feel in line with the new
parsing API. Did I miss something in the documentation ? If not, is there
any possible work-around @dtolnay <https://github.com/dtolnay> ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#476 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABdWK4dgVbmAiGF2VOUO8vNEwkESxDdRks5uXFc6gaJpZM4WWdl2>
.
|
I'd like to test out the new release but it's a long weekend in the US so I probably won't get a chance to do this until Tuesday/Wednesday at the earliest |
|
I don't have a good design for custom keywords. Currently the best workaround would be as demonstrated in this example code e.g. if you have a custom keyword called let gen_token: Ident = input.parse()?;
if gen_token != "gen" {
return Err(Error::new(gen_token.span(), "expected `gen`"));
} Ideally this would be something like input.parse::<gen>()?;
// or
input.parse::<Token![""gen""]>()?;
// or
input.parse::<Keyword<gen>>()?; with some macro to wire everything up. custom_keyword!(gen); There's a question of what exactly this macro emits and how to deal with visibility, since we wouldn't want something public by default because that makes it unusable in the root of a proc macro crate which cannot contain anything pub, but we want some way for the same custom keyword to be usable across modules. It could be: custom_keyword!(pub gen); Alternatively there's K.I.S.S. I would love a PR or prototype if anyone wants to think about this. |
If we had some way to make Perhaps we could have a |
Ok got a chance to port over
Overall this looks like a great improvement! The commit looks quite clean. I'm not sure if |
Thanks Alex! We can add Clone for Error. Instead of ToTokens, would it help if we change into_compile_error to to_compile_error and take self by ref? Regarding Instead of your AnyIdent try to use |
@dtolnay I think For performance that sounds great to me, it sounds like the right defaults. I like the default of "use Also |
Update: I got busy, currently planning to land something for custom keywords as well as the changes based on Alex's feedback, then release morning PDT on Thursday. |
I landed a design I like for custom keywords in #481, added |
proc_macro::Group::span_open and span_close Before this addition, every delimited group like `(`...`)` `[`...`]` `{`...`}` has only a single Span that covers the full source location from opening delimiter to closing delimiter. This makes it impossible for a procedural macro to trigger an error pointing to just the opening or closing delimiter. The Rust compiler does not seem to have the same limitation: ```rust mod m { type T = } ``` ```console error: expected type, found `}` --> src/main.rs:3:1 | 3 | } | ^ ``` On that same input, a procedural macro would be forced to trigger the error on the last token inside the block, on the entire block, or on the next token after the block, none of which is really what you want for an error like above. This commit adds `group.span_open()` and `group.span_close()` which access the Span associated with just the opening delimiter and just the closing delimiter of the group. Relevant to Syn as we implement real error messages for when parsing fails in a procedural macro: dtolnay/syn#476. ```diff impl Group { fn span(&self) -> Span; + fn span_open(&self) -> Span; + fn span_close(&self) -> Span; } ``` Fixes #48187 r? @alexcrichton
Preview rustdoc: https://docs.rs/syn-next/0.15.0-rc4/syn/
Release notes work in progress:
This release introduces a new parsing API that enables procedural macros to easily report intelligent errors when provided syntactically invalid macro input.
This functionality is important because Rust 1.29.0, shipping next week, will be stabilizing support for defining
functionlike!(...)
procedural macros. Until now procedural macros have only been usable as custom derives, for which the compiler guarantees a syntactically valid input and thus error reporting is not the responsibility of the macro. Function-like macros a.k.a. "bang" macros are different in that the caller may pass any invalid crazy input and needs to be told by the macro where they messed it up.See below a few examples of error messages produced by Syn with almost no effort or attention to error handling on the part of the macro author.
Parsing
With the transition to the new parsing API we drop the use of
nom
-style parser combinator macros in favor of plain Rust functions and control flow. Parsers should be easier to write, much easier to read, and emit reasonable error messages with very little effort.Here is how we might implement parsing for a simplified representation of Rust
struct
s.Another example, input that may be either a
struct
or anenum
:This release introduces a
parse_macro_input!
macro that handles shuffling errors correctly back to the compiler inside of a procedural macro.Let's try feeding this macro some invalid input. Syn triggers a compiler error indicating the problematic token and information about what the parser would have expected in that position where possible.
Compile time and performance
As always, much attention has been paid to compile time. Error reporting is nice but we don't want to spend an excessive amount of time compiling tons of error handling code.
The parsing component has been designed with compile time in mind and Syn 0.15 consistently compiles in around the same amount of time as the most recent point release of 0.14. This is despite adding support for a variety of new Rust syntax accepted through RFCs and eRFCs in recent months.
Parsing performance improves by 50% with the move to the new parsing API, as measured by time taking to parse every Rust source file in the rust-lang/rust repo and its submodules. That time is down from 10.6 seconds to 6.9 seconds on my machine.
Newly supported Rust syntax
try
blocks — RFC: Reservetry
fortry { .. }
block expressions rust-lang/rfcs#2388extern
blocks — Tracking issue formacros_in_extern
feature rust-lang/rust#49476use
— impl-only-use rust-lang/rfcs#2166if let
andwhile let
chains — eRFC: if- and while-let-chains, take 2 rust-lang/rfcs#2497MyTrait<AssociatedType: Bounds>
rust-lang/rfcs#2289The text was updated successfully, but these errors were encountered: