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

parser: Collect tokens for values in key-value attributes #81337

Merged
merged 1 commit into from
Jan 24, 2021

Conversation

petrochenkov
Copy link
Contributor

Fixes #81208 which happens when we parse the attribute value for the second time with an overridden span to synthesize tokens.

It also may be faster to collect tokens instead of re-synthesizing them.

@rust-highfive
Copy link
Collaborator

r? @davidtwco

(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 Jan 24, 2021
@petrochenkov
Copy link
Contributor Author

@bors try @rust-timer queue
r? @Aaron1011

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rust-highfive rust-highfive assigned Aaron1011 and unassigned davidtwco Jan 24, 2021
@bors
Copy link
Contributor

bors commented Jan 24, 2021

⌛ Trying commit bd07165 with merge 2d1533fed9e0f5f4c94ef0bf054bd1fb1bd8dbfc...

@bors
Copy link
Contributor

bors commented Jan 24, 2021

☀️ Try build successful - checks-actions
Build commit: 2d1533fed9e0f5f4c94ef0bf054bd1fb1bd8dbfc (2d1533fed9e0f5f4c94ef0bf054bd1fb1bd8dbfc)

@rust-timer
Copy link
Collaborator

Queued 2d1533fed9e0f5f4c94ef0bf054bd1fb1bd8dbfc with parent 72c7b70, future comparison URL.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 24, 2021
@Aaron1011
Copy link
Member

Can you also update rustc_ast_lowering to stop passing CanSynthesizeMissingTokens::Yes?

@petrochenkov
Copy link
Contributor Author

@Aaron1011
I tried it, but it causes panics because tokens still need to be synthesized when the value is a result of macro expansion, e.g. #[attr = concat!("a", "b")].

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (2d1533fed9e0f5f4c94ef0bf054bd1fb1bd8dbfc): 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
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 24, 2021
@Aaron1011
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 24, 2021

📌 Commit bd07165 has been approved by Aaron1011

@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 Jan 24, 2021
@bors
Copy link
Contributor

bors commented Jan 24, 2021

⌛ Testing commit bd07165 with merge 1d0d76f...

@bors
Copy link
Contributor

bors commented Jan 24, 2021

☀️ Test successful - checks-actions
Approved by: Aaron1011
Pushing 1d0d76f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 24, 2021
@bors bors merged commit 1d0d76f into rust-lang:master Jan 24, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 24, 2021
@wesleywiser wesleywiser added beta-nominated Nominated for backporting to the compiler in the beta channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 25, 2021
@camelid camelid added the A-parser Area: The parsing of Rust source code to an AST label Jan 25, 2021
@apiraino apiraino added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jan 28, 2021
@ehuss
Copy link
Contributor

ehuss commented Feb 5, 2021

@petrochenkov or @Aaron1011, this does not apply cleanly to the beta branch. Do you have some guidance on making it work? The issue is that collect_tokens on beta returns a tuple (expr, tokens), whereas on master it just returns an expr. Just ignoring the tokens didn't seem to work (it ICE'd).

This is somewhat time sensitive since beta will be rolling out soon.

@Aaron1011
Copy link
Member

@ehuss: On beta, you should do expr.tokens = Some(tokens).

@ehuss
Copy link
Contributor

ehuss commented Feb 5, 2021

Hmm, the following change (on top of this PR):

diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs
index 760e141b1be..501b6d61e61 100644
--- a/compiler/rustc_parse/src/parser/mod.rs
+++ b/compiler/rustc_parse/src/parser/mod.rs
@@ -974,7 +974,8 @@ fn parse_mac_args_common(&mut self, delimited_only: bool) -> PResult<'a, MacArgs
                     }

                     // Collect tokens because they are used during lowering to HIR.
-                    let expr = self.collect_tokens(|this| this.parse_expr())?;
+                    let (mut expr, tokens) = self.collect_tokens(|this| this.parse_expr())?;
+                    expr.tokens = tokens;
                     let span = expr.span;

                     match &expr.kind {

results in the error:

error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte
  --> /home/eric/Proj/rust-beta/src/test/ui/attributes/key-value-non-ascii.rs:3:19
   |
LL | #[rustc_dummy = b"ffi.rs"] //~ ERROR byte constant must be ASCII
   |                   ^

thread 'rustc' panicked at 'assertion failed: bpos.to_u32() >= mbc.pos.to_u32() + mbc.bytes as u32', compiler/rustc_span/src/lib.rs:1489:17

Did I misinterpret what you meant?

@Aaron1011
Copy link
Member

That change looks correct - I'm not sure why the ICE is still happening.
cc @estebank @petrochenkov

@petrochenkov
Copy link
Contributor Author

The change looks correct to me too (except that we do if expr.tokens.is_none() { expr.tokens = tokens } instead of assigning tokens unconditionally).
I can check what happens, but not earlier than Feb 7.

@petrochenkov
Copy link
Contributor Author

@Aaron1011 Looks like on beta the pretty-print-reparse hack is not removed yet, so b"ffi.rs" is lexed for the second time (and produces an ICE) unconditionally.

@ehuss I suggest to backport this fragment petrochenkov@e4e460b of #81307 instead, it fixes the underlying problem with span arithmetic.

@pietroalbini
Copy link
Member

@petrochenkov cherry-picked that commit into the stable PR!

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 8, 2021
…lbini

Rust 1.50.0 stable release

This PR builds the artifacts for the 1.50.0 stable release, and:

* Cherry-picks e4e460b to fix rust-lang#81208, as recommended in rust-lang#81337 (comment).
* Backports the release notes of 1.49.0 and 1.50.0.

r? `@ghost`
cc `@rust-lang/release`
@pietroalbini pietroalbini removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST beta-accepted Accepted for backporting to the compiler in the beta channel. 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE with non-ascii byte string in #[path] attribute