-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Refactor feature handling, and improve error messages. #9290
Conversation
r? @Eh2406 (rust-highfive has picked a reviewer for you, use r? to override) |
// This returns `false` for CliFeatures just for simplicity. It | ||
// would take a bit of work to compare since they are not in the | ||
// same format as DepFeatures (and that may be expensive | ||
// performance-wise). Also, it should only occur once for a root | ||
// package. The only drawback is that it may re-activate a root | ||
// package again, which should only affect performance, but that | ||
// should be rare. Cycles should still be detected since those | ||
// will have `DepFeatures` edges. | ||
RequestedFeatures::CliFeatures(_) => return Ok(false), |
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.
I don't know if this is actually correct. I didn't fully understand why the original code returned false
when all_features
was set.
This function was originally added in 06f37a0 to deal with cycles. It treated Method::Everything
as "false". The check for all_features
as added in 7de30dd without an explanation.
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.
I'm unfortunately unable to piece together more context than what you probably already know. I don't really know what this check was doing prior other than exactly what you're doing here which is to generate a little bit more work for the resolver to avoid trying to handle more at this call-site.
I think that's fine, however, and I doubt this will have any noticeable impact on perf or anything like that.
I like the additional type safety, and checking for invariants earlier on. I have always wondered why feature parsing code was part of the resolver. Thank you for doing something about that! |
@bors: r+ |
📌 Commit 85854b1 has been approved by |
☀️ Test successful - checks-actions |
Update cargo 8 commits in 90691f2bfe9a50291a98983b1ed2feab51d5ca55..58a961314437258065e23cb6316dfc121d96fb71 2021-03-16 21:36:55 +0000 to 2021-03-22 22:59:56 +0000 - Emit note when `--future-incompat-report` had nothing to report (rust-lang/cargo#9263) - RFC 3052: Stop including authors field in manifests made by cargo new (rust-lang/cargo#9282) - Refactor feature handling, and improve error messages. (rust-lang/cargo#9290) - Split out cargo-util package for cargo-test-support. (rust-lang/cargo#9292) - Fix redundant_semicolons warning in resolver-tests. (rust-lang/cargo#9293) - Use serde's error message option to avoid implementing `Deserialize`. (rust-lang/cargo#9237) - Allow `cargo update` to operate with the --offline flag (rust-lang/cargo#9279) - Fix typo in faq.md (rust-lang/cargo#9285)
Update cargo 8 commits in 90691f2bfe9a50291a98983b1ed2feab51d5ca55..58a961314437258065e23cb6316dfc121d96fb71 2021-03-16 21:36:55 +0000 to 2021-03-22 22:59:56 +0000 - Emit note when `--future-incompat-report` had nothing to report (rust-lang/cargo#9263) - RFC 3052: Stop including authors field in manifests made by cargo new (rust-lang/cargo#9282) - Refactor feature handling, and improve error messages. (rust-lang/cargo#9290) - Split out cargo-util package for cargo-test-support. (rust-lang/cargo#9292) - Fix redundant_semicolons warning in resolver-tests. (rust-lang/cargo#9293) - Use serde's error message option to avoid implementing `Deserialize`. (rust-lang/cargo#9237) - Allow `cargo update` to operate with the --offline flag (rust-lang/cargo#9279) - Fix typo in faq.md (rust-lang/cargo#9285)
Update cargo 12 commits in 90691f2bfe9a50291a98983b1ed2feab51d5ca55..1e8703890f285befb5e32627ad4e0a0454dde1fb 2021-03-16 21:36:55 +0000 to 2021-03-26 16:59:39 +0000 - tests: Tolerate "exit status" in error messages (rust-lang/cargo#9307) - Default macOS targets to `unpacked` debuginfo (rust-lang/cargo#9298) - Fix publication of packages with metadata and resolver (rust-lang/cargo#9300) - Fix config includes not working. (rust-lang/cargo#9299) - Emit note when `--future-incompat-report` had nothing to report (rust-lang/cargo#9263) - RFC 3052: Stop including authors field in manifests made by cargo new (rust-lang/cargo#9282) - Refactor feature handling, and improve error messages. (rust-lang/cargo#9290) - Split out cargo-util package for cargo-test-support. (rust-lang/cargo#9292) - Fix redundant_semicolons warning in resolver-tests. (rust-lang/cargo#9293) - Use serde's error message option to avoid implementing `Deserialize`. (rust-lang/cargo#9237) - Allow `cargo update` to operate with the --offline flag (rust-lang/cargo#9279) - Fix typo in faq.md (rust-lang/cargo#9285)
Update `cargo` dependency to 0.54 The breaking change was introduced in rust-lang/cargo#9290.
This changes the way feature strings are handled with an eye towards fixing some improper handling and to improve error messages. The key change is to stop treating all features as free-form strings and instead try to handle them as typed values. This helps avoid needing to deal with parsing different feature syntax (like
dep:
orfoo/bar
) or forgetting to handle it properly.Overview of refactoring changes:
RequestedFeatures
changed to an enum to differentiate between features coming from the command-line, and those that are from a dependency.CompileOptions
), and ensures that they are properly handled asFeatureValue
instead of strings.DetailedTomlDependency
now validates things so you can see the location for the errantCargo.toml
(previously some validation was deep in the resolver, which provided poor errors).This is a pretty large PR, but at the core it is just changing
RequestedFeatures
and then dealing with the fallout from that. Hopefully this is an improvement overall.List of user-visible changes:
--features bar?/feat
and--features dep:bar
bar/feat
anddep:bar
in dependency declarations.[features]
table can no longer contain slashes.cargo tree -e features --all-features -Z namespaced-features
cargo tree
involving-Z weak-dep-features
I did a small amount of benchmarking, and I wasn't able to record much of a difference.