Skip to content

compiletest: Further clean up directive parsing - #165651

Merged
rust-bors[bot] merged 10 commits into
rust-lang:mainfrom
fmease:comptest-dir-improv
Nov 26, 2026
Merged

rust-bors[bot] merged 10 commits into
rust-lang:mainfrom
fmease:comptest-dir-improv

Conversation

@fmease

@fmease fmease commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

View all comments

See individual commits for details. Follow-up to #165576 and #165483.

Fixes #123765.

r? jieyouxu

(No LLM was or will be used by me during the entire creation process of this PR)

@rustbot

rustbot commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

compiletest directives have been modified. Please add or update docs for the
new or modified directive in src/doc/rustc-dev-guide/.

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner 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. labels Nov 8, 2026
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Nov 8, 2026
@fmease

fmease commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

These refactorings aren't the most exciting, I wanted to do more but ran out of time last Sunday as I had to dip.

One "large" thing I want to do eventually is to avoid reparsing directives. AFAICT for the UI test suite, we always parse directives twice, first when "constructing" the test (make_test) to find & extract revisions, only-*, needs-* & ignore-*. Then we drop the DirectiveLines (instead of, e.g., storing them in CollectedTestDesc) and reparse the directives when executing the test / constructing the TestProps to handle all remaining directives.

For that DirectiveLine would need to store Strings instead of &str since the content of the file gets dropped at the end of make_test IIRC. I won't attempt this in this PR.

I could be mistaken but for the rustdoc-html test suite it seemed like we parse directives 4 times. Needs investigation.

Once we only parse directives once, it should be easier to make errors in line_directive etc. non-fatal (without reporting duplicate errors).

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Largely looks good, I still need to check the cdb case.

EDIT: tested locally, this still passes cdb for me except for #165815 on 10.0.28000.2957.

@rustbot author

View changes since this review

Comment thread src/tools/compiletest/src/directives.rs Resolved
@rustbot rustbot 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 Nov 11, 2026
@fmease
fmease force-pushed the comptest-dir-improv branch from 5f8f169 to 2c1918d Compare November 15, 2026 12:12
@rustbot

This comment has been minimized.

@fmease

fmease commented Nov 15, 2026 •

Copy link
Copy Markdown
Member Author

