Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Attach tokens to all AST types used in Nonterminal #75800

Merged
merged 8 commits into from
Sep 11, 2020

Conversation

Aaron1011
Copy link
Member

We perform token capturing when we have outer attributes (for nonterminals that support attributes - e.g. Stmt), or when we parse a Nonterminal for a macro_rules! argument. The full list of Nonterminals affected by this PR is:

  • NtBlock
  • NtStmt
  • NtTy
  • NtMeta
  • NtPath
  • NtVis
  • NtLiteral

Of these nonterminals, only NtStmt and NtLiteral (which is actually just an Expr), support outer attributes - the rest only ever have token capturing perform when they match a macro_rules! argument.

This makes progress towards solving #43081 - we now collect tokens for everything that might need them. However, we still need to handle #[cfg], inner attributes, and misc pretty-printing issues (e.g. #75734)

I've separated the changes into (mostly) independent commits, which could be split into individual PRs for each Nonterminal variant. The purpose of having them all in one PR is to do a single Crater run for all of them.

Most of the changes in this PR are trivial (adding tokens: None everywhere we construct the various AST structs). The significant changes are:

  • ast::Visibility is changed from type Visibility = Spanned<VisibilityKind> to a struct Visibility { kind, span, tokens }.
  • maybe_collect_tokens is made generic, and used for both ast::Expr and ast::Stmt.
  • Some of the statement-parsing functions are refactored so that we can capture the trailing semicolon.
  • Nonterminal and Expr both grew by 8 bytes, as some of the structs which are stored inline (rather than behind a P) now have an Option<TokenStream> field. Hopefully the performance impact of doing this is negligible.

@rust-highfive
Copy link
Contributor

r? @ecstatic-morse

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 22, 2020
@Aaron1011
Copy link
Member Author

r? @petrochenkov

@Aaron1011
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Collaborator

bors commented Aug 22, 2020

⌛ Trying commit f1624da705b3b5c569ab49f0560c22e652b9f3ad with merge 249ff4f3249e07e4b951856c7d9938186efce584...

@bors
Copy link
Collaborator

bors commented Aug 22, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 249ff4f3249e07e4b951856c7d9938186efce584 (249ff4f3249e07e4b951856c7d9938186efce584)

@rust-timer
Copy link
Collaborator

Queued 249ff4f3249e07e4b951856c7d9938186efce584 with parent de521cb, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (249ff4f3249e07e4b951856c7d9938186efce584): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@Aaron1011
Copy link
Member Author

Even if this PR doesn't land in its current form, we'll want to make this change eventually. Let's see what the breakage looks like.

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-75800 created and queued.
🤖 Automatically detected try build 249ff4f3249e07e4b951856c7d9938186efce584
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 22, 2020
@petrochenkov petrochenkov added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 22, 2020
@petrochenkov
Copy link
Contributor

Code LGTM, perf is acceptable, so only waiting for crater.

@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 22, 2020
@bors
Copy link
Collaborator

bors commented Aug 23, 2020

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

@Aaron1011 Aaron1011 force-pushed the feature/full-nt-tokens branch from b681f77 to 6da31a8 Compare August 24, 2020 16:44
@Aaron1011
Copy link
Member Author

@bors try

@bors
Copy link
Collaborator

bors commented Aug 24, 2020

⌛ Trying commit 6da31a8b9bc332944b69d94c9c28ca5b61ad3dc4 with merge fb5211a6951b98ccbb5503375fa78704f59200fe...

@bors
Copy link
Collaborator

bors commented Aug 24, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: fb5211a6951b98ccbb5503375fa78704f59200fe (fb5211a6951b98ccbb5503375fa78704f59200fe)

@Aaron1011
Copy link
Member Author

@craterbot abort

@craterbot
Copy link
Collaborator

🗑️ Experiment pr-75800 deleted!

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 24, 2020
A `Visibility` does not have outer attributes, so we only capture tokens
when parsing a `macro_rules!` matcher
We currently only attach tokens when parsing a `:stmt` matcher for a
`macro_rules!` macro. Proc-macro attributes on statements are still
unstable, and need additional work.
@bors

This comment has been minimized.

This commit contains miscellaneous changes that don't fit into any of
the other commits in this PR
@Aaron1011 Aaron1011 force-pushed the feature/full-nt-tokens branch from cdbaf88 to fec0479 Compare September 10, 2020 21:58
@Aaron1011 Aaron1011 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 10, 2020
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 10, 2020

📌 Commit fec0479 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 10, 2020
@bors
Copy link
Collaborator

bors commented Sep 11, 2020

⌛ Testing commit fec0479 with merge 3673b18616a0a8abaf68ff34da09037d9c42ccfe...

@bors
Copy link
Collaborator

bors commented Sep 11, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 11, 2020
@Aaron1011
Copy link
Member Author

