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

upgrade rustc-ap-* version to v642 #4022

Merged
merged 22 commits into from
Feb 10, 2020

Conversation

calebcartwright
Copy link
Member

@calebcartwright calebcartwright commented Jan 16, 2020

I structured the changes into several smaller commits that were focused on a specific change/related set of changes in the upstream rustc crates, and included details about the upstream change in the commit messages (hope this makes it somewhat easier to review!).

I decided to focus on getting rustfmt to just "work" with the latest rustc crate versions, and defer making certain other changes (like refactoring, supporting the new half open range syntax - #4009, etc.) to future PRs. My thinking is defering those other changes will hopefully make this easier to merge since there's already a decent sized diff just from upgrading the rustc-ap versions, and I suspect this PR has a higher potential than normal for merge conflicts

syntax_pos was renamed to rustc_span
rust-lang/rust#67707

and modules like `symbol` and `source_map` are no longer re-exported in
libsyanx so we also need to consume them directly from the rustc_span
crate
rust-lang/rust#67786
several mods from libsyntax have been split out into separate crates,
including the `parse` mod
rust-lang/rust#65324
TraitItem/ImplItem were combined to `AssocItem`, along with their
respecitve `*Kind`'s, the `Method` variant was also renamed to `Fn` in
the new `AssocItemKind`

rust-lang/rust#67131
`Mutability` variants were renamed to `Not` and `Mut`
rust-lang/rust#67355
implicit pprust dependencies were removed and now require explicit usage
rust-lang/rust#65363
AFAICT these changes are required based on the changes `LocalInternedString` and `SymbolStr` in
rust-lang/rust#65776
@calebcartwright
Copy link
Member Author

@topecongiro - most of the tests that are failing are due to an extra semicolon being inserted on macros that have a paren or bracket delim, and I'm not sure why that's happening 🤔

 impl Foo {
-    add_fun!();
+    add_fun!();;
 }

Any suggestions on the best way to address that? I could fix most of them by removing the explicit semicolon insertion but I don't think that's the right solution.

if ts.is_empty() && !has_comment {
return match style {
DelimToken::Paren if position == MacroPosition::Item => {
Some(format!("{}();", macro_name))
}
DelimToken::Bracket if position == MacroPosition::Item => {
Some(format!("{}[];", macro_name))
}

@topecongiro
Copy link
Contributor

@calebcartwright I had a similar issue in the past, and IIRC it was due to the change to the span. In this case, it could be that in 610, the span of macro didn't contain the trailing semicolon, whereas, in 638, the span contains it.

@calebcartwright
Copy link
Member Author

You are right @topecongiro, that is exactly what's happening

@calebcartwright calebcartwright force-pushed the rustc-ap-v638 branch 2 times, most recently from 86d7fb4 to 657c336 Compare January 18, 2020 05:47
@@ -0,0 +1,2 @@
a_macro!(name<Param1, Param2>,
Copy link
Member Author

Choose a reason for hiding this comment

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

apparently the trailing whitespace is now actually being trimmed, so creating a test file under source directory with the trailing whitepsace to keep the test case valid since the end formatting result in the file under target has the whitepsace removed


// 1 = ;
let shape = self.shape().saturating_sub_width(1);
let rewrite = self.with_context(|ctx| rewrite_macro(mac, ident, ctx, shape, pos));
self.push_rewrite(mac.span, rewrite);
let (span, rewrite) = match macro_style(mac, &self.get_context()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is to address the change in this version of the rustc-ap creates where the span no longer includes the associated ; (#4022 (comment)). Wasn't sure what the best solution to this would be, so figured I'd try to just get the "correct" span to include the ; when warranted, so that Mac items that have whitespace between the closing delim and the semicolon are still formatted correctly (i.e. ) ; is still formatted to );)

} else {
rw
}
});
Copy link
Member Author

Choose a reason for hiding this comment

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

This was done to fix two snippets that were failing in the tests due to the ; being stripped. I think that was related to the same span change around missing semis so correcting it here.

The two failing snippets without this were:

gfx_pipeline!(pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
out: gfx::RenderTarget<ColorFormat> = "Target0",
});

and

a_macro!(name<Param1, Param2>,
);

Copy link
Member Author

@calebcartwright calebcartwright Jan 18, 2020

Choose a reason for hiding this comment

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

Note that on both master and rustfmt 1.x that any whitespace between the closing delim and semi is not currently removed for these two snippets, so I think this actually fixes a very minor existing issue.

For example with the below/linked snippet, the whitespace between the delim and semi remains after formatting with 1.x and master:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=649ebcbc83ba416d42392084d91ba266

gfx_pipeline!(pipe { 
     vbuf: gfx::VertexBuffer<Vertex> = (), 
     out: gfx::RenderTarget<ColorFormat> = "Target0", 
 })       ;

I enhanced those two test snippets to ensure that rustfmt removes that extra whitespace

@calebcartwright calebcartwright marked this pull request as ready for review January 18, 2020 06:01
@calebcartwright calebcartwright changed the title [WIP] upgrade rustc-ap-* versions upgrade rustc-ap-* version to v638 Jan 18, 2020
Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! Looks good to me with some minor nits addressed.

@matthiaskrgr
Copy link
Member

Rustfmt in the rustc repo just broke rust-lang/rust#68917
I guess we'd need to update to 64*.0.0 to get it working again.

@calebcartwright
Copy link
Member Author

I'll work on bumping this up to a 64*.0.0 version, and hopefully @topecongiro will be available to merge.

I believe I'd likely then need to backport this on top of the 1.4.11 branch though to fix the issue in the rustc repo, since this is targetting the new 2.x version of rustfmt on master which I don't believe is ready for release

@calebcartwright calebcartwright changed the title upgrade rustc-ap-* version to v638 upgrade rustc-ap-* version to v641 Feb 8, 2020
@calebcartwright
Copy link
Member Author

Believe we'll need an early bump of the rustc-ap-* crates to pull in the box_region changes for rustc_data_structures to be able to compile, otherwise we'll have to wait for v642 to get published on Tuesday.

Refs: alexcrichton/rustc-auto-publish#16

@calebcartwright calebcartwright changed the title upgrade rustc-ap-* version to v641 upgrade rustc-ap-* version to v642 Feb 8, 2020
@topecongiro topecongiro merged commit 4e8ed17 into rust-lang:master Feb 10, 2020
@topecongiro
Copy link
Contributor

@calebcartwright My apologies for the late reply, I have been busy with my private life. Thank you so much for all the work!

@calebcartwright
Copy link
Member Author

@calebcartwright My apologies for the late reply, I have been busy with my private life. Thank you so much for all the work!

No worries, and my pleasure!

@karyon
Copy link
Contributor

karyon commented Oct 26, 2021

Backport not needed

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

Successfully merging this pull request may close these issues.

4 participants