I've addressed your comments and implemented some more checks (as alluded to in my Zulip PM):

  1. As you suggested we now reject "empty values" (e.g., //@ name:, //@ name: ).
  2. As you suggested "if the remark is empty" the payload is now None (e.g., //@ name )
  3. //@ name : value (whitespace before :) now gets parsed as a key-value directive instead of a valueless directive with remark : value
  4. Previously, //@ name remark would get parsed as a (valueless) directive with name name remark instead of a valueless directive with remark remark if the space wasn't literally U+0020 even if it was valid Unicode whitespace. Now we effectively split by Unicode whitespace here (only makes sense given we trim by Unicode whitespace everywhere else already)
  5. We now require the directive name and the revision name in the revision condition to be valid identifiers (post-trimming) where identifier means "non-empty sequence of underscores, hyphens and alphanumeric characters"

>>> Changes since your last review <<<.

@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 Nov 15, 2026
@fmease
fmease force-pushed the comptest-dir-improv branch 4 times, most recently from b71bb77 to edb7c1f Compare November 15, 2026 12:52
@rust-log-analyzer

This comment has been minimized.

@fmease
fmease force-pushed the comptest-dir-improv branch 3 times, most recently from 3bf4f7d to f174681 Compare November 15, 2026 14:15

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rustbot rustbot 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 Nov 17, 2026
@rust-bors

This comment has been minimized.

@fmease
fmease force-pushed the comptest-dir-improv branch from f174681 to f18a370 Compare November 21, 2026 17:13
@rustbot

rustbot commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@fmease
fmease force-pushed the comptest-dir-improv branch from f18a370 to 6da2875 Compare November 26, 2026 00:48
@fmease

fmease commented Nov 26, 2026 •

Copy link
Copy Markdown
Member Author
  • Tightened the checks for revisions directives (see final commit)
  • (Introduced a Location struct in a separate refactoring commit that bundles file path & file name because I couldn't bear it any longer when trying to add a new Error{,Kind} for the parsing of //@ revisions (sorry))

@rustbot review


Edit: And I know, having so many separate *Error{,Kind} types is not ideal wrt. LOC and ergonomics; having to remember their names, the extra imports, the boilerplate and the need for a wrapper error type if we started bubbling them up to the callers instead of raise_fatal. I can collapse all 3 (line::Error, EarlyValidationError, RevisionsParseError) into 1 directives::Error if you want.

I don't consider this to be the final design. Ideally, we would not only bubble up the error but actually report multiple errors at once where possible. In the far future, we might even replace all these Errors with opaque Diagnostics and turn these unit tests into UI self tests.

@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 Nov 26, 2026
@fmease
fmease force-pushed the comptest-dir-improv branch from 6da2875 to 23679e8 Compare November 26, 2026 01:01
* Reject revision names that aren't a sequence of alphanumeric chars,
  `-` and `_`.
* Reject conditional `revision` directives (e.g., `//@[r] revisions: q`).
@fmease
fmease force-pushed the comptest-dir-improv branch from 23679e8 to 8e47edf Compare November 26, 2026 01:05

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! This is much nicer indeed.

@bors r+ rollup

View changes since this review

@rust-bors

rust-bors Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8e47edf has been tentatively approved by jieyouxu

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot 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 Nov 26, 2026
@jieyouxu

Copy link
Copy Markdown
Member

I don't consider this to be the final design. Ideally, we would not only bubble up the error but actually report multiple errors at once where possible. In the far future, we might even replace all these Errors with opaque Diagnostics and turn these unit tests into UI self tests.

Yep, any incr improvement here is good.

clarfonthey added a commit to clarfonthey/rust that referenced this pull request Nov 26, 2026
…ouxu

compiletest: Further clean up directive parsing

See individual commits for details. Follow-up to rust-lang#165576 and rust-lang#165483.

Fixes rust-lang#123765.

r? jieyouxu

<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
Rollup of 4 pull requests

Successful merges:

 - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes)
 - #165651 (compiletest: Further clean up directive parsing)
 - #166196 (autodiff: don't ICE on invalid macro arguments)
 - #166556 (remove `Box::into_boxed_slice`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 26, 2026
…ouxu

compiletest: Further clean up directive parsing

See individual commits for details. Follow-up to rust-lang#165576 and rust-lang#165483.

Fixes rust-lang#123765.

r? jieyouxu

<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #164252 (Share retain implementation between Vec and VecDeque)
 - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes)
 - #166506 (traits: Fix dead match arm for String type suggestions.)
 - #164542 (Add regression test for #151312)
 - #165651 (compiletest: Further clean up directive parsing)
 - #166196 (autodiff: don't ICE on invalid macro arguments)
 - #166556 (remove `Box::into_boxed_slice`)
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #164252 (Share retain implementation between Vec and VecDeque)
 - #166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature)
 - #166156 (tests: cover proc-macro metadata path remapping)
 - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes)
 - #166506 (traits: Fix dead match arm for String type suggestions.)
 - #164542 (Add regression test for #151312)
 - #165651 (compiletest: Further clean up directive parsing)
 - #166196 (autodiff: don't ICE on invalid macro arguments)
 - #166556 (remove `Box::into_boxed_slice`)
 - #166562 (docs: add backticks around `!` in primitive docs )
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #164252 (Share retain implementation between Vec and VecDeque)
 - #166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature)
 - #166156 (tests: cover proc-macro metadata path remapping)
 - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes)
 - #166506 (traits: Fix dead match arm for String type suggestions.)
 - #164542 (Add regression test for #151312)
 - #165651 (compiletest: Further clean up directive parsing)
 - #166196 (autodiff: don't ICE on invalid macro arguments)
 - #166556 (remove `Box::into_boxed_slice`)
 - #166562 (docs: add backticks around `!` in primitive docs )
@rust-bors
rust-bors Bot merged commit c7d02e0 into rust-lang:main Nov 26, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
Rollup merge of #165651 - fmease:comptest-dir-improv, r=jieyouxu

compiletest: Further clean up directive parsing

See individual commits for details. Follow-up to #165576 and #165483.

Fixes #123765.

r? jieyouxu

<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
@fmease
fmease deleted the comptest-dir-improv branch November 26, 2026 18:22
mehmettoplu-rs pushed a commit to mehmettoplu-rs/miri that referenced this pull request Nov 27, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#164252 (Share retain implementation between Vec and VecDeque)
 - rust-lang/rust#166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature)
 - rust-lang/rust#166156 (tests: cover proc-macro metadata path remapping)
 - rust-lang/rust#166171 (borrowck: Fix Reborrow ICE on types with several lifetimes)
 - rust-lang/rust#166506 (traits: Fix dead match arm for String type suggestions.)
 - rust-lang/rust#164542 (Add regression test for rust-lang/rust#151312)
 - rust-lang/rust#165651 (compiletest: Further clean up directive parsing)
 - rust-lang/rust#166196 (autodiff: don't ICE on invalid macro arguments)
 - rust-lang/rust#166556 (remove `Box::into_boxed_slice`)
 - rust-lang/rust#166562 (docs: add backticks around `!` in primitive docs )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compiletest has some parsing footguns around revisions

4 participants