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

Refactor feature handling, and improve error messages. #9290

Merged
merged 2 commits into from
Mar 22, 2021

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Mar 19, 2021

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: or foo/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.
  • Moved parsing of CLI features to an earlier stage (now stored in CompileOptions), and ensures that they are properly handled as FeatureValue instead of strings.
  • Pushed some feature validation earlier. For example, DetailedTomlDependency now validates things so you can see the location for the errant Cargo.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:

  • Fix handling in resolver V2 of --features bar?/feat and --features dep:bar
  • Better error handling for bar/feat and dep:bar in dependency declarations.
  • Feature keys in the [features] table can no longer contain slashes.
  • Fixed a minor issue with cargo tree -e features --all-features -Z namespaced-features
  • Fixed a panic with 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.

@rust-highfive
Copy link

r? @Eh2406

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 19, 2021
Comment on lines +165 to +173
// 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),
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 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.

Copy link
Member

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.

@Eh2406
Copy link
Contributor

Eh2406 commented Mar 20, 2021

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!

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 22, 2021

📌 Commit 85854b1 has been approved by alexcrichton

@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 Mar 22, 2021
@bors
Copy link
Contributor

bors commented Mar 22, 2021

⌛ Testing commit 85854b1 with merge 39d9413...

@bors
Copy link
Contributor

bors commented Mar 22, 2021

☀️ Test successful - checks-actions
Approved by: alexcrichton
Pushing 39d9413 to master...

@bors bors merged commit 39d9413 into rust-lang:master Mar 22, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 23, 2021
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)
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 23, 2021
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)
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 26, 2021
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)
bors added a commit to rust-lang/rust-semverver that referenced this pull request Jun 29, 2021
Update `cargo` dependency to 0.54

The breaking change was introduced in rust-lang/cargo#9290.
@ehuss ehuss added this to the 1.53.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants