You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #14662 - epage:resolver, r=Eh2406,weihanglo
docs(resolver): Lay groundwork for documenting MSRV-aware logic
### What does this PR try to resolve?
This is prep for document the MSRV-aware resolver (see #14639), in particular
- This give more breathing room for adding this new heuristic to the resolver documentation
- This provides the context for understanding the limitations
In moving documentation, I asked the question "where would I look to find this if I had a question on it". I tried to balance this by not putting too much formal / technical documentation in more guide-level descriptions. In particular, while "Specifying Dependencies" is in the reference, its also written in somewhat of a guide-style.
There is likely more work that can be done, including
- Maybe making the "SemVer Compatibility" chapter the de facto reference for Cargo's version of semver that other sections reference for a more exhaustive description.
- Splitting discussion of the Feature resolver out of the resolver and features documentation. In the current implementation, we have 3 resolve phases (1) lockfile, (2) adapt to the current compilation, (3) resolve features. The last two really serve the same role and I'd consider merging discussion of them.
### How should we test and review this PR?
I tried to break up changes in smaller to digest chunks. This means some times a new section doesn't fully jive with another section until a follow up commit. I'd recommend reviewing by commit while having the full diff up on the side to see if a concern is still relevant.
### Additional information
Cargo reuses versions where possible to reduce build times and allow types from common dependencies to be passed between APIs.
67
+
If multiple versions would have been unified if it wasn't for conflicts in their [dependency specifications], Cargo will backtrack, erroring if no solution is found, rather than selecting multiple versions.
68
+
A [dependency specification] or Cargo may decide that a version is undesirable,
69
+
preferring to backtrack or error rather than use it.
70
+
- Preferring versions (`pick_next_version`):
71
+
Cargo may decide that it should prefer a specific version,
72
+
falling back to the next version when backtracking.
73
+
74
+
### Version numbers
75
+
76
+
Cargo prefers the highest version currently available.
77
+
78
+
For example, if you had a package in the resolve graph with:
62
79
```toml
63
-
# Package A
64
80
[dependencies]
65
-
bitflags = "1.0"
81
+
bitflags = "*"
82
+
```
83
+
If at the time the `Cargo.lock` file is generated, the greatest version of
84
+
`bitflags` is `1.2.1`, then the package will use `1.2.1`.
66
85
67
-
# Package B
86
+
### Version requirements
87
+
88
+
Package specify what versions they support, rejecting all others, through
89
+
[version requirements].
90
+
91
+
For example, if you had a package in the resolve graph with:
92
+
```toml
68
93
[dependencies]
69
-
bitflags = "1.1"
94
+
bitflags = "1.0"# meaning `>=1.0.0,<2.0.0`
70
95
```
71
-
72
96
If at the time the `Cargo.lock` file is generated, the greatest version of
73
-
`bitflags` is `1.2.1`, then both packages will use `1.2.1` because it is the
97
+
`bitflags` is `1.2.1`, then the package will use `1.2.1` because it is the
74
98
greatest within the compatibility range. If `2.0.0` is published, it will
75
99
still use `1.2.1` because `2.0.0` is considered incompatible.
76
100
77
-
If multiple packages have a common dependency with semver-incompatible
78
-
versions, then Cargo will allow this, but will build two separate copies of
Cargo assumes packages follow [SemVer] and will unify dependency versions if they are
106
+
[SemVer] compatible according to the [Caret version requirements].
107
+
If two compatible versions cannot be unified because of conflicting version requirements,
108
+
Cargo will error.
80
109
110
+
See the [SemVer Compatibility] chapter for guidance on what is considered a
111
+
"compatible" change.
112
+
113
+
Examples:
114
+
115
+
The following two packages will have their dependencies on `bitflags` unified because any version picked will be compatible with each other.
81
116
```toml
82
117
# Package A
83
118
[dependencies]
84
-
rand = "0.7"
119
+
bitflags = "1.0"# meaning `>=1.0.0,<2.0.0`
85
120
86
121
# Package B
87
122
[dependencies]
88
-
rand = "0.6"
123
+
bitflags = "1.1"# meaning `>=1.1.0,<2.0.0`
89
124
```
90
125
91
-
The above will result in Package A using the greatest `0.7` release (`0.7.3`
92
-
at the time of this writing) and Package B will use the greatest `0.6` release
93
-
(`0.6.5` for example). This can lead to potential problems, see the
94
-
[Version-incompatibility hazards] section for more details.
95
-
96
-
Multiple versions within the same compatibility range are not allowed and will
97
-
result in a resolver error if it is constrained to two different versions
98
-
within a compatibility range. For example, if there are two packages in the
99
-
resolve graph with the following requirements:
100
-
126
+
The following packages will error because the version requirements conflict, selecting two distinct compatible versions.
101
127
```toml
102
128
# Package A
103
129
[dependencies]
@@ -108,14 +134,39 @@ log = "=0.4.11"
108
134
log = "=0.4.8"
109
135
```
110
136
111
-
The above will fail because it is not allowed to have two separate copies of
112
-
the `0.4` release of the `log` package.
137
+
The following two packages will not have their dependencies on `rand` unified because only incompatible versions are available for each.
138
+
Instead, two different versions (e.g. 0.6.5 and 0.7.3) will be resolved and built.
139
+
This can lead to potential problems, see the [Version-incompatibility hazards] section for more details.
140
+
```toml
141
+
# Package A
142
+
[dependencies]
143
+
rand = "0.7"# meaning `>=0.7.0,<0.8.0`
144
+
145
+
# Package B
146
+
[dependencies]
147
+
rand = "0.6"# meaning `>=0.6.0,<0.7.0`
148
+
```
149
+
150
+
Generally, the following two packages will not have their dependencies unified because incompatible versions are available that satisfy the version requirements:
151
+
Instead, two different versions (e.g. 0.6.5 and 0.7.3) will be resolved and built.
152
+
The application of other constraints or heuristics may cause these to be unified,
153
+
picking one version (e.g. 0.6.5).
154
+
```toml
155
+
# Package A
156
+
[dependencies]
157
+
rand = ">=0.6,<0.8.0"
158
+
159
+
# Package B
160
+
[dependencies]
161
+
rand = "0.6"# meaning `>=0.6.0,<0.7.0`
162
+
```
113
163
114
164
[SemVer]: https://semver.org/
115
165
[SemVer Compatibility]: semver.md
166
+
[Caret version requirements]: specifying-dependencies.md#default-requirements
0 commit comments