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

rustbot commented Nov 15, 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 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
And stop accepting

1. empty or "non-identifier" directive names,
2. empty values (after the `:`)

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

Comment on lines +234 to +237
help!(
"the name has to be a non-empty sequence of alphanumeric characters, \
`_`, `-` and `!`"
);

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.

Unfortunately there's a spanner in the works, because of how //@ ignore-$target works. You see, there are some funny targets with periods in their names, because why not:

// Check target names for unwanted characters like `.` that can cause problems e.g. in Cargo.
// See also Tier 3 target policy.
// If desired, target names can ignore this check.
let ignore_target_names = [
"thumbv8m.base-none-eabi",
"thumbv8m.main-none-eabi",
"thumbv8m.main-none-eabihf",
"thumbv8m.base-nuttx-eabi",
"thumbv8m.main-nuttx-eabi",
"thumbv8m.main-nuttx-eabihf",
];

So I think right now we would reject //@ ignore-thumbv8m.base-none-eabi. I kinda hate target names that have a . in them, but... yeah.

Comment on lines +227 to +230
ErrorKind::EmptyValue => {
title("no non-empty value found after the colon `:`");
help!("consider removing the colon");
}

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, shouldn't we suggest providing a value? I guess it's 50/50:

  • Either it's a name-only directive, so remove colon
  • Or user forgor the value, so user should provide value

Maybe add another line of help for the "should provide value" case?

Comment on lines +58 to +62
// We need to allow `!` for {Html,Json}DocCk directives like `!has`.
let (name, payload) = directive
.find(|char| !is_identifier_char(char) && char != '!')
.map(|index| (&directive[..index], Some(directive[index..].trim_start())))
.unwrap_or((directive, None));

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.

Here we split as soon as we find a non-identifier character (or !). But won't we accept other wonky forms like

//@ ignore-foo$
//@ ignore-bar.
//@ ignore-baz@

Should we enforce that if we find a name, the user must only provide:

  • Only :, so //@ name: value form
  • Only whitespace, so //@ ignore-wasm hello world
  • Or EOL, just //@ ignore-wasm

@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

rust-bors Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

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

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