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

feat(resolver): Stabilize resolver v3 #14754

Merged
merged 1 commit into from
Nov 15, 2024
Merged

Conversation

epage
Copy link
Contributor

@epage epage commented Oct 31, 2024

What does this PR try to resolve?

This is a follow up to #14639 in prep for Edition 2024

How should we test and review this PR?

This is stacked on #14753

Additional information

@epage epage added the T-cargo Team: Cargo label Oct 31, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2024

r? @weihanglo

rustbot has assigned @weihanglo.
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-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 31, 2024
Comment on lines 507 to +510
- `"2"` ([`edition = "2021"`](manifest.md#the-edition-field) default): Introduces changes in [feature
unification](#features). See the [features chapter][features-2] for more
details.
- `"3"` (requires Rust 1.84+): Change the default for [`resolver.incompatible-rust-versions`] from `allow` to `fallback`
Copy link
Contributor Author

@epage epage Oct 31, 2024

Choose a reason for hiding this comment

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

side note: When we stabilize 2024 edition, we'll need to update it to say that v3 is the default for it

@epage
Copy link
Contributor Author

epage commented Oct 31, 2024

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Oct 31, 2024

Team member @epage has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Oct 31, 2024
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Implementation wise looks good.

@weiznich
Copy link
Contributor

weiznich commented Nov 4, 2024

I would like to raise a concern about changing the default resolver at the edition boundary. In my reading of RFC-2052 that's something that is not covered by what editions are allowed to change.

Specifically this part of the RFC is relevant:

Sometimes a feature we want to make available in a new edition would require backwards-incompatible changes, like introducing a new keyword. In that case, the feature is only available by explicitly opting in to the new edition. Each crate can declare an edition in its Cargo.toml like edition = "2019"; otherwise it is assumed to have edition 2015, coinciding with Rust 1.0. Thus, new editions are opt in, and the dependencies of a crate may use older or newer editions than the crate itself.

Source, highlighting of the relevant section by me.

In my understanding that forbids any changes on how cargo resolves features, as by definition they affect the whole dependency tree, not only the crate that opt's into this changes. This suddenly turns supporting the new edition into something that is forced onto the dependency crates by the crate that opt's into the new edition.

And yes, I'm aware that the 2021 edition contained a similar change, I argued against that back then already for exactly the same reason.

@epage
Copy link
Contributor Author

epage commented Nov 4, 2024

@weiznich package.resolver encompasses two resolvers, a dependency version resolver and a feature resolver. v3 only changes the dependency version resolver. The feature resolver remains unchanged. See https://rust-lang.github.io/rfcs/3537-msrv-resolver.html

EDIT: To add, this change will not affect existing lockfiles but only when the lockfile is already being changed (a changed Cargo.toml that causes a Cargo.lock change, cargo update, cargo generate-lockfile).

@weiznich
Copy link
Contributor

weiznich commented Nov 4, 2024

package.resolver encompasses two resolvers, a dependency version resolver and a feature resolver. v3 only changes the dependency version resolver. The feature resolver remains unchanged. See https://rust-lang.github.io/rfcs/3537-msrv-resolver.html

Thanks for clarifying this difference. That's helpful. I believe that it is still possible that this might cause broken builds of dependencies, for example for the following cases:

  • crate x declare a lower MSRV than any of its dependencies and the user tries to build with that minimal version as target
  • crate x uses a wrong minimal version requirement for one of its dependencies and that gets resolved by the new MSRV constraint to an actual incompatible dependency crate version. (E.g writing serde = "1" but the actual requirement for a working build is serde = "1.0.100"

Crate x revers in both cases to an crate deep in the dependency tree of that crate that opts into the new resolver.

That's written: I would consider both cases above to be clear bugs in crate x and I cannot come up with other examples, so I suppose this might be fine. Therefore consider my concern here resolved.

EDIT: To add, this change will not affect existing lockfiles but only when the lockfile is already being changed (a changed Cargo.toml that causes a Cargo.lock change, cargo update, cargo generate-lockfile).

That's from my point of view not relevant, as it will nevertheless opt in dependencies into the new resolver behaviour by using any of these commands, which might be seen as direct violation of the cited part of the edition RFC.

@rfcbot rfcbot added the final-comment-period FCP — a period for last comments before action is taken label Nov 5, 2024
@rfcbot
Copy link
Collaborator

rfcbot commented Nov 5, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period An FCP proposal has started, but not yet signed off. label Nov 5, 2024
@weiznich
Copy link
Contributor

I would like to add another question here: The edition RFC states as hard constraint:

TL;DR: Warning-free code on edition N must compile on edition N+1 and have the same behavior.

Does cargo warn for cases that might be broken by this change? See my previous case for examples of potential broken builds.

@epage
Copy link
Contributor Author

epage commented Nov 14, 2024

When a user migrates from 2021 to 2024 edition, there code will still work as it does today. The new resolver behavior will still respect their lockfile and not force the dependencies to match the MSRV.

If they take an explicit action, like adding a new dependency or running cargo generate-lockfile, then that opens them up to "whatever state the index is in" combined with "the resolver policy". I would consider that outside of the scope of what editions specify.

If someone does not commit their lockfile (which we've made committing the default behavior), then they don't need to perform an explicit action but they are still open to "whatever state the index is in" combined with "the resolver policy". I would still consider that to be outside of the scope of Editions.

@weiznich
Copy link
Contributor

When a user migrates from 2021 to 2024 edition, there code will still work as it does today. The new resolver behavior will still respect their lockfile and not force the dependencies to match the MSRV.

If they take an explicit action, like adding a new dependency or running cargo generate-lockfile, then that opens them up to "whatever state the index is in" combined with "the resolver policy". I would consider that outside of the scope of what editions specify.

That's a good argument, as long as it needs an additional step that's fine.

If someone does not commit their lockfile (which we've made committing the default behavior), then they don't need to perform an explicit action but they are still open to "whatever state the index is in" combined with "the resolver policy". I would still consider that to be outside of the scope of Editions.

I think that's not the correct conclusion here. Yes you changed the default, but old projects still exists and these guarantees applies to them as well. Otherwise you would just declare any old project outside the scope of editions, which is really strange. The easy way to workaround this without spending much time on implementing warnings for this change would be to warn for not-existing lock files on edition updates.

@rfcbot rfcbot added to-announce and removed final-comment-period FCP — a period for last comments before action is taken labels Nov 15, 2024
@rfcbot
Copy link
Collaborator

rfcbot commented Nov 15, 2024

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.

This will be merged soon.

@weihanglo
Copy link
Member

In terms of the hypothetical example in #14754 (comment), and the "Warning-free code on edition N must compile on edition N+1 and have the same behavior" statement, they happens more often nowadays without MSRV-aware resolver. If a package doesn't commmit its lockfile, it may break one way or the other becase MSRV bump may happen within SemVer minor range.

I think what you've described is actually the area the resolver v3 tries to make it a bit smoother. Resolver V3 is not silver bullent eliminating every corner cases, though it does minimize chances of those happening. Hence, I agree with Ed that the not-commiting-lockfiles case is kinda out-of-scope.


BTW I would encourage people to use inline (threaded) comments for discussions, see rust-lang/rfcs#3717.

@weihanglo
Copy link
Member

The FCP is complete. Thank you all for your participation!

@weihanglo weihanglo added this pull request to the merge queue Nov 15, 2024
@weiznich
Copy link
Contributor

weiznich commented Nov 15, 2024

@weihanglo I'm not sure how that is related to the warning free code argument. Sure that old code can break also in different ways but that's often the case. And yes I agree with you that all the provided examples that fail to compile with the new resolver are essentially broken in some way. Nevertheless they compile without warning using the current edition.

The relevant point here is that you are adding a new way to break things and that you make that new way the default with the new addition. This on its own is fine as long as you follow the rules of such edition changes. These rules are in my opinion clear as they literally say warning free code on edition N-1 must compile on edition N! I'm not aware of any exception from this rule. Given that I do not even understand why you even try to argue about that: Either you want to change the default with the edition then you must follow these rules (or submit an RFC with new rules) or you cannot change the default. My suggestion would be to warn for crates that don't include their lock files in their vcs, which should be reasonably easy to do and would sidestep the problem as explained by Ed Page above.

And to be sure: I will continue to argue about that and possibly involve an wider audience.

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 15, 2024
@ehuss ehuss added this pull request to the merge queue Nov 15, 2024
@ehuss
Copy link
Contributor

ehuss commented Nov 15, 2024

Re-queued, for some reason fix::migrate_rename_underscore_fields hung.

Merged via the queue into rust-lang:master with commit ca3eb82 Nov 15, 2024
20 checks passed
@epage epage deleted the resolver branch November 15, 2024 18:34
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 16, 2024
Update cargo

15 commits in 4a2d8dc636445b276288543882e076f254b3ae95..69e595908e2c420e7f0d1be34e6c5b984c8cfb84
2024-11-09 19:10:33 +0000 to 2024-11-16 01:26:11 +0000
- refactor(fingerprint): Track the intent for each use of `UnitHash` (rust-lang/cargo#14826)
- fix(toml): Update frontmatter parser for RFC 3503 (rust-lang/cargo#14792)
- docs(unstable): Move -Zwarnings from stable to unstable section (rust-lang/cargo#14827)
- Simplify English used in guide (rust-lang/cargo#14825)
- feat(resolver): Stabilize resolver v3 (rust-lang/cargo#14754)
- docs: Clean up doc comments (rust-lang/cargo#14823)
- fix(remove): On error, suggest other dependencies  (rust-lang/cargo#14818)
- Always include Cargo.lock in published crates (rust-lang/cargo#14815)
- fix(build-rs)!: Updates from an audit (rust-lang/cargo#14817)
- feat(rustdoc): diplay env vars in extra verbose mode  (rust-lang/cargo#14812)
- Migrate build-rs to the Cargo repo (rust-lang/cargo#14786)
- chore(ci): Check for clippy `correctness` (rust-lang/cargo#14796)
- git: do not validate submodules of fresh checkouts (rust-lang/cargo#14605)
- refactor: clone-on-write when needed for InternedString (rust-lang/cargo#14808)
- fix(docs): typo in cargo-fmt.md (rust-lang/cargo#14805)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 16, 2024
Update cargo

15 commits in 4a2d8dc636445b276288543882e076f254b3ae95..69e595908e2c420e7f0d1be34e6c5b984c8cfb84
2024-11-09 19:10:33 +0000 to 2024-11-16 01:26:11 +0000
- refactor(fingerprint): Track the intent for each use of `UnitHash` (rust-lang/cargo#14826)
- fix(toml): Update frontmatter parser for RFC 3503 (rust-lang/cargo#14792)
- docs(unstable): Move -Zwarnings from stable to unstable section (rust-lang/cargo#14827)
- Simplify English used in guide (rust-lang/cargo#14825)
- feat(resolver): Stabilize resolver v3 (rust-lang/cargo#14754)
- docs: Clean up doc comments (rust-lang/cargo#14823)
- fix(remove): On error, suggest other dependencies  (rust-lang/cargo#14818)
- Always include Cargo.lock in published crates (rust-lang/cargo#14815)
- fix(build-rs)!: Updates from an audit (rust-lang/cargo#14817)
- feat(rustdoc): diplay env vars in extra verbose mode  (rust-lang/cargo#14812)
- Migrate build-rs to the Cargo repo (rust-lang/cargo#14786)
- chore(ci): Check for clippy `correctness` (rust-lang/cargo#14796)
- git: do not validate submodules of fresh checkouts (rust-lang/cargo#14605)
- refactor: clone-on-write when needed for InternedString (rust-lang/cargo#14808)
- fix(docs): typo in cargo-fmt.md (rust-lang/cargo#14805)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 17, 2024
Update cargo

15 commits in 4a2d8dc636445b276288543882e076f254b3ae95..69e595908e2c420e7f0d1be34e6c5b984c8cfb84
2024-11-09 19:10:33 +0000 to 2024-11-16 01:26:11 +0000
- refactor(fingerprint): Track the intent for each use of `UnitHash` (rust-lang/cargo#14826)
- fix(toml): Update frontmatter parser for RFC 3503 (rust-lang/cargo#14792)
- docs(unstable): Move -Zwarnings from stable to unstable section (rust-lang/cargo#14827)
- Simplify English used in guide (rust-lang/cargo#14825)
- feat(resolver): Stabilize resolver v3 (rust-lang/cargo#14754)
- docs: Clean up doc comments (rust-lang/cargo#14823)
- fix(remove): On error, suggest other dependencies  (rust-lang/cargo#14818)
- Always include Cargo.lock in published crates (rust-lang/cargo#14815)
- fix(build-rs)!: Updates from an audit (rust-lang/cargo#14817)
- feat(rustdoc): diplay env vars in extra verbose mode  (rust-lang/cargo#14812)
- Migrate build-rs to the Cargo repo (rust-lang/cargo#14786)
- chore(ci): Check for clippy `correctness` (rust-lang/cargo#14796)
- git: do not validate submodules of fresh checkouts (rust-lang/cargo#14605)
- refactor: clone-on-write when needed for InternedString (rust-lang/cargo#14808)
- fix(docs): typo in cargo-fmt.md (rust-lang/cargo#14805)
@weihanglo weihanglo added this to the 1.84.0 milestone Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues disposition-merge FCP with intent to merge finished-final-comment-period FCP complete relnotes Release-note worthy S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants