Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b59f827
Use bit sets to simplify large marker DNFs
zanieb Oct 15, 2026
a1409c6
Make DNF simplification tests explicit
charliermarsh Oct 16, 2026
cceb622
Cache clause differences when simplifying large marker DNFs
zanieb Oct 15, 2026
76d97d3
Share DNF simplification across clause representations
charliermarsh Oct 15, 2026
72da9f6
Use an enum for DNF clause comparisons
charliermarsh Oct 15, 2026
cacc9bb
Use a private trait for DNF clause comparisons
charliermarsh Oct 15, 2026
21f4b07
Use indexed flags for redundant DNF clauses
charliermarsh Oct 16, 2026
1954319
Avoid expanding environment-only conflict markers
zanieb Oct 15, 2026
0f56ec3
Preserve marker ordering when restoring Python bounds
charliermarsh Oct 16, 2026
da6c598
Prototype validation of marker selections from declared requests
charliermarsh Oct 16, 2026
45541f5
Avoid repeated traversal of shared marker paths
charliermarsh Oct 16, 2026
49e68a3
Include base dependencies when validating an extra selection
charliermarsh Oct 16, 2026
13a07c3
Compare equivalent marker selections and exports
charliermarsh Oct 16, 2026
08a1d86
Substitute grounded marker activations before validation
charliermarsh Oct 16, 2026
23ed399
Reuse validated marker reachability for selection and export
charliermarsh Oct 16, 2026
989c236
Remove experimental marker-selection adapters and benchmarks
charliermarsh Oct 16, 2026
39ff6d3
Extract marker DNF covers from decision diagrams
charliermarsh Oct 16, 2026
8484ee2
Preserve diagram ordering and update marker covers
charliermarsh Oct 16, 2026
3d3bc55
Integrate request validation into lock selection and export
charliermarsh Oct 16, 2026
f6e5e0a
Remove unused conflict-group accessors
charliermarsh Oct 16, 2026
f9df0b8
Avoid rebuilding marker cover guards
charliermarsh Oct 16, 2026
adb6187
Skip marker restriction when no conflicts are declared
charliermarsh Oct 16, 2026
050ac8a
Reuse cached environment markers after restriction
charliermarsh Oct 16, 2026
789b935
Restore v1 lockfile serialization and selection
charliermarsh Oct 16, 2026
f030e00
Remove the unused request-selection model
charliermarsh Oct 16, 2026
7e9937f
Skip constant nodes when tracking marker traversal
charliermarsh Oct 16, 2026
e93cb56
Avoid expanding environment-only conflict markers
zanieb Oct 15, 2026
7fa0b7d
Evaluate selection markers under declared conflicts
charliermarsh Oct 16, 2026
94cbde9
Construct conflict constraints without enumerating pairs
charliermarsh Oct 17, 2026
024fbbd
Merge the updated marker stack base
charliermarsh Oct 17, 2026
6d6389c
Remove an operator helper superseded by marker covers
charliermarsh Oct 17, 2026
962d915
Remove unused marker dependencies and public surface
charliermarsh Oct 17, 2026
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions crates/uv-lock/src/lock/export/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use uv_pep508::MarkerTree;
use uv_pypi_types::ConflictItem;

use uv_resolver_types::graph_ops::Reachable;
use uv_resolver_types::universal_marker::resolve_activated_extras;
use uv_resolver_types::universal_marker::ConflictMarkerContext;

pub use crate::lock::export::metadata::{Metadata, PythonReport};
pub(crate) use crate::lock::export::metadata::{
Expand Down Expand Up @@ -315,7 +315,9 @@ impl<'lock> ExportableRequirements<'lock> {
}

// Determine the reachability of each node in the graph.
let mut reachability = conflict_marker_reachability(&graph, &[], &activated_items);
let mut marker_context = ConflictMarkerContext::new(target.lock().conflicts());
let mut reachability =
conflict_marker_reachability(&graph, &[], &activated_items, &mut marker_context);

// Collect all packages.
let nodes = graph
Expand Down Expand Up @@ -429,6 +431,7 @@ fn conflict_marker_reachability<'lock>(
graph: &Graph<Node<'lock>, Edge<'lock>>,
fork_markers: &[Edge<'lock>],
known_conflicts: &FxHashMap<ConflictItem, MarkerTree>,
marker_context: &mut ConflictMarkerContext<'_>,
) -> FxHashMap<NodeIndex, MarkerTree> {
// For each node, track the conditions under which each conflict item is enabled.
let mut conflict_maps =
Expand Down Expand Up @@ -481,7 +484,7 @@ fn conflict_marker_reachability<'lock>(
Node::Package(package) => Some(package.name()),
Node::Root => None,
};
*marker = resolve_activated_extras(*marker, scope_package, conflict_map);
*marker = marker_context.resolve_activated_extras(*marker, scope_package, conflict_map);
});