2020-09-11T01:55:37.4205616Z test process::tests::set_current_dir_works ... ok
2020-09-11T01:55:37.5548862Z �[0m�[0m�[1m�[31merror�[0m�[1m:�[0m test failed, to rerun pass '-p std --lib'
2020-09-11T01:55:37.5549312Z 
2020-09-11T01:55:37.5549575Z Caused by:
2020-09-11T01:55:37.5551189Z   process didn't exit successfully: `/checkout/obj/build/tmp/distcheck/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-2996f0f88f1190de` (signal: 11, SIGSEGV: invalid memory reference)
2020-09-11T01:55:37.5571913Z 
2020-09-11T01:55:37.5572407Z 
2020-09-11T01:55:37.5575181Z command did not execute successfully: "/checkout/obj/build/tmp/distcheck/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "16" "--release" "--locked" "--frozen" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/obj/build/tmp/distcheck/library/test/Cargo.toml" "-p" "std" "--"
2020-09-11T01:55:37.5577464Z expected success, got: exit code: 101
2020-09-11T01:55:37.5577757Z 
2020-09-11T01:55:37.5577908Z 
2020-09-11T01:55:37.5584916Z failed to run: /checkout/obj/build/tmp/distcheck/build/bootstrap/debug/bootstrap test --stage 2
2020-09-11T01:55:37.5585653Z Build completed unsuccessfully in 0:27:49
2020-09-11T01:55:37.5674366Z make: *** [check] Error 1
2020-09-11T01:55:37.5675254Z Makefile:42: recipe for target 'check' failed
2020-09-11T01:55:37.5675789Z 
2020-09-11T01:55:37.5676174Z 
2020-09-11T01:55:37.5676639Z command did not execute successfully: "make" "check"
2020-09-11T01:55:37.5677157Z expected success, got: exit code: 2
2020-09-11T01:55:37.5677429Z 
2020-09-11T01:55:37.5677609Z 
2020-09-11T01:55:37.5690417Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test distcheck
2020-09-11T01:55:37.5691477Z Build completed unsuccessfully in 0:29:46
2020-09-11T01:55:37.5810819Z == clock drift check ==
2020-09-11T01:55:37.5820379Z   local time: Fri Sep 11 01:55:37 UTC 2020
2020-09-11T01:55:37.7287572Z   network time: Fri, 11 Sep 2020 01:55:37 GMT
2020-09-11T01:55:37.7288224Z == end clock drift check ==
2020-09-11T01:55:38.1083046Z ##[error]Process completed with exit code 1.
2020-09-11T01:55:38.1112763Z Cleaning up orphan processes
2020-09-11T01:55:38.2327184Z Terminate orphan process: pid (5505) (node)
2020-09-11T01:55:38.2354662Z Terminate orphan process: pid (5514) (python)

This looks somewhat concerning, but seems unrelated to this PR.

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 11, 2020
@bors
Copy link
Collaborator

bors commented Sep 11, 2020

⌛ Testing commit fec0479 with merge 94b4de0...

@bors
Copy link
Collaborator

bors commented Sep 11, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: petrochenkov
Pushing 94b4de0 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 11, 2020
@bors bors merged commit 94b4de0 into rust-lang:master Sep 11, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 11, 2020
bartlomieju pushed a commit to denoland/deno_doc that referenced this pull request Sep 14, 2020
The `doc_test!` macro defines two local variables (`entries` and `doc`),
which are then accessed from the provided `block`.

However, this only compiled due to a bug in rustc: substituted
metavariables cannot refer to names defined within the macro body. For
example, the following ode does not compile:

```rust
macro_rules! foo {
    ($block:expr) => {
        let mut bar = false;
        $block
    }
}

fn main() {
    foo!({bar = true});
}
```

In this case, the `doc_test!` macro was incorrectly allowed to compile
due to the presence of the `#[tokio::test]` macro on the enclosing
function. When the underlying compiler bug is fixed in
rust-lang/rust#75800,
this macro will stop compiling.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 24, 2020
…etrochenkov

Attach tokens to all AST types used in `Nonterminal`

We perform token capturing when we have outer attributes (for nonterminals that support attributes - e.g. `Stmt`), or when we parse a `Nonterminal` for a `macro_rules!` argument. The full list of `Nonterminals` affected by this PR is:

* `NtBlock`
* `NtStmt`
* `NtTy`
* `NtMeta`
* `NtPath`
* `NtVis`
* `NtLiteral`

Of these nonterminals, only `NtStmt` and `NtLiteral` (which is actually just an `Expr`), support outer attributes - the rest only ever have token capturing perform when they match a `macro_rules!` argument.

This makes progress towards solving rust-lang#43081 - we now collect tokens for everything that might need them. However, we still need to handle `#[cfg]`, inner attributes, and misc pretty-printing issues (e.g. rust-lang#75734)

I've separated the changes into (mostly) independent commits, which could be split into individual PRs for each `Nonterminal` variant. The purpose of having them all in one PR is to do a single Crater run for all of them.

Most of the changes in this PR are trivial (adding `tokens: None` everywhere we construct the various AST structs). The significant changes are:

* `ast::Visibility` is changed from `type Visibility = Spanned<VisibilityKind>` to a `struct Visibility { kind, span, tokens }`.
* `maybe_collect_tokens` is made generic, and used for both `ast::Expr` and `ast::Stmt`.
* Some of the statement-parsing functions are refactored so that we can capture the trailing semicolon.
* `Nonterminal` and `Expr` both grew by 8 bytes, as some of the structs which are stored inline (rather than behind a `P`) now have an `Option<TokenStream>` field. Hopefully the performance impact of doing this is negligible.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants