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

Simplify the internal API for declaring command-line options #132754

Merged
merged 4 commits into from
Nov 9, 2024

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Nov 8, 2024

The internal APIs for declaring command-line options are old, and intimidatingly complex. This PR replaces them with a single function that takes explicit stability and kind arguments, making it easier to see how each option is handled, and whether it is treated as stable or unstable.

We also don't appear to have any tests for the output of rustc --help and similar, so I've added a run-make test to verify that this PR doesn't change any output. (There is already a similar run-make test for rustdoc's help output.)


The librustdoc changes are simply adjusting to updated compiler APIs; no functional change intended.


A side-effect of these changes is that rustfmt can once again format the entirety of these option declaration lists, which it was not doing before.

@rustbot
Copy link
Collaborator

rustbot commented Nov 8, 2024

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 8, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 8, 2024

The run-make-support library was changed

cc @jieyouxu

This PR modifies tests/run-make/. If this PR is trying to port a Makefile
run-make test to use rmake.rs, please update the
run-make port tracking issue
so we can track our progress. You can either modify the tracking issue
directly, or you can comment on the tracking issue and link this PR.

cc @jieyouxu

Comment on lines +1492 to +1497
"Link the generated crate(s) to the specified native\n\
library NAME. The optional KIND can be one of\n\
static, framework, or dylib (the default).\n\
Optional comma separated MODIFIERS\n\
(bundle|verbatim|whole-archive|as-needed)\n\
may be specified each with a prefix of either '+' to\n\
Copy link
Contributor Author

@Zalathar Zalathar Nov 8, 2024

Choose a reason for hiding this comment

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

IIRC this is one of the entries that used to confuse rustfmt, causing the rest of the list to quietly not be auto-formatted at all.

Replacing the hard line-breaks with \n\ seems to work around that, without changing the output seen by the new run-make test.

@jieyouxu jieyouxu self-assigned this Nov 8, 2024
Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

Changes look good to me, thanks! I'll let someone from the compiler team confirm it's good on their side as well.

@Zalathar
Copy link
Contributor Author

Zalathar commented Nov 8, 2024

Hmm, it occurs to me that the help output is slightly different on beta/stable, but only if RUSTC_BOOTSTRAP is not set.

Looking at some of the other run-make tests, it seems that they already pass -Z flags to the compiler without any special nightly-only directives, so hopefully that variable is set and things will be fine? Even if it somehow isn't fine, I guess the worst-case outcome is that someone is slightly inconvenienced when doing the next beta branch.

@jieyouxu
Copy link
Member

jieyouxu commented Nov 9, 2024

Hmm, it occurs to me that the help output is slightly different on beta/stable, but only if RUSTC_BOOTSTRAP is not set.

Looking at some of the other run-make tests, it seems that they already pass -Z flags to the compiler without any special nightly-only directives, so hopefully that variable is set and things will be fine? Even if it somehow isn't fine, I guess the worst-case outcome is that someone is slightly inconvenienced when doing the next beta branch.

compiletest is AFAIK always run with RUSTC_BOOTSTRAP=1

cmd.env("RUSTC_BOOTSTRAP", "1");

so it shouldn't cause problems beta bumping.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thank you, this looks like a significant readibility cleanup for the options handling! One minor question, but otherwise looks good.

Comment on lines +1482 to +1490
opt(
Stable,
Multi,
"",
"cfg",
"Configure the compilation environment.\n\
SPEC supports the syntax `NAME[=\"VALUE\"]`.",
"SPEC",
),
Copy link
Member

@jieyouxu jieyouxu Nov 9, 2024

Choose a reason for hiding this comment

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

Question: what does rustc_short_optgroups actually mean?

Returns the "short" subset of the rustc command line options

Like the options that have a shorthand...? I was trying to figure out what the distinction of rustc_short_optgroups vs rustc_optgroups was lol.

Copy link
Member

Choose a reason for hiding this comment

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

Anyway, this doesn't have to be in this PR (probably for the better).

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 believe it means “the subset of options that we print when running rustc --help without -v”.

It’s not a great name!

@jieyouxu
Copy link
Member

jieyouxu commented Nov 9, 2024

@bors r=GuillaumeGomez,jieyouxu

@bors
Copy link
Contributor

bors commented Nov 9, 2024

📌 Commit b8377e5 has been approved by GuillaumeGomez,jieyouxu

It is now in the queue for this repository.

