Skip to content
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

parse: unify function front matter parsing #69023

Merged
merged 13 commits into from Feb 13, 2020
Merged

parse: unify function front matter parsing #69023

merged 13 commits into from Feb 13, 2020

Conversation

@Centril
Copy link
Member

Centril commented Feb 10, 2020

Part of #68728.

  • const extern fn feature gating is now done post-expansion such that we do not have conditional compatibilities of function qualifiers in parsing.

  • The FnFrontMatter grammar becomes:

    Extern = "extern" StringLit ;
    FnQual = "const"? "async"? "unsafe"? Extern? ;
    FnFrontMatter = FnQual "fn" ;

    That is, all item contexts now syntactically allow const async unsafe extern "C" fn and use semantic restrictions to rule out combinations previously prevented syntactically. The semantic restrictions include in particular:

    • fns in extern { ... } can have no qualifiers.
    • const and async cannot be combined.
  • We change ast::{Unsafety, Spanned<Constness>}> into enum ast::{Unsafe, Const} { Yes(Span), No } respectively. This change in formulation allow us to exclude Span in the case of No, which facilitates parsing. Moreover, we also add a Span to IsAsync which is renamed to Async. The new Spans in Unsafety and Async are then taken advantage of for better diagnostics. A reason this change was made is to have a more uniform and clear naming scheme.

    The HIR keeps the structures in AST (with those definitions moved into HIR) for now to avoid regressing perf.

r? @petrochenkov

src/librustc_ast_passes/ast_validation.rs Outdated Show resolved Hide resolved
src/librustc_ast_passes/ast_validation.rs Outdated Show resolved Hide resolved
src/librustc_ast_passes/ast_validation.rs Outdated Show resolved Hide resolved
src/librustc_ast_passes/ast_validation.rs Outdated Show resolved Hide resolved
src/librustc_hir/print.rs Outdated Show resolved Hide resolved
src/librustc_ast_passes/ast_validation.rs Outdated Show resolved Hide resolved
src/librustc_builtin_macros/test.rs Outdated Show resolved Hide resolved
src/librustc_parse/parser/item.rs Outdated Show resolved Hide resolved
src/librustc_ast_passes/feature_gate.rs Show resolved Hide resolved
src/librustc_parse/parser/item.rs Outdated Show resolved Hide resolved
@bors

This comment was marked as resolved.

Copy link
Contributor

bors commented Feb 11, 2020

☔️ The latest upstream changes (presumably #68929) made this pull request unmergeable. Please resolve the merge conflicts.

@Centril Centril force-pushed the Centril:parse_fn branch from 5477de2 to 5065590 Feb 11, 2020
@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Feb 11, 2020

Addressed the comments. :)

@bors

This comment was marked as resolved.

Copy link
Contributor

bors commented Feb 11, 2020

☔️ The latest upstream changes (presumably #68725) made this pull request unmergeable. Please resolve the merge conflicts.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Feb 11, 2020

r=me after rebase

@Centril Centril force-pushed the Centril:parse_fn branch from 5065590 to 9828559 Feb 13, 2020
@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Feb 13, 2020

@bors r=petrochenkov

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 13, 2020

📌 Commit 9828559 has been approved by petrochenkov

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 13, 2020

⌛️ Testing commit 9828559 with merge be493fe...

bors added a commit that referenced this pull request Feb 13, 2020
parse: unify function front matter parsing

Part of #68728.

- `const extern fn` feature gating is now done post-expansion such that we do not have conditional compatibilities of function qualifiers *in parsing*.

- The `FnFrontMatter` grammar becomes:
   ```rust
   Extern = "extern" StringLit ;
   FnQual = "const"? "async"? "unsafe"? Extern? ;
   FnFrontMatter = FnQual "fn" ;
   ```

   That is, all item contexts now *syntactically* allow `const async unsafe extern "C" fn` and use semantic restrictions to rule out combinations previously prevented syntactically. The semantic restrictions include in particular:

   - `fn`s in `extern { ... }` can have no qualifiers.
   - `const` and `async` cannot be combined.

- We change `ast::{Unsafety, Spanned<Constness>}>` into `enum ast::{Unsafe, Const} { Yes(Span), No }` respectively. This change in formulation allow us to exclude `Span` in the case of `No`, which facilitates parsing. Moreover, we also add a `Span` to `IsAsync` which is renamed to `Async`. The new `Span`s in `Unsafety` and `Async` are then taken advantage of for better diagnostics. A reason this change was made is to have a more uniform and clear naming scheme.

  The HIR keeps the structures in AST (with those definitions moved into HIR) for now to avoid regressing perf.

r? @petrochenkov
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 13, 2020

☀️ Test successful - checks-azure
Approved by: petrochenkov
Pushing be493fe to master...

@bors bors added the merged-by-bors label Feb 13, 2020
@bors bors merged commit 9828559 into rust-lang:master Feb 13, 2020
5 checks passed
5 checks passed
homu Test successful
Details
pr Build #20200213.12 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-7) Linux x86_64-gnu-llvm-7 succeeded
Details
pr (Linux x86_64-gnu-tools) Linux x86_64-gnu-tools succeeded
Details
@Centril Centril deleted the Centril:parse_fn branch Feb 13, 2020
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Feb 13, 2020

📣 Toolstate changed by #69023!

Tested on commit be493fe.
Direct link to PR: #69023

💔 rustc-guide on linux: test-pass → test-fail (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Feb 13, 2020
Tested on commit rust-lang/rust@be493fe.
Direct link to PR: <rust-lang/rust#69023>

💔 rustc-guide on linux: test-pass → test-fail (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).
@JohnTitor

This comment has been minimized.

Copy link
Member

JohnTitor commented Feb 13, 2020

(Toolstate failure is spurious, can be ignored.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.