uv/crates
Ibraheem Ahmed ffd18cc75d
Implement marker trees using algebraic decision diagrams (#5898)
## Summary

This PR rewrites the `MarkerTree` type to use algebraic decision
diagrams (ADD). This has many benefits:
- The diagram is canonical for a given marker function. It is impossible
to create two functionally equivalent marker trees that don't refer to
the same underlying ADD. This also means that any trivially true or
unsatisfiable markers are represented by the same constants.
- The diagram can handle complex operations (conjunction/disjunction) in
polynomial time, as well as constant-time negation.
- The diagram can be converted to a simplified DNF form for user-facing
output.

The new representation gives us a lot more confidence in our marker
operations and simplification, which is proving to be very important
(see https://github.com/astral-sh/uv/pull/5733 and
https://github.com/astral-sh/uv/pull/5163).

Unfortunately, it is not easy to split this PR into multiple commits
because it is a large rewrite of the `marker` module. I'd suggest
reading through the `marker/algebra.rs`, `marker/simplify.rs`, and
`marker/tree.rs` files for the new implementation, as well as the
updated snapshots to verify how the new simplification rules work in
practice. However, a few other things were changed:
- [We now use release-only comparisons for `python_full_version`, where
we previously only did for
`python_version`](https://github.com/astral-sh/uv/blob/ibraheem/canonical-markers/crates/pep508-rs/src/marker/algebra.rs#L522).
I'm unsure how marker operations should work in the presence of
pre-release versions if we decide that this is incorrect.
- [Meaningless marker expressions are now
ignored](https://github.com/astral-sh/uv/blob/ibraheem/canonical-markers/crates/pep508-rs/src/marker/parse.rs#L502).
This means that a marker such as `'x' == 'x'` will always evaluate to
`true` (as if the expression did not exist), whereas we previously
treated this as always `false`. It's negation however, remains `false`.
- [Unsatisfiable markers are written as `python_version <
'0'`](https://github.com/astral-sh/uv/blob/ibraheem/canonical-markers/crates/pep508-rs/src/marker/tree.rs#L1329).
- The `PubGrubSpecifier` type has been moved to the new `uv-pubgrub`
crate, shared by `pep508-rs` and `uv-resolver`. `pep508-rs` also depends
on the `pubgrub` crate for the `Range` type, we probably want to move
`pubgrub::Range` into a separate crate to break this, but I don't think
that should block this PR (cc @konstin).

There is still some remaining work here that I decided to leave for now
for the sake of unblocking some of the related work on the resolver.
- We still use `Option<MarkerTree>` throughout uv, which is unnecessary
now that `MarkerTree::TRUE` is canonical.
- The `MarkerTree` type is now interned globally and can potentially
implement `Copy`. However, it's unclear if we want to add more
information to marker trees that would make it `!Copy`. For example, we
may wish to attach extra and requires-python environment information to
avoid simplifying after construction.
- We don't currently combine `python_full_version` and `python_version`
markers.
- I also have not spent too much time investigating performance and
there is probably some low-hanging fruit. Many of the test cases I did
run actually saw large performance improvements due to the markers being
simplified internally, reducing the stress on the old `normalize`
routine, especially for the extremely large markers seen in
`transformers` and other projects.

Resolves https://github.com/astral-sh/uv/issues/5660,
https://github.com/astral-sh/uv/issues/5179.
2024-08-09 13:40:02 -04:00
..
bench Add basic universal benchmarks to CI (#5938) 2024-08-09 12:52:28 -04:00
cache-key Use hasher to compute resolution hash (#5495) 2024-07-26 23:24:09 +00:00
distribution-filename Enforce extension validity at parse time (#5888) 2024-08-08 21:39:47 -04:00
distribution-types Enforce extension validity at parse time (#5888) 2024-08-08 21:39:47 -04:00
install-wheel-rs feat: more rust in trampoline (#5750) 2024-08-07 08:19:38 +00:00
once-map Use lockfile to prefill resolver index (#4495) 2024-07-12 18:49:28 -04:00
pep440-rs Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
pep508-rs Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
platform-tags Process completed Python installs and uninstalls as a stream (#5203) 2024-07-19 12:50:38 +00:00
pypi-types Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
requirements-txt Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
uv Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
uv-auth Upgrade to Rust 1.80.0 (#5472) 2024-07-27 01:49:47 +00:00
uv-build Support no-build-isolation-package (#5894) 2024-08-08 01:35:56 +00:00
uv-cache Enforce extension validity at parse time (#5888) 2024-08-08 21:39:47 -04:00
uv-cli Improve the uv venv CLI documentation (#5963) 2024-08-09 12:15:22 -05:00
uv-client Enforce extension validity at parse time (#5888) 2024-08-08 21:39:47 -04:00
uv-configuration Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
uv-dev Add CLI flags to reference documentation (#5926) 2024-08-08 18:51:27 +00:00
uv-dispatch Allow downloading wheels for metadata with --no-binary (#5707) 2024-08-06 18:14:12 +00:00
uv-distribution Enforce extension validity at parse time (#5888) 2024-08-08 21:39:47 -04:00
uv-extract Enforce extension validity at parse time (#5888) 2024-08-08 21:39:47 -04:00
uv-fs Capture portable path serialization in a struct (#5652) 2024-07-31 16:00:37 +00:00
uv-git Fix reuse of Git commits in lockfile (#5908) 2024-08-08 13:01:59 +00:00
uv-installer Enforce extension validity at parse time (#5888) 2024-08-08 21:39:47 -04:00
uv-macros Autogenerate possible values for enums in reference documentation (#5137) 2024-07-17 12:37:33 -04:00
uv-normalize Support dev dependencies in virtual workspace roots (#5709) 2024-08-01 21:04:30 +00:00
uv-options-metadata Autogenerate possible values for enums in reference documentation (#5137) 2024-07-17 12:37:33 -04:00
uv-pubgrub Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
uv-python Enforce extension validity at parse time (#5888) 2024-08-08 21:39:47 -04:00
uv-requirements Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
uv-resolver Implement marker trees using algebraic decision diagrams (#5898) 2024-08-09 13:40:02 -04:00
uv-scripts Support empty dependencies in PEP 723 scripts (#5864) 2024-08-07 10:56:05 -04:00
uv-settings Add conversion to fill default settings (#5933) 2024-08-08 21:05:38 +00:00
uv-shell fix(venv): make relocatable activation scripts support ksh (#5640) 2024-07-31 12:18:11 -04:00
uv-state Cache tool environments in uv tool run (#4784) 2024-07-03 19:25:39 -04:00
uv-tool Add uv tool upgrade command (#5197) 2024-08-08 16:48:14 -04:00
uv-trampoline feat: more rust in trampoline (#5750) 2024-08-07 08:19:38 +00:00
uv-types Support no-build-isolation-package (#5894) 2024-08-08 01:35:56 +00:00
uv-version Bump version to v0.2.34 (#5889) 2024-08-07 16:33:53 -04:00
uv-virtualenv fix(venv): make relocatable activation scripts support ksh (#5640) 2024-07-31 12:18:11 -04:00
uv-warnings Upgrade to Rust 1.80.0 (#5472) 2024-07-27 01:49:47 +00:00
uv-workspace Make repeated uv add operations simpler (#5922) 2024-08-08 13:55:07 -04:00
README.md Use prettier to format the documentation (#5708) 2024-08-02 08:58:31 -05:00

Crates

bench

Functionality for benchmarking uv.

cache-key

Generic functionality for caching paths, URLs, and other resources across platforms.

distribution-filename

Parse built distribution (wheel) and source distribution (sdist) filenames to extract structured metadata.

distribution-types

Abstractions for representing built distributions (wheels) and source distributions (sdists), and the sources from which they can be downloaded.

install-wheel-rs

Install built distributions (wheels) into a virtual environment.]

once-map

A waitmap-like concurrent hash map for executing tasks exactly once.

pep440-rs

Utilities for interacting with Python version numbers and specifiers.

pep508-rs

Utilities for interacting with PEP 508 dependency specifiers.

platform-host

Functionality for detecting the current platform (operating system, architecture, etc.).

platform-tags

Functionality for parsing and inferring Python platform tags as per PEP 425.

uv

Command-line interface for the uv package manager.

uv-build

A PEP 517-compatible build frontend for uv.

uv-cache

Functionality for caching Python packages and associated metadata.

uv-client

Client for interacting with PyPI-compatible HTTP APIs.

uv-dev

Development utilities for uv.

uv-dispatch

A centralized struct for resolving and building source distributions in isolated environments. Implements the traits defined in uv-types.

uv-distribution

Client for interacting with built distributions (wheels) and source distributions (sdists). Capable of fetching metadata, distribution contents, etc.

uv-extract

Utilities for extracting files from archives.

uv-fs

Utilities for interacting with the filesystem.

uv-git

Functionality for interacting with Git repositories.

uv-installer

Functionality for installing Python packages into a virtual environment.

uv-python

Functionality for detecting and leveraging the current Python interpreter.

uv-normalize

Normalize package and extra names as per Python specifications.

uv-package

Types and functionality for working with Python packages, e.g., parsing wheel files.

uv-requirements

Utilities for reading package requirements from pyproject.toml and requirements.txt files.

uv-resolver

Functionality for resolving Python packages and their dependencies.

uv-shell

Utilities for detecting and manipulating shell environments.

uv-types

Shared traits for uv, to avoid circular dependencies.

pypi-types

General-purpose type definitions for types used in PyPI-compatible APIs.

uv-virtualenv

A venv replacement to create virtual environments in Rust.

uv-warnings

User-facing warnings for uv.

uv-workspace

Workspace abstractions for uv.

requirements-txt

Functionality for parsing requirements.txt files.