Skip to content

Commit

Permalink
Auto merge of #14305 - linyihai:matches-prerelease-semantic, r=epage
Browse files Browse the repository at this point in the history
feat: Add matches_prerelease semantic

### What does this PR try to resolve?
One implementaion for #13290

Thanks to `@Eh2406` feedback, a working version came out, and I think it should be able to test under the nightly feature.

This PR proposes a `matches_prerelease semantic`.

| req              | matches             | matches_prerelease     | matches_prerelease_mirror_node [<sub>2<sub>](#mirror-node) |
|------------------|---------------------|------------------------| ----------------------------------|
| `Op::Exact`      |                     |                        |                                   |
| =I.J.K           | =I.J.K              | >=I.J.K, <I.J.(K+1)-0  | >=I.J.K, <I.J.(K+1)-0             |
| =I.J             | >=I.J.0, <I.(J+1).0 | >=I.J.0, <I.(J+1).0-0  | >=I.J.0-0, <I.(J+1).0-0           |
| =I               | >=I.0.0, <(I+1).0.0 | >=I.0.0, <(I+1).0.0-0  | >=I.0.0-0, <(I+1).0.0-0           |
| `Op::Greater`    |                     |                        |                                   |
| >I.J.K           | >I.J.K              | >I.J.K                 | >I.J.K                            |
| >I.J             | >=I.(J+1).0         | >=I.(J+1).0-0          | >=I.(J+1).0-0                     |
| >I               | >=(I+1).0.0         | >=(I+1).0.0-0          | >=(I+1).0.0-0                     |
| `Op::GreaterEq`  |                     |                        |                                   |
| >=I.J.K          | >=I.J.K             | >=I.J.K                | >=I.J.K                           |
| >=I.J            | >=I.J.0             | >=I.J.0                | >=I.J.0-0                         |
| >=I              | >=I.0.0             | >=I.0.0                | >=I.0.0-0                         |
| `Op::Less`       |                     |                        |                                   |
| <I.J.K           | <I.J.K              | <I.J.K or I.J.K-0 depends [<sub>1<sub>](#op-less) | <I.J.K |
| <I.J             | <I.J.0              | <I.J.0-0               | <I.J.0-0                          |
| <I               | <I.0.0              | <I.0.0-0               | <I.0.0-0                          |
| `Op::LessEq`     |                     |                        |                                   |
| <=I.J.K          | <=I.J.K             | <=I.J.K                | <=I.J.K                           |
| <=I.J            | <I.(J+1).0          | <I.(J+1).0-0           | <I.(J+1).0-0                      |
| <=I              | <(I+1).0.0          | <(I+1).0.0-0           | <(I+1).0.0-0                      |
| `Op::Tilde`      |                     |                        |                                   |
| ~I.J.K           | >=I.J.K, <I.(J+1).0 | >=I.J.K, <I.(J+1).0-0  | >=I.J.K, <I.(J+1).0-0             |
| ~I.J             | =I.J                | >=I.J.0, <I.(J+1).0-0  | >=I.J.0, <I.(J+1).0-0             |
| ~I               | =I                  | >=I.0.0, <(I+1).0.0-0  | >=I.0.0, <(I+1).0.0-0             |
| `Op::Caret`      |                     |                        |                                   |
| ^I.J.K (for I>0) | >=I.J.K, <(I+1).0.0 | >=I.J.K, <(I+1).0.0-0  | >=I.J.K, <(I+1).0.0-0             |
| ^0.J.K (for J>0) | >=0.J.K, <0.(J+1).0 | >=0.J.K,  <0.(J+1).0-0 | >=0.J.K-0, <0.(J+1).0-0           |
| ^0.0.K           | =0.0.K              | >=0.0.K,  <0.0.(K+1)-0 | >=0.J.K-0, <0.(J+1).0-0           |
| ^I.J             | ^I.J.0              | >=I.J.0,  <(I+1).0.0-0 | >=I.J.0-0, <(I+1).0.0-0           |
| ^0.0             | =0.0                | >=0.0.0, <0.1.0-0      | >=0.0.0-0, <0.1.0-0               |
| ^I               | =I                  | >=I.0.0, <(I+1).0.0-0  | >=I.0.0-0, <(I+1).0.0-0           |
| `Op::Wildcard`   |                     |                        |                                   |
| `I.J.*`          | =I.J                | >=I.J.0, <I.(J+1).0-0  | >=I.J.0-0, <I.(J+1).0-0           |
| `I.*` or `I.*.*` | =I                  | >=I.0.0, <(I+1).0.0-0  | >=I.0.0-0, <(I+1).0.0-0           |

Notes:

<div id="op-less"></div>

- `<I.J.K`: This is equivalent to `<I.J.K-0` if no lower bound or the lower bound isn't pre-release, otherwise this is equivalent to `<I.J.K`.

<div id="mirror-node"></div>

- [matches_prerelease_mirror_node](dtolnay/semver@3464fd1) is yet another  implementation of [node semver compatibility](https://github.com/npm/node-semver?tab=readme-ov-file#semver1----the-semantic-versioner-for-npm) (with [includePrerelease=true](https://github.com/npm/node-semver?tab=readme-ov-file#functions)) test. This is extrapolated from the test cases and is not necessarily the same as the node implementation

Besides, the proposed semtantic left a [unsolved issuse ](dtolnay/semver#321 (comment)), I don't have clear idea to handle it.

### How should we test and review this PR?
The tests in `src/cargo/util/semver_eval_ext.rs` are designed to reflect current semantic.

### Additional information
Migrated from dtolnay/semver#321

TBO, this feature was not conceived in advance plus the semantic is unclear at first.  I need to experiment step by step and find out what I think makes sense.  My experiment can be seen this [comment](#13290 (comment)).
  • Loading branch information
bors committed Aug 23, 2024
2 parents b57cdb5 + bdf19e0 commit a0acc29
Show file tree
Hide file tree
Showing 4 changed files with 708 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/cargo/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ mod progress;
mod queue;
pub mod restricted_names;
pub mod rustc;
mod semver_eval_ext;
mod semver_ext;
pub mod sqlite;
pub mod style;
Expand Down
Loading

0 comments on commit a0acc29

Please sign in to comment.