// When we see an edge like `parent [dotenv]> flask`, we should take the reachability
Expand Down Expand Up @@ -511,7 +514,7 @@ fn conflict_marker_reachability<'lock>(
let marker = match child_edge.weight() {
Edge::Prod { marker, .. } => {
// Resolve any active extras on the edge.
resolve_activated_extras(*marker, scope_package, &parent_map)
marker_context.resolve_activated_extras(*marker, scope_package, &parent_map)
}
Edge::Optional { extra, marker, .. } => {
// The optional edge is only active when its extra is active. Preserve the
Expand All @@ -525,7 +528,11 @@ fn conflict_marker_reachability<'lock>(
};

// Resolve any active extras on the edge.
let marker = resolve_activated_extras(*marker, scope_package, &parent_map);
let marker = marker_context.resolve_activated_extras(
*marker,
scope_package,
&parent_map,
);
marker.and(active_marker)
}
Edge::Dev { group, marker, .. } => {
Expand All @@ -537,7 +544,7 @@ fn conflict_marker_reachability<'lock>(
}

// Resolve any active extras on the edge.
resolve_activated_extras(*marker, scope_package, &parent_map)
marker_context.resolve_activated_extras(*marker, scope_package, &parent_map)
}
};

Expand Down
9 changes: 4 additions & 5 deletions crates/uv-lock/src/lock/installable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use uv_platform_tags::Tags;
use uv_pypi_types::{ConflictKind, ConflictSet, ResolverMarkerEnvironment};

use uv_resolver_types::UniversalMarker;
use uv_resolver_types::universal_marker::ActivatedConflictItems;
use uv_resolver_types::universal_marker::{ActivatedConflictItems, ConflictMarkerContext};

use crate::lock::{
Dependency, DependencySelectionContext, HashedDist, LockErrorKind, Package, PackageIndex,
Expand Down Expand Up @@ -762,17 +762,16 @@ trait InstallableExt<'lock>: Installable<'lock> {
activated_extras.iter().copied(),
activated_groups.iter().copied(),
);
let mut marker_context = ConflictMarkerContext::new(self.lock().conflicts());
let mut selection = marker_context.for_selection(&activated);

while let Some((package_index, extra)) = queue.pop_front() {
let package = self.lock().package(package_index);
for dep in package_dependencies(package, extra) {
if validate_conflicts && dep.complexified_marker.has_conflict_marker() {
dependencies_for_conflict_validation.push((package, dep));
}
if !dep
.complexified_marker
.evaluate_activated(marker_env, &activated)
{
if !selection.evaluate(dep.complexified_marker, marker_env) {
continue;
}

Expand Down
28 changes: 0 additions & 28 deletions crates/uv-pep440/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,6 @@ pub enum Operator {
}

impl Operator {
/// Negates this operator, if a negation exists, so that it has the
/// opposite meaning.
///
/// This returns a negated operator in every case except for the `~=`
/// operator. In that case, `None` is returned and callers may need to
/// handle its negation at a higher level. (For example, if it's negated
/// in the context of a marker expression, then the "compatible" version
/// constraint can be split into its component parts and turned into a
/// disjunction of the negation of each of those parts.)
///
/// Note that this routine is not reversible in all cases. For example
/// `Operator::ExactEqual` negates to `Operator::NotEqual`, and
/// `Operator::NotEqual` in turn negates to `Operator::Equal`.
pub fn negate(self) -> Option<Self> {
Some(match self {
Self::Equal => Self::NotEqual,
Self::EqualStar => Self::NotEqualStar,
Self::ExactEqual => Self::NotEqual,
Self::NotEqual => Self::Equal,
Self::NotEqualStar => Self::EqualStar,
Self::TildeEqual => return None,
Self::LessThan => Self::GreaterThanEqual,
Self::LessThanEqual => Self::GreaterThan,
Self::GreaterThan => Self::LessThanEqual,
Self::GreaterThanEqual => Self::LessThan,
})
}

/// Returns true if and only if this operator can be used in a version
/// specifier with a version containing a non-empty local segment.
///
Expand Down
98 changes: 8 additions & 90 deletions crates/uv-pep508/src/marker/algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ use crate::{
ExtraOperator, MarkerExpression, MarkerOperator, MarkerValueString, MarkerValueVersion,
};

pub(super) mod isop;

/// The global node interner.
pub(crate) static INTERNER: LazyLock<Interner> = LazyLock::new(Interner::default);

Expand Down Expand Up @@ -942,98 +944,14 @@ impl InternerGuard<'_> {
}

let py_range = Ranges::from_range_bounds((py_lower.cloned(), py_upper.cloned()));
if py_range.is_empty() {
// Oops, the bounds imply there is nothing that can match,
// so we always evaluate to false.
return NodeId::FALSE;
}
if matches!(i, NodeId::TRUE) {
let var = Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion);
let edges = Edges::Version {
let versions = self.create_node(
Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion),
Edges::Version {
edges: Edges::from_range(&py_range),
};
return self.create_node(var, edges).negate(i);
}

let node = self.shared.node(i);
let Node {
var: Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion),
children: Edges::Version { edges },
} = node
else {
// Complexify all nodes recursively.
let children = node.children.map(i, |node_id| {
self.complexify_python_versions(node_id, py_lower, py_upper)
});
return self.create_node(node.var.clone(), children);
};
// The approach we take here is to filter out any range that
// has no intersection with our Python lower/upper bounds.
// These ranges will now always be false, so we can dismiss
// them entirely.
//
// Then, depending on whether we have finite lower/upper bound,
// we "fix up" the edges by clipping the existing ranges and
// adding an additional range that covers the Python versions
// outside of our bounds by always mapping them to false.
let mut new: SmallVec<_> = edges
.iter()
.filter(|(range, _)| !py_range.intersection(range).is_empty())
.cloned()
.collect();
// Below, we assume `new` has at least one element. It's
// subtle, but since 1) edges is a disjoint covering of the
// universe and 2) our `py_range` is non-empty at this point,
// it must intersect with at least one range.
assert!(
!new.is_empty(),
"expected at least one non-empty intersection"
},
);
// This is the NodeId we map to anything that should
// always be false. We have to "negate" it in case the
// parent is negated.
let exclude_node_id = NodeId::FALSE.negate(i);
if !matches!(py_lower, Bound::Unbounded) {
let &(ref first_range, first_node_id) = new.first().unwrap();
let first_upper = first_range.bounding_range().unwrap().1;
// When the first range is always false, then we can just
// "expand" it out to negative infinity to reflect that
// anything less than our lower bound should evaluate to
// false. If we don't do this, then we could have two
// adjacent ranges map to the same node, which would not be
// a canonical representation.
if exclude_node_id == first_node_id {
let clipped = Ranges::from_range_bounds((Bound::Unbounded, first_upper.cloned()));
*new.first_mut().unwrap() = (clipped, first_node_id);
} else {
let clipped = Ranges::from_range_bounds((py_lower.cloned(), first_upper.cloned()));
*new.first_mut().unwrap() = (clipped, first_node_id);

let py_range_lower =
Ranges::from_range_bounds((py_lower.cloned(), Bound::Unbounded));
new.insert(0, (py_range_lower.complement(), NodeId::FALSE.negate(i)));
}
}
if !matches!(py_upper, Bound::Unbounded) {
let &(ref last_range, last_node_id) = new.last().unwrap();
let last_lower = last_range.bounding_range().unwrap().0;
// See lower bound case above for why we do this. The
// same reasoning applies here: to maintain a canonical
// representation.
if exclude_node_id == last_node_id {
let clipped = Ranges::from_range_bounds((last_lower.cloned(), Bound::Unbounded));
*new.last_mut().unwrap() = (clipped, last_node_id);
} else {
let clipped = Ranges::from_range_bounds((last_lower.cloned(), py_upper.cloned()));
*new.last_mut().unwrap() = (clipped, last_node_id);

let py_range_upper =
Ranges::from_range_bounds((Bound::Unbounded, py_upper.cloned()));
new.push((py_range_upper.complement(), exclude_node_id));
}
}
self.create_node(node.var.clone(), Edges::Version { edges: new })
.negate(i)
// Conjunction inserts the version decision before extras and other later variables.
self.and(i, versions)
}

/// Check satisfiability without expanding paths, including known cross-variable exclusions.
Expand Down
Loading
Loading