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

tidy watcher #114209

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

tidy watcher #114209

wants to merge 4 commits into from

Conversation

klensy
Copy link
Contributor

@klensy klensy commented Jul 29, 2023

MVP of tidy watcher:

Allows to check that changes to some pieces of text synced in different files (or at least warn about it). Should resolve situations like: "Oh no, I've changed that constant here and here, but forgot to update it in other 3 places."

Current state is very MVP'ish, so it simply works and nothing more, posted to get some feedback.

Usage: wrap text that need to be synced with arbitrarily chosen tags:

some.rs:

// tidy-ticket-foo
const FOO: usize = 42;
// tidy-ticket-foo

some.sh:

# tidy-ticket-foo
export FOO=42
# tidy-ticket-foo

and add them to watcher.rs in tidy, adding into one group:

    add_group!(
        ("src/tools/opt-dist/src/main.rs", "728c2783154a52a30bdb1d66f8ea1f2a", "tidy-ticket-perf-commit"),
        ("src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile", "76c8d9783e38e25a461355f82fcd7955", "tidy-ticket-perf-commit")
    ),

If hashes differs, actual and expected ones will be printed:

tidy error: The code blocks tagged with tidy watcher has changed.
It's likely that code blocks with the following tags need to be changed too. Check src/tools/tidy/src/watcher.rs, find t
ag/hash in TIDY_WATCH_LIST list and verify that sources for provided group of tags in sync. Once that done, run tidy aga
in and update hashes in TIDY_WATCH_LIST with provided actual hashes.
tidy error: hash for tag `tidy-ticket-sess-time-item_types_checking` in path `compiler/rustc_hir_analysis/src/lib.rs` mi
smatch:
  actual: `842e23fb65caf3a96681686131093316`, expected: `842e23fb65caf3a96681686131093317`
  Verify that tags `["tidy-ticket-sess-time-item_types_checking", "tidy-ticket-sess-time-item_types_checking"]` in sync.

Added check for PERF_COMMIT and few others as example.

r? @ghost

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jul 29, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Jul 30, 2023
@klensy
Copy link
Contributor Author

klensy commented Jul 30, 2023

Added few more entries a49ed53, but i don't know if all of them actually sync as of now, this should be reviewed.

@bors
Copy link
Contributor

bors commented Jul 31, 2023

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

@rustbot rustbot added the O-unix Operating system: Unix-like label Sep 7, 2023
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Sep 18, 2023

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

@klensy klensy marked this pull request as ready for review October 2, 2023 17:55
@rustbot
Copy link
Collaborator

rustbot commented Oct 2, 2023

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes might have occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@klensy
Copy link
Contributor Author

klensy commented Oct 2, 2023

Okay. Implementation is trivial, but most of asserted pieces of code in compiler, so r? compiler. Didn't checked if current state is sync, as i don't always understand whats functions do.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 2, 2023
@@ -149,6 +149,7 @@ where
None => {
// For unsized types with an extern type tail we perform no adjustments.
// NOTE: keep this in sync with `PlaceRef::project_field` in the codegen backend.
// FIXME: that one? compiler/rustc_codegen_ssa/src/mir/place.rs
Copy link
Member

@RalfJung RalfJung Oct 2, 2023

Choose a reason for hiding this comment

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

Specifically this:

_ if self.llextra.is_none() => {
debug!(
"unsized field `{}`, of `{:?}` has no metadata for adjustment",
ix, self.llval
);
return simple();
}

I don't see how an automatic checker can help here. This is about keeping the semantics in sync.

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 just run over codebase, found few comments like "keep in sync with" and wrapped them in tags. Of course this check can't say if two places is valid, only ping author to give it chance to check things manually.

@RalfJung
Copy link
Member

RalfJung commented Oct 2, 2023

If hashes differs, actual and expected ones will be printed:

This needs to give very clear guidance on what I should do now, otherwise it will be very frustrating.

@klensy
Copy link
Contributor Author

klensy commented Oct 2, 2023

If hashes differs, actual and expected ones will be printed:

This needs to give very clear guidance on what I should do now, otherwise it will be very frustrating.

It slightly more descriptive, forgot to update first message, but can be improved.

@@ -1144,6 +1150,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
})
}

// tidy-ticket-wildcards
Copy link
Member

Choose a reason for hiding this comment

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

I would have expected that we reuse the tag for all the places that need to be in sync. E.g. if I modify wildcards() here and not arity(), it would ping me "you should also check arity".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added grouping for tags, should write

tidy error: hash for tag `tidy-ticket-ast-from_token` in path `compiler/rustc_ast/src/token.rs` mismatch:
  actual: `eecacc0fe4c615f7c71409c3ebfcff80`, expected: `70666de80ab0194a67524deeda3c01b8`
  Verify that tags `["tidy-ticket-ast-from_token", "tidy-ticket-ast-can_begin_literal_maybe_minus", "tidy-ticket-rustc_p
arse-can_begin_literal_maybe_minus"]` in sync.

Copy link
Member

Choose a reason for hiding this comment

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

Nice! Could you make it explain what it's about for those who don't know? Something like: "the code block tagged with tidy-ticket-ast-from_token has changed. It's likely that code blocks with the following tags need to be changed too. Once that is done, run tidy again with the --blessed flag to update the hashes. The related tags are ["tidy-ticket-ast-from_token", "tidy-ticket-ast-can_begin_literal_maybe_minus", "tidy-ticket-rustc_parse-can_begin_literal_maybe_minus"]"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tidy-keep-sync-with= and updated error message with parts from your suggestion.

@Nadrieril
Copy link
Member

Nadrieril commented Oct 2, 2023

The tag should have a name that explains what it's for if we encounter it in code. Something like tidy-keep-sync-with=<tag>.

@klensy
Copy link
Contributor Author

klensy commented Oct 4, 2023

The tag should have a name that explains what it's for if we encounter it in code. Something like tidy-keep-sync-with=<tag>.

Don't want to implement smarter parsing for tags (at least for now), can just make it longer, like tidy-keep-sync-try_visit_primitive tidy-keep-sync-visit_value?

Anyway, accidental removing of tag from code will enrage tidy, which will say something special about it.

@Nadrieril
Copy link
Member

Nadrieril commented Oct 4, 2023

You don't need to do any parsing, just allow "=" in the list of allowed symbols in a tag. I just think it's more legible

@Nadrieril
Copy link
Member

You might want to wait and see if compiler contributors actually want this before investing more time in it though. As far as I am concerned this adds unnecessary friction; I'm waiting to hear from ppl who work on files where this would be helpful.

@klensy
Copy link
Contributor Author

klensy commented Oct 25, 2023

@klensy this is a compile-time check, correct? At a very high level, what's the difference between using this static watchlist and getting errors when compiling? Are you trying to keep in sync pieces of code that otherwise would not emit errors when out of sync?

Yes, this is for code that will not emit errors; for example git hash for rustc-perf in dockerfile and opt-dist, or code commented in style "please keep me in sync", which will not immediately cause errors, but will silently do wrong things; or assert pieces in rust, bash, python code simultaneously (which will hard to sync other way).

Also, what would the added computational cost be? Did you already run some benches?

This is tidy lint, so works only when tidy runs; this lint reads only specifically listed files (not all files in repo), so cost should be almost zero.

@apiraino
Copy link
Contributor

T-compiler visited this PR during the weekly triage meeting (Zulip notes).

The idea is really cool and worth pursuing. Though the question could be where this static list could reside. Maybe at the LLVM level? We have our fork of LLVM, so tagging @rust-lang/wg-llvm for a comment.

@rustbot label -I-compiler-nominated

@rustbot rustbot removed the I-compiler-nominated Nominated for discussion during a compiler team meeting. label Oct 26, 2023
@cuviper
Copy link
Member

cuviper commented Oct 26, 2023

Though the question could be where this static list could reside. Maybe at the LLVM level?

There's nothing specific to LLVM here, but what I got from that discussion is that there are also some things that we want to keep in sync with LLVM -- and maybe we could annotate those in our rust-lang/llvm-project fork.

@pnkfelix
Copy link
Member

Though the question could be where this static list could reside. Maybe at the LLVM level?

There's nothing specific to LLVM here, but what I got from that discussion is that there are also some things that we want to keep in sync with LLVM -- and maybe we could annotate those in our rust-lang/llvm-project fork.

Yes, I was specifically thinking of this bit of feedback I had put onto a recent code review I was doing: #113923 (comment)

@bors
Copy link
Contributor

bors commented Oct 28, 2023

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

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 11, 2023

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

@cjgillot
Copy link
Contributor

r? compiler

@rustbot rustbot assigned petrochenkov and unassigned cjgillot Dec 17, 2023
@petrochenkov
Copy link
Contributor

r? compiler

@rustbot rustbot assigned TaKO8Ki and unassigned petrochenkov Dec 17, 2023
@wesleywiser
Copy link
Member

r? wesleywiser

@rustbot rustbot assigned wesleywiser and unassigned TaKO8Ki Dec 21, 2023
@apiraino
Copy link
Contributor

@klensy in the meanwhile, could you please rebase this? thanks

@Dylan-DPC Dylan-DPC added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 25, 2024
@alex-semenyuk
Copy link
Member

@klensy
From wg-triage. Do you have any updates on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc O-unix Operating system: Unix-like S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.