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

rustc_parse: More precise spans for tuple.0.0 #77774

Merged
merged 1 commit into from
Oct 11, 2020

Conversation

petrochenkov
Copy link
Contributor

This should help with rust-lang/rustfmt#4355, but I haven't verified, cc @calebcartwright.

@rust-highfive
Copy link
Collaborator

r? @estebank

(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 Oct 9, 2020
@petrochenkov
Copy link
Contributor Author

The rustfmt issue looks severe enough to beta-backport this (if this PR is confirmed to fix it).

@petrochenkov petrochenkov 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 Oct 9, 2020
@camelid camelid added the A-parser Area: The parsing of Rust source code to an AST label Oct 10, 2020
@calebcartwright
Copy link
Member

The rustfmt issue looks severe enough to beta-backport this (if this PR is confirmed to fix it).

Thanks for the ping @petrochenkov. If this lands before Tuesday (08:00 UTC) then it'll be in the next release of the rustc-ap crates which we can pull into rustfmt to confirm it resolves rust-lang/rustfmt#4355.

Would be tough to validate beforehand though because with the current model it's usually pretty painful to test rustc changes within rustfmt outside the auto publish process.

@calebcartwright
Copy link
Member

Actually can confirm this will indeed resolve rust-lang/rustfmt#4355

We were already using a relatively up-to-date version of the rustc-ap crates so it wasn't too difficult to validate

let span = self.token.span;
let span_is_good = || self.span_to_snippet(span).as_deref() == Ok(float_str).as_deref();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry that this span_to_snippet might be too expensive in the parser. Can't we instead look at self.token.kind? Of course, this would be called in an uncommon enough codepath that it wouldn't be too bad, but I would prefer to avoid any unnecessary perf expense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The span can point anywhere regardless of the self.token.kind, and for an arbitrary span span.lo + 1 can potentially point e.g. in the middle of a UTF-8 encoded code point.
So, I'm afraid that actually looking into the source map is the only reliable way to determine that you can do arithmetic operations on that span.

Of course, this would be called in an uncommon enough codepath

Yes, that's what I hope for, tuple.0.0 is a rare syntactic construction.
Hopefully we'll be able to migrate to more fine-grained tokens ~next year, then the whole parse_tuple_field_access_expr_float could be eliminated.

match &*components {
// 1e2
[IdentLike(i)] => {
self.parse_tuple_field_access_expr(lo, base, Symbol::intern(&i), suffix, None)
}
// 1.
[IdentLike(i), Punct('.')] => {
let (ident_span, dot_span) = if span_is_good() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename span_is_good to span_is_not_through_macro or something else more descriptive? Even though the diff is easy to follow, it'll be hard to understand what this means on isolation, and the comment explaining why is not next to the closure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've expanded the comment a bit.
(I don't think it's not about macros exactly, just about dangers of arithmetic with arbitrary spans.)

@estebank
Copy link
Contributor

r=me, preferably with both nitpicks addressed.

@petrochenkov
Copy link
Contributor Author

@bors r=estebank

@bors
Copy link
Contributor

bors commented Oct 10, 2020

📌 Commit dee7049 has been approved by estebank

@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 Oct 10, 2020
@bors
Copy link
Contributor

bors commented Oct 11, 2020

⌛ Testing commit dee7049 with merge 9a8ca69...

@bors
Copy link
Contributor

bors commented Oct 11, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: estebank
Pushing 9a8ca69 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 11, 2020
@bors bors merged commit 9a8ca69 into rust-lang:master Oct 11, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 11, 2020
pymongo added a commit to pymongo/learn_rust that referenced this pull request Oct 12, 2020
@spastorino
Copy link
Member

discussed in T-compiler meeting.

@rustbot modify labels: beta-accepted

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Oct 15, 2020
@pietroalbini pietroalbini removed this from the 1.49.0 milestone Oct 20, 2020
@pietroalbini pietroalbini added this to the 1.48.0 milestone Oct 20, 2020
@pietroalbini pietroalbini removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Oct 20, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2020
[beta] Rollup backports

Cherry-picked:

*  Always use the Rust version in package names rust-lang#77336
*  rustc_parse: More precise spans for `tuple.0.0` rust-lang#77774
*  Update crossbeam-channel to avoid UB rust-lang#77819
*  build-manifest: stop generating numbered channel names except for stable rust-lang#77854
*  Dist build manifest rust-lang#77762
*  bootstrap: set correct path for the build-manifest binary rust-lang#77909

r? `@ghost`
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.

9 participants