-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustbuild: x.py fmt src/tools/rustfmt
doesn't format code in the rustfmt subtree
#90672
Comments
It's explicitly excluded (like other subtrees), because rustfmt's tests probably are using a different rustfmt to x.py fmt? https://github.com/rust-lang/rust/blob/master/rustfmt.toml#L36 Do you have a pointer to the tests in rustfmt that check it's own source code? |
|
Hm. Yeah, so looks like we will probably end up fighting ourselves at some point if we try to format with x.py fmt, but if we don't then this kind of error will also appear. @rust-lang/wg-rustfmt, do you think this test adds a lot of value? It may make sense to just remove it -- the rustfmt source code is probably not terribly interesting from a formatting perspective. |
I've mentioned before that I think we might want to consider using the in-tree version of rustfmt to format the rustfmt tree in this repo now that it's a If this is dropped and/or rustfmt source is formatted with a different/older version then what happens in r-l/rustfmt then I see it adding undo complexity and increased merge conflicts on those syncs |
that test is also the only viable mechanism we have for enforcing formatting consistency of our own code in the main repo where the development happens on that code, so it's pretty important from that perspective too 😄 |
That would require everyone building rustfmt locally, right? That doesn't seem feasible.
I was suggesting we remove the test entirely, and that upstream rustfmt repo check formatting in CI against the same version used locally in rust-lang/rust (perhaps by reading - via GitHub API - src/stage0.json or something; or just pinning and manually bumping from time to time the nightly used). |
FWIW it might make sense to format |
That's the type of thing I was referring to as well, though not sure how feasible/difficult it would be to have it only run on some explicit invocation/conditional flag.
I still feel the same, and am not keen on adding this type of complexity and sacrificing a test that is important to rustfmt. In general I don't think folks should be making too many changes to subtrees over here, certainly not to the extent that this is a significant problem as opposed to an occasional paper cut. We'd have a new chunk of work to do on the rustfmt side (some x.py equivalent to ensure folks can locally run the same, older version) and we'd lose the only test that has idempotency checks against an actual codebase. That's quite literally a step in the wrong direction of where I want to take our testing. |
I could live with an update to the test that conditionally skips execution, e.g. when RUSTC_BOOTSTRAP is set so that it doesn't impact folks over here. I would feel even more comfortable about that if we could get the bots to still ping teams if submod/subtree changes are added after the PR opens and/or if we could find another way to be more proactively kept in the loop on subtree changes that get made in this repo |
I looked into this and it was trickier than expected. If we build rustfmt unconditionally, it means building the whole compiler on each @Mark-Simulacrum at one point suggested having ~everything be downloadable from CI if it hasn't been modified. I wonder if we could start downloading rustfmt and using stage 2 unconditionally (falling back to building when it's been changed)? Then we naturally get what we want:
|
I suspect that in many cases this wouldn't be true? rustfmt doesn't dynamically link against the locally compiled code (and probably that's not really possible), so any changes in rustc wouldn't be picked up by rustfmt. Changes to rustfmt code that rely on rustc would cause a recompile and reformat, but at that point you might as well just build rustfmt (via x.py) and adjust config.toml to point at the built copy temporarily. In CI, I'm happy to have us have some builder that does this (builds rustfmt and then re-formats the repo, failing if there are any changes), it should be relatively fast to add that to e.g. the tools builder, since it's not doing much work on top of building rustfmt to format things. This could even be part of the rustfmt test step, for example. |
Oh I see, you're worried about changes to rustc_parser or lexer impacting rustfmt. We could have some logic to rebuild from source if those crates change (no need to rebuild if any part of compiler/ changed IMO).
That requires you to It's certainly better than nothing, but I think doing this automatically with bootstrap is not too terribly much effort and a lot more user friendly. That said, a) is solved by having a builder that enforces you do this ... willing to be convinced. |
Parser and lexer are part of compiler/, and I'd rather not maintain a mapping of interesting crates -- we can't readily extract it from rustfmt due to it pulling from sysroot rather than declaring in Cargo.toml. The list is somewhat longer than just those two: rust/src/tools/rustfmt/src/lib.rs Lines 17 to 25 in 1f5d8d4
I think, in general, the likelihood that your changes affect rustfmt is low. Forcing anyone editing these crates to rebuild rustfmt just to format their code is a huge speed bump, and the flow with a CI check (we can make it happen even in the llvm-12 builder, I guess) would be just "x.py test src/tools/rustfmt", which gives you a diff you need to remove. I think the comparative benefit of catching this "earlier" and the cost of forcing re-building format is not a tradeoff that makes sense to make in favor of rebuilding. It should be even rarer that your changes create a diff in rustfmt's output and you want to re-bless the code. At least according to my understanding, most changes should be treated as bugs in the PR. And we can support re-blessing with x.py test src/tools/rustfmt --bless, since we already do that with e.g. compiletest UI tests. |
Makes sense to me :) Mentoring instructions: I believe
|
I don't think I don't think we should make |
Currently we don't format any code in subtrees (there's some config in I don't think we should start formatting with a two different rustfmts, that seems likely to break. I guess this is a question for @calebcartwright though: if a later rustfmt disagrees with an earlier rustfmt on formatting, is that always a bug? I know sometimes rustfmt learns new syntax and that's ok, mostly want to avoid the earlier rustfmt changing it back to how it was before, which would break our CI with the setup @Mark-Simulacrum suggested. |
OK, sure, that makes sense -- we definitely shouldn't break |
tbh, I'm not entirely sure I follow all of the proposals and associated implications as I don't typically do much work in this repository beyond the subtree syncs. However, as I see it the original impetus for this is really about the inner dev loop experience when contributors also have to modify the rustfmt source in tree, and that ties back to a test we have in rustfmt that's critical to the CI and inner dev loop experience for rustfmt contributors in r-l/rustfmt (it's our mechanism to ensure the rustfmt source is properly formatted, our equivalent of I still believe that the most direct path to addressing the original item is what I mentioned in #90672 (comment). We've already got other rustfmt tests that are intentionally skipped during Rust's CI in this repo, and I believe Clippy does this for certain tests too. I also acknowledge that the broader proposals discussed above around revamping how/where automated formatting is applied in this repo would also have the effect of addressing the original item. However, I feel like those also introduce a broader set of considerations and potential complexity/drawbacks. If there's a need/desire for those broader changes to provide more general improvements to formatting in this repo then fair enough, but if the main focus is just the original scenario then I'd reiterate my prior recommendation. I think that's the simplest option with a very, very low ceiling of potential impact (worst case scenario is that I occasionally need to add an extra commit on subtree pushes)
Short answer is no, though there's a lot of caveats and nuance. I typically recommend folks think about it this way: So long as you are exclusively using default config options, you should never see an earlier version of rustfmt vN-1 want to change formatting emitted by a newer version of rustfmt vN. The reverse mostly holds true as well but that's where the important nuance comes into play that's probably not worth delving into here (especially since this comment is already approaching novel-length). However, this repo is using several non-default option values, notably Again if that's the right change for this repository then I'll learn to deal with it, but I'd worry it could complicate our ability to perform syncs/increase odds of merge conflicts that typically require restarting the entire sync workflow |
Split some functions with many arguments into builder pattern functions r? `@estebank` This doesn't resolve all of the ones in rustc, mostly because I need to do other cleanups in order to be able to use some builder derives from crates.io Works around rust-lang#90672 by making `x test rustfmt --bless` format itself instead of testing that it is formatted
I added While we figure out what to do, this makes it at least easy to bless rustfmt |
Split some functions with many arguments into builder pattern functions r? `@estebank` This doesn't resolve all of the ones in rustc, mostly because I need to do other cleanups in order to be able to use some builder derives from crates.io Works around rust-lang/rust#90672 by making `x test rustfmt --bless` format itself instead of testing that it is formatted
Split some functions with many arguments into builder pattern functions r? `@estebank` This doesn't resolve all of the ones in rustc, mostly because I need to do other cleanups in order to be able to use some builder derives from crates.io Works around rust-lang/rust#90672 by making `x test rustfmt --bless` format itself instead of testing that it is formatted
rustfmt
's tests require its source code to be properly formatted, but when making changes to rustfmt through its subtree in rust-lang/rust, it seems like there's no way to do such formatting automatically.@jyn514 suggests that
x.py fmt src/tools/rustfmt
should just work and do the formatting, and it's probably just a missing step insrc/bootstrap/fmt.rs
that prevents it from working.The text was updated successfully, but these errors were encountered: