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

Migrate "ui" test suite from legacy compiletest-style directives // to ui_test-style directives //@ #120881

Merged
merged 2 commits into from
Feb 16, 2024

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Feb 10, 2024

Preface

There's an on-going effort to rewrite parts of or the entirety of compiletest
(rust-lang/compiler-team#536). A step towards this involve migrating
ui tests to use the ui_test framework, which involves
changing compiletest directives in // <directive-name> style to ui_test //@ <directive-name>
style (rust-lang/compiler-team#512).

This PR aims to implement the directive-style change from // to //@ for ui tests only and
make compiletest only accept //@ directives in the "ui" test suite (only).

Key Changes

  1. All ui test // directives are replaced by //@ directives.
  2. Only accept //@ directives for "ui" test suite.
  3. Errors if a comment could be interpreted as a legacy-style // directive.

Diff Generation

The diff is generated by:

  • Collecting directives from ui tests via hacking on compiletest.
  • Using a migration tool to replace // directives in ui tests with //@.

Reproduction Steps

  1. Delete the temporary directory $RUSTC_REPO_PATH/build/x86_64-apple-darwin/test/ui/__directive_lines and the temporary file $RUSTC_REPO_PATH/build/x86_64-apple-darwin/test/ui/__directive_lines.txt (if you ran the collection script before).
  2. Use the https://github.com/jieyouxu/rust/tree/collect-test-directives collect-test-directives
    script, which outputs temporary files recording headers occuring in each ui test.
    • You need to checkout this branch: git checkout collect-test-directives.
    • You might need to rebase on lastest master and ensure there are no conflicts.
    • You likely need to run ./x test tests/ui --stage 1 --force-rerun to generate the temporary
      files consistently.
  3. Checkout the migrate-ui-test-directives branch.
  4. Run the migration tool https://github.com/jieyouxu/compiletest-ui_test-header-migration.
    • You will need to first generate a migration_config.toml via cargo run -- generate-config under $CWD.
    • Then, update manual_directives = ["// should-fail"] in migration_config.toml. This is required because the collection script doesn't deal with some special meta ui tests and there are no other // should-fail occurrences.
  5. Check that the migration at least does not cause UI test failures if you change compiletest to
    accept //@ directives for ui tests only.
    • RUSTC_TEST_FAIL_FAST=1 ./x test tests/ui --stage 1 --bless
  6. Confirm that there is no difference after running the migration tool when you are on the
    migrate-ui-test-directives branch.

Next Steps

  • Need to implement some kind of warning or tidy script to help contributors catch old-style
    // <directive-name> directives, while only accepting ui_test-style //@ <directive-name>
    directives.
    An error is emitted if a comment that could be interpreted as legacy-style test directive is encountered.
  • Need to properly document this change in e.g. rustc-dev-guide (Update docs about ui tests now using //@ headers rustc-dev-guide#1885).
    • Add a README.md to tests/ui describing the directive style change.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc 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. labels Feb 10, 2024
@fmease
Copy link
Member

fmease commented Feb 10, 2024

Lol, did rustbot just give up?
r? compiler

@oli-obk
Copy link
Contributor

oli-obk commented Feb 10, 2024

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned davidtwco Feb 10, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Feb 10, 2024

cc @asquared31415 @pietroalbini

@asquared31415
Copy link
Contributor

asquared31415 commented Feb 10, 2024

I no longer have the energy to work on my efforts for that, but I have pushed the rest of my changes to my fork and this was part of an effort to allow compiletest to properly parse ui_test style headers, not just change the syntax. Feel free to use any of this code for any purpose.

I think it's a better move to just move to ui_test style comments without changing the actual commands. However I would like to see a tidy warning and fix suggestion (that can auto apply on bless), to make sure that developers don't accidentally use the old style comments and the test doesn't actually test everything it's meant to.

(I have some code in my branch that has tidy fixing things, for reference. However I ended up completely changing how the parsing works, so it may or may not be usable.)

@jieyouxu
Copy link
Member Author

I think it's a better move to just move to ui_test style comments without changing the actual commands. However I would like to see a tidy warning and fix suggestion (that can auto apply on bless), to make sure that developers don't accidentally use the old style comments and the test doesn't actually test everything it's meant to.

I agree that a tidy warning would be a good idea. I'm not entirely sure on the auto-apply fix suggestion though, because there might be unfortunate cases like

// This comment serves to mention that
// ignore-test is a very useful directive
// which ignores the test.

and then the test can become unintentionally ignored. (Even though is this the current behavior.)

@oli-obk
Copy link
Contributor

oli-obk commented Feb 12, 2024

It may be simpler to parse twice, once with @ and once without, and error if any successfully parse without.

@jieyouxu
Copy link
Member Author

jieyouxu commented Feb 12, 2024

It may be simpler to parse twice, once with @ and once without, and error if any successfully parse without.

I added a very dumb check, trying to parse a // comment as a legacy directive. Currently it simply reports an error message and panics on the first such encountered directive.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 12, 2024

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

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 12, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 13, 2024

Changes to the code generated for builtin derived traits.

cc @nnethercote

@jieyouxu
Copy link
Member Author

Sorry there's something weird with my diff, might have accidentally done something...

@jieyouxu
Copy link
Member Author

jieyouxu commented Feb 15, 2024

I can squash the commits after the relevant migration parts are reviewed.
@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 15, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Feb 16, 2024

lgtm! Please squash.

will the collect-test-directives branch still work on top of this or does it include the relevant parts to skip tidy?

@jieyouxu

This comment was marked as outdated.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bccb9bb): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.2% [-1.2%, -1.2%] 1
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 638.862s -> 639.086s (0.04%)
Artifact size: 306.32 MiB -> 308.39 MiB (0.67%)

Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 17, 2024
When these extra directives were ported over as part of rust-lang#112300, it made sense
to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own
purposes, it's slightly simpler to move the coverage special-case code directly
into `iter_header` as well. This lets us get rid of `iter_header_extra`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 17, 2024
When these extra directives were ported over as part of rust-lang#112300, it made sense
to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own
purposes, it's slightly simpler to move the coverage special-case code directly
into `iter_header` as well. This lets us get rid of `iter_header_extra`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 17, 2024
When these extra directives were ported over as part of rust-lang#112300, it made sense
to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own
purposes, it's slightly simpler to move the coverage special-case code directly
into `iter_header` as well. This lets us get rid of `iter_header_extra`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 17, 2024
When these extra directives were ported over as part of rust-lang#112300, it made sense
to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own
purposes, it's slightly simpler to move the coverage special-case code directly
into `iter_header` as well. This lets us get rid of `iter_header_extra`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 17, 2024
When these extra directives were ported over as part of rust-lang#112300, it made sense
to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own
purposes, it's slightly simpler to move the coverage special-case code directly
into `iter_header` as well. This lets us get rid of `iter_header_extra`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 17, 2024
When these extra directives were ported over as part of rust-lang#112300, it made sense
to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own
purposes, it's slightly simpler to move the coverage special-case code directly
into `iter_header` as well. This lets us get rid of `iter_header_extra`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 17, 2024
When these extra directives were ported over as part of rust-lang#112300, it made sense
to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own
purposes, it's slightly simpler to move the coverage special-case code directly
into `iter_header` as well. This lets us get rid of `iter_header_extra`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 17, 2024
When these extra directives were ported over as part of rust-lang#112300, it made sense
to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own
purposes, it's slightly simpler to move the coverage special-case code directly
into `iter_header` as well. This lets us get rid of `iter_header_extra`.
saethlin added a commit to saethlin/rust that referenced this pull request Feb 20, 2024
Move the extra directives for `Mode::CoverageRun` into `iter_header`

When these extra directives were ported over as part of rust-lang#112300, it made sense to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own purposes, it's slightly simpler to move the coverage special-case code directly into `iter_header` as well. This lets us get rid of `iter_header_extra`.
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Feb 20, 2024
Move the extra directives for `Mode::CoverageRun` into `iter_header`

When these extra directives were ported over as part of rust-lang#112300, it made sense to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own purposes, it's slightly simpler to move the coverage special-case code directly into `iter_header` as well. This lets us get rid of `iter_header_extra`.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 20, 2024
Rollup merge of rust-lang#121233 - Zalathar:extra-directives, r=oli-obk

Move the extra directives for `Mode::CoverageRun` into `iter_header`

When these extra directives were ported over as part of rust-lang#112300, it made sense to introduce `iter_header_extra` and pass them in as an extra argument.

But now that rust-lang#120881 has added a `mode` parameter to `iter_header` for its own purposes, it's slightly simpler to move the coverage special-case code directly into `iter_header` as well. This lets us get rid of `iter_header_extra`.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 12, 2024
compiletest: Remove the one thing that was checking a directive's `original_line`

This special handling of `ignore-tidy*` was introduced during the migration to `//`@`` directives (rust-lang#120881), and has become unnecessary after the subsequent removal of the legacy directive check (rust-lang#131392).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 13, 2024
compiletest: Remove the one thing that was checking a directive's `original_line`

This special handling of `ignore-tidy*` was introduced during the migration to `//`@`` directives (rust-lang#120881), and has become unnecessary after the subsequent removal of the legacy directive check (rust-lang#131392).
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 13, 2024
Rollup merge of rust-lang#131585 - Zalathar:original-line, r=jieyouxu

compiletest: Remove the one thing that was checking a directive's `original_line`

This special handling of `ignore-tidy*` was introduced during the migration to `//`@`` directives (rust-lang#120881), and has become unnecessary after the subsequent removal of the legacy directive check (rust-lang#131392).
@jieyouxu jieyouxu deleted the migrate-ui-test-directives branch November 7, 2024 14:31
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 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-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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants