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

uv-resolver: pre-compute PEP 508 markers from universal markers #10472

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions crates/uv-resolver/src/universal_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,24 @@ pub struct UniversalMarker {
/// stand-point, evaluating it requires uv's custom encoding of extras (and
/// groups).
marker: MarkerTree,
/// The strictly PEP 508 version of `marker`. Basically, `marker`, but
/// without any extras in it. This could be computed on demand (and
/// that's what we used to do), but we do it enough that it was causing a
/// regression in some cases.
pep508: MarkerTree,
}

impl UniversalMarker {
/// A constant universal marker that always evaluates to `true`.
pub(crate) const TRUE: UniversalMarker = UniversalMarker {
marker: MarkerTree::TRUE,
pep508: MarkerTree::TRUE,
};

/// A constant universal marker that always evaluates to `false`.
pub(crate) const FALSE: UniversalMarker = UniversalMarker {
marker: MarkerTree::FALSE,
pep508: MarkerTree::FALSE,
};

/// Creates a new universal marker from its constituent pieces.
Expand All @@ -94,21 +101,26 @@ impl UniversalMarker {
/// Creates a new universal marker from a marker that has already been
/// combined from a PEP 508 and conflict marker.
pub(crate) fn from_combined(marker: MarkerTree) -> UniversalMarker {
UniversalMarker { marker }
UniversalMarker {
marker,
pep508: marker.without_extras(),
}
}

/// Combine this universal marker with the one given in a way that unions
/// them. That is, the updated marker will evaluate to `true` if `self` or
/// `other` evaluate to `true`.
pub(crate) fn or(&mut self, other: UniversalMarker) {
self.marker.or(other.marker);
self.pep508.or(other.pep508);
}

/// Combine this universal marker with the one given in a way that
/// intersects them. That is, the updated marker will evaluate to `true` if
/// `self` and `other` evaluate to `true`.
pub(crate) fn and(&mut self, other: UniversalMarker) {
self.marker.and(other.marker);
self.pep508.and(other.pep508);
}

/// Imbibes the world knowledge expressed by `conflicts` into this marker.
Expand All @@ -121,6 +133,7 @@ impl UniversalMarker {
let self_marker = self.marker;
self.marker = conflicts.marker;
self.marker.implies(self_marker);
self.pep508 = self.marker.without_extras();
}

/// Assumes that a given extra/group for the given package is activated.
Expand All @@ -132,6 +145,7 @@ impl UniversalMarker {
ConflictPackage::Extra(ref extra) => self.assume_extra(item.package(), extra),
ConflictPackage::Group(ref group) => self.assume_group(item.package(), group),
}
self.pep508 = self.marker.without_extras();
}

/// Assumes that a given extra/group for the given package is not
Expand All @@ -144,6 +158,7 @@ impl UniversalMarker {
ConflictPackage::Extra(ref extra) => self.assume_not_extra(item.package(), extra),
ConflictPackage::Group(ref group) => self.assume_not_group(item.package(), group),
}
self.pep508 = self.marker.without_extras();
}

/// Assumes that a given extra for the given package is activated.
Expand All @@ -155,6 +170,7 @@ impl UniversalMarker {
self.marker = self
.marker
.simplify_extras_with(|candidate| *candidate == extra);
self.pep508 = self.marker.without_extras();
}

/// Assumes that a given extra for the given package is not activated.
Expand All @@ -166,6 +182,7 @@ impl UniversalMarker {
self.marker = self
.marker
.simplify_not_extras_with(|candidate| *candidate == extra);
self.pep508 = self.marker.without_extras();
}

/// Assumes that a given group for the given package is activated.
Expand All @@ -177,6 +194,7 @@ impl UniversalMarker {
self.marker = self
.marker
.simplify_extras_with(|candidate| *candidate == extra);
self.pep508 = self.marker.without_extras();
}

/// Assumes that a given group for the given package is not activated.
Expand All @@ -188,6 +206,7 @@ impl UniversalMarker {
self.marker = self
.marker
.simplify_not_extras_with(|candidate| *candidate == extra);
self.pep508 = self.marker.without_extras();
}

/// Returns true if this universal marker will always evaluate to `true`.
Expand Down Expand Up @@ -259,7 +278,7 @@ impl UniversalMarker {
/// always use a universal marker since it accounts for all possible ways
/// for a package to be installed.
pub fn pep508(self) -> MarkerTree {
self.marker.without_extras()
self.pep508
}

/// Returns the non-PEP 508 marker expression that represents conflicting
Expand Down
Loading