@bors bors 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 9, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 9, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#132341 (Reject raw lifetime followed by `'`, like regular lifetimes do)
 - rust-lang#132363 (Enforce that raw lifetimes must be valid raw identifiers)
 - rust-lang#132744 (add regression test for rust-lang#90781)
 - rust-lang#132754 (Simplify the internal API for declaring command-line options)
 - rust-lang#132772 (use `download-rustc="if-unchanged"` as a global default)
 - rust-lang#132774 (Use lld with non-LLVM backends)
 - rust-lang#132799 (Make `Ty::primitive_symbol` recognize `str`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 88acd49 into rust-lang:master Nov 9, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 9, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 9, 2024
Rollup merge of rust-lang#132754 - Zalathar:opts, r=GuillaumeGomez,jieyouxu

Simplify the internal API for declaring command-line options

The internal APIs for declaring command-line options are old, and intimidatingly complex. This PR replaces them with a single function that takes explicit `stability` and `kind` arguments, making it easier to see how each option is handled, and whether it is treated as stable or unstable.

We also don't appear to have any tests for the output of `rustc --help` and similar, so I've added a run-make test to verify that this PR doesn't change any output. (There is already a similar run-make test for rustdoc's help output.)

---

The librustdoc changes are simply adjusting to updated compiler APIs; no functional change intended.

---

A side-effect of these changes is that rustfmt can once again format the entirety of these option declaration lists, which it was not doing before.
@Zalathar Zalathar deleted the opts branch November 9, 2024 22:59
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 11, 2024
Remove `rustc_session::config::rustc_short_optgroups`

Follow-up to rust-lang#132754 (comment).

The name `rustc_short_optgroups` has always been confusing, because it is unrelated to the distinction between short and long options (i.e. `-s` vs `--long`), and instead means something like “the subset of command-line options that are printed by `rustc --help` without `-v`”.

So let's merge that function into the main `rustc_optgroups`, and store the relevant bit of information in a boolean field in `RustcOptGroup` instead.

---

This PR also modifies `RustcOptGroup` to store its various strings directly, instead of inside a boxed `apply` closure. That turned out to not be necessary for the main change, but is a worthwhile cleanup in its own right.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 11, 2024
Rollup merge of rust-lang#132891 - Zalathar:short-opt-groups, r=jieyouxu

Remove `rustc_session::config::rustc_short_optgroups`

Follow-up to rust-lang#132754 (comment).

The name `rustc_short_optgroups` has always been confusing, because it is unrelated to the distinction between short and long options (i.e. `-s` vs `--long`), and instead means something like “the subset of command-line options that are printed by `rustc --help` without `-v`”.

So let's merge that function into the main `rustc_optgroups`, and store the relevant bit of information in a boolean field in `RustcOptGroup` instead.

---

This PR also modifies `RustcOptGroup` to store its various strings directly, instead of inside a boxed `apply` closure. That turned out to not be necessary for the main change, but is a worthwhile cleanup in its own right.
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
…eyouxu

Simplify the internal API for declaring command-line options

The internal APIs for declaring command-line options are old, and intimidatingly complex. This PR replaces them with a single function that takes explicit `stability` and `kind` arguments, making it easier to see how each option is handled, and whether it is treated as stable or unstable.

We also don't appear to have any tests for the output of `rustc --help` and similar, so I've added a run-make test to verify that this PR doesn't change any output. (There is already a similar run-make test for rustdoc's help output.)

---

The librustdoc changes are simply adjusting to updated compiler APIs; no functional change intended.

---

A side-effect of these changes is that rustfmt can once again format the entirety of these option declaration lists, which it was not doing before.
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#132341 (Reject raw lifetime followed by `'`, like regular lifetimes do)
 - rust-lang#132363 (Enforce that raw lifetimes must be valid raw identifiers)
 - rust-lang#132744 (add regression test for rust-lang#90781)
 - rust-lang#132754 (Simplify the internal API for declaring command-line options)
 - rust-lang#132772 (use `download-rustc="if-unchanged"` as a global default)
 - rust-lang#132774 (Use lld with non-LLVM backends)
 - rust-lang#132799 (Make `Ty::primitive_symbol` recognize `str`)

r? `@ghost`
`@rustbot` modify labels: rollup
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
Remove `rustc_session::config::rustc_short_optgroups`

Follow-up to rust-lang#132754 (comment).

The name `rustc_short_optgroups` has always been confusing, because it is unrelated to the distinction between short and long options (i.e. `-s` vs `--long`), and instead means something like “the subset of command-line options that are printed by `rustc --help` without `-v`”.

So let's merge that function into the main `rustc_optgroups`, and store the relevant bit of information in a boolean field in `RustcOptGroup` instead.

---

This PR also modifies `RustcOptGroup` to store its various strings directly, instead of inside a boxed `apply` closure. That turned out to not be necessary for the main change, but is a worthwhile cleanup in its own right.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants