Skip to content

compiletest: Further clean up directive parsing - #165651

Open
fmease wants to merge 8 commits into
rust-lang:mainfrom
fmease:comptest-dir-improv
Open

fmease wants to merge 8 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.

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 commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Reverted the "directive name needs to be alphanumerical ∪ {-, _, !}". Now, the only requirement for directive names is that they have to be non-empty after trimming.

@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 21, 2026

@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.

One final thing I just realized :D
@rustbot author

View changes since this review

Comment on lines +51 to +53
if rev.is_empty() || rev.contains(|char| !is_identifier_char(char)) {
return error(ErrorKind::InvalidRevisionName { revision: rev });
}

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.

Hm, right now we are rejecting usage of invalid directive names (i.e. alphanumeric $\cup$ {_, -} but we weren't rejecting declarations of invalid direction names right? So I think parse_and_update_revisions also needs to reject symmetrically, otherwise we'd end up with

//@ revisions: a$b
//@[a$b] oops-cant-use-it

@fmease fmease Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep :) I also realized this but shrugged it off as I was thinking about doing that in a follow-up PR but it's probably better to do it at once. That would then also fix #123765 (which is about both the revision directive and [ revision conditions ]).

Comment on lines +86 to 88
fn is_identifier_char(char: char) -> bool {
char == '-' || char == '_' || char.is_ascii_alphanumeric()
}

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.

Nit: bit pedantic, but maybe is_valid_revision_name_char, since e.g. I don't think foo-bar is a valid identifier in Rust

@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 24, 2026

This branch has not been deployed

No deployments
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-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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants