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

A big options clean-up #70729

Merged
merged 10 commits into from
Apr 20, 2020
Merged

Conversation

nnethercote
Copy link
Contributor

Lots of improvements here.

r? @Centril

@nnethercote
Copy link
Contributor Author

I recommend reviewing this one commit at a time.

@petrochenkov petrochenkov self-assigned this Apr 3, 2020
Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

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

This looks nice. Here are some things I spotted during review.
However, I'm not too familiar with this part of the codebase, so I'll leave approval to @petrochenkov.

src/librustc_session/options.rs Outdated Show resolved Hide resolved
src/librustc_session/options.rs Outdated Show resolved Hide resolved
src/doc/rustc/src/codegen-options/index.md Outdated Show resolved Hide resolved
@Centril Centril removed their assignment Apr 3, 2020
@petrochenkov petrochenkov added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 3, 2020
@petrochenkov
Copy link
Contributor

This is great, thank you.

After our discussion about -Cembed-bitcode I had the same thought about converting all the flag options (old parse_bool) into boolean options (old parse_opt_bool).

@petrochenkov
Copy link
Contributor

petrochenkov commented Apr 3, 2020

I have some reservations regarding all the no-* options which look pretty bad with the new yes/no values due to possible double negation.
With the new scheme I think we need to convert them from no-foo=no/yes to foo=yes/no.

For unstable flag options -Z no-foo we can

  • Add -Z foo=yes/no
  • Remove the existing -Z no-foo (possibly later in a separate PR)

For stable flag options -C no-foo we can

  • Add -C foo=yes/no
  • Keep the existing -C no-foo for compatibility, without support for yes/no (by introducing parse_flag equivalent to the old parse_bool)

(Or we can just avoid touching the no-* options in this PR at all.)

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 3, 2020
@bors
Copy link
Contributor

bors commented Apr 4, 2020

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

@nnethercote
Copy link
Contributor Author

(Or we can just avoid touching the no-* options in this PR at all.)

I would strongly prefer that.

I agree that --no-foo flags are weird and it would be nice to get rid of them. Having said that, I think that addition/removal/renaming of flags is significant scope creep for this PR, which is about cleaning things up and making things consistent without any significant changes in behaviour.
(Also note that someone writing --no-foo=no is extremely unlikely, because (a) it has been impossible prior to now, and (b) it has no effect unless preceded by --no-foo.)

@petrochenkov
Copy link
Contributor

I would strongly prefer that.

Ok.
Could you reintroduce parse_flag then and use it for the no-* options.

@nnethercote
Copy link
Contributor Author

Could you reintroduce parse_flag then and use it for the no-* options.

Advantages of this:

  • Double-negatives (e.g. --no-foo=no) are not possible.

Disadvantages of this:

  • --no-foo options would go back to being sticky, i.e. not overridable.
  • We would lose the new consistency that all options can take values.
  • We would require an extra parse_* function.
  • We would have to remove the "Make option type descriptions non-optional" commit, which was a nice simplification.

In my opinion, the disadvantages outweigh the advantages, particularly given that the number of --no-foo options is likely to drop in the future.

@petrochenkov
Copy link
Contributor

@nnethercote
Looks like we misinterpreted each other then?

In "avoid touching the no-* options in this PR at all" I meant not touching them compared to the status quo (before this PR), not compared to this PR as is.
You were also talking about "making things consistent without any significant changes" which I also interpreted as support for the status quo.

@petrochenkov
Copy link
Contributor

Double-negatives (e.g. --no-foo=no) are not possible.

--no-foo=yes, which is equally confusing, also becomes impossible.

--no-foo options would go back to being sticky, i.e. not overridable.

I'll fix this and introduce the corresponding --foo options once the option field redirection from #70665 lands. (That PR will be less about cleanup, and more about significant changes.)

We would lose the new consistency that all options can take values.

Temporarily, see the previous comment.

We would require an extra parse_* function.

Certainly not a big deal.

We would have to remove the "Make option type descriptions non-optional" commit

Why can't we come up with some description for parse_flag and keep it? It's indeed a nice simplification.

@nnethercote
Copy link
Contributor Author

Sorry for the confusion. I like the PR code as is. It deliberately introduces the minor functional change that all boolean options, including --no-foo ones, can take a value. I call this "minor" because it doesn't require any rustc user to change how they use the compiler. (Though they can, if they want to.)

In contrast, I consider renaming flags or removing flags "non-minor" because rustc users might have to change how they use the compiler.

@nnethercote
Copy link
Contributor Author

Hmm, -C no-redzone complicates things. It's an existing no option that already takes a value.

A problem with the parse_flag suggestion: if we end up with -C no-foo and -C foo=<bool>, then any use site has to check for both cg.no_foo and cg.foo, which is error-prone.

Here's another possibility that avoids that problem, and also gets us away from the use of no more quickly.

  • Switch all the --no-foo options to --foo=<bool>...
  • ...but give them a marking that allows --no-foo to be allowed as a synonym for --foo=no.
  • In the documentation, use the --foo= form, but mention that --no-foo is a deprecated alternative.
  • Later on (though perhaps quite soon), remove the marking for all the current -Z no-foo options.
  • We'll probably need to keep the marking for the current -C no-foo options for some time, or forever.

@eddyb
Copy link
Member

eddyb commented Apr 5, 2020

cc @rust-lang/compiler

@petrochenkov
Copy link
Contributor

@nnethercote

A problem with the parse_flag suggestion: if we end up with -C no-foo and -C foo=<bool>, then any use site has to check for both cg.no_foo and cg.foo, which is error-prone.

I wanted to use the same method that is used in #70665 for merging -C link-arg into -C link-args to merge -C no-foo into -C foo and avoid the mentioned error prone situation.
The macro_rules! redirect_field table serves as the marking in that case, but perhaps it can be integrated with the options! DSL in a nicer way.

@nnethercote nnethercote force-pushed the a-big-options-clean-up branch from bcf2973 to 07a6a56 Compare April 6, 2020 00:33
@nnethercote
Copy link
Contributor Author

I added a commit with a parse_no_flag function that reverts the changes to the no- flags. This commit is highly prone to conflicts and that seemed like the fastest way to get it landed.

@bors
Copy link
Contributor

bors commented Apr 6, 2020

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

@nnethercote nnethercote force-pushed the a-big-options-clean-up branch from 07a6a56 to 80a640d Compare April 6, 2020 03:14
@petrochenkov petrochenkov 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 Apr 6, 2020
- No trailing '.' chars.
- Use a lower-case letter at the start.
They now all accept yes/no/y/n/on/off values. (Previously only some of
them did.)

This commit also makes `parse_bool` and `parse_opt_bool` more concise
and readable, and adds some helpful comments to some functions.
Put identical ones next to each other, and avoid duplicated strings.
Currently, if you give a bogus value like
`-Zsanitizer-memory-track-origins=99` you get this incorrect error:
```
error: debugging option `sanitizer-memory-track-origins` takes no value
```
This commit fixes it so it gives this instead:
```
error: incorrect value `99` for debugging option `sanitizer-memory-track-origins` - 0, 1, or 2 was expected
```
The commit also makes `parse_sanitizer_memory_track_origins` more
readable.
Don't set `slot` on failure, like all the other `parse_*` functions.
Because all options now can take a value. This simplifies some code
quite a bit.
This lets us specify the default at the options declaration point,
instead of using `.unwrap(default)` or `None | Some(default)` at some
use point far away. It also makes the code more concise.
For all `-C` and `-Z` options that have them.

The commit also rewords a few options to make them clearer, mostly by
avoiding the word "don't".

It also removes the listed default for `-Cinline-threshold`, which is
incorrect -- that option doesn't have a static default.
This commit:
- Adds "following values" indicators for all the options that are
  missing them.
- Tweaks some wording and punctuation for consistency.
- Rewords some things for clarity.
- Removes the `no-integrated-as` entry, because that option was removed
  in rust-lang#70345.
With the exception of `-C no-redzone`, because that could take a value
before this PR.

This partially undoes one of the earlier commits in this PR, which added
the ability to take a value to all boolean options that lacked it.

The help output for these options looks like this:
```
    -C         no-vectorize-slp=val -- disable LLVM's SLP vectorization pass
```
The "=val" part is a lie, but hopefully this will be fixed in the future.
@nnethercote nnethercote force-pushed the a-big-options-clean-up branch from 066fa09 to 3e3fd73 Compare April 19, 2020 10:05
@nnethercote
Copy link
Contributor Author

@bors p=1 because this PR is conflict-prone and other PRs will soon be depending on it.

@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Apr 20, 2020
@rfcbot
Copy link

rfcbot commented Apr 20, 2020

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbot rfcbot removed the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Apr 20, 2020
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Apr 20, 2020

📌 Commit 3e3fd73 has been approved by petrochenkov

@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-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Apr 20, 2020
@bors
Copy link
Contributor

bors commented Apr 20, 2020

⌛ Testing commit 3e3fd73 with merge 8ce3f84...

@bors
Copy link
Contributor

bors commented Apr 20, 2020

☀️ Test successful - checks-azure
Approved by: petrochenkov
Pushing 8ce3f84 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 20, 2020
@bors bors merged commit 8ce3f84 into rust-lang:master Apr 20, 2020
@nnethercote nnethercote deleted the a-big-options-clean-up branch April 20, 2020 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. 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-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.

8 participants