-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Plumb rustc -Zhint-mostly-unused
flag through as a profile option
#15643
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
base: master
Are you sure you want to change the base?
Plumb rustc -Zhint-mostly-unused
flag through as a profile option
#15643
Conversation
d9cc290
to
e4904fe
Compare
Been thinking more about this
|
@epage It's very much intentionally unspecified what this hint does, so that it can be changed in the future if desired. Right now it acts like
Not sure what you mean by that. An attribute for what? |
A |
I would expect that in the majority of cases where this hint is useful, it would apply to the vast majority of the crate, making it particularly inconvenient to tag such items with attributes. (Also, in the future possibility of letting the crate provide the hint about itself in its own |
On a similar note to an attribute is rust-lang/rust#54882. For the cases where the hint would be used like that are likely code generated which removes the burden of adding it. Yes, there wouldn't be overrides, that could maybe be put behind features but then we are back to adding features. At least those features are optional rather people dealing with possibly bad error messages to find out they need to add a feature. I was wondering about it from the perspective of crates where the main part is always used but there are possibly unused subsets that would normally be put behind a feature. Say |
@epage wrote:
Ah, I see. That's an interesting idea. It's possible that a Right now, it's almost equivalent to |
The rustc `-Zhint-mostly-unused` flag tells rustc that most of a crate will go unused. This is useful for speeding up compilation of large dependencies from which you only use a few items. Plumb that option through as a profile option, to allow specifying it for specific dependencies: ```toml [profile.dev.package.huge-mostly-unused-dependency] hint-mostly-unused = true ``` To enable this feature, pass `-Zprofile-hint-mostly-unused`. However, since this option is a hint, using it without passing `-Zprofile-hint-mostly-unused` will only warn and ignore the profile option. Versions of Cargo prior to the introduction of this feature will give an "unused manifest key" warning, but will otherwise function without erroring. This allows using the hint in a crate's `Cargo.toml` without mandating the use of a newer Cargo to build it. Add a test verifying that the profile option gets ignored with a warning without passing `-Zprofile-hint-mostly-unused`, and another test verifying that it gets handled when passing `-Zprofile-hint-mostly-unused`.
f5047ad
to
1eaec82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just waiting on rustc
r? @epage The PR has been merged; waiting for nightly to be updated. |
The rustc
-Zhint-mostly-unused
flag tells rustc that most of a crate will go unused. This is useful for speeding up compilation of large dependencies from which you only use a few items. Plumb that option through as a profile option, to allow specifying it for specific dependencies:To enable this feature, pass
-Zprofile-hint-mostly-unused
. However, since this option is a hint, using it without passing-Zprofile-hint-mostly-unused
will only warn and ignore the profile option. Versions of Cargo prior to the introduction of this feature will give an "unused manifest key" warning, but will otherwise function without erroring. This allows using the hint in a crate'sCargo.toml
without mandating the use of a newer Cargo to build it.Add a test verifying that the profile option gets ignored with a warning without passing
-Zprofile-hint-mostly-unused
, and another test verifying that it gets handled when passing-Zprofile-hint-mostly-unused
.How to test and review this PR?
The tests in the testsuite demonstrate both that the option works as expected and that it gets ignored with a warning if not passing
-Zprofile-hint-mostly-unused
.This will remain a draft until rust-lang/rust#135656 gets merged in rustc; once that happens, the "nightly" jobs will pass in CI.