Skip to content

Commit

Permalink
Add a method to retrieve unchanging terms for a package
Browse files Browse the repository at this point in the history
When prefetching, we want to avoid prefetching packages we will certainly reject. `PartialSolution::unchanging_term_for_package` returns the terms from root that a certain independent from the current partial solution. See pubgrub-rs#263 (comment)
  • Loading branch information
konstin committed Oct 16, 2024
1 parent 19c7726 commit 3daf4b1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/internal/partial_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,18 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
pub(crate) fn current_decision_level(&self) -> DecisionLevel {
self.current_decision_level
}

/// Retrieve the constraints on a package that will not change.
pub fn unchanging_term_for_package(&self, package: &DP::P) -> Option<&Term<DP::VS>> {
let pa = self.package_assignments.get(package)?;

let idx_newer = pa
.dated_derivations
.as_slice()
.partition_point(|dd| dd.decision_level <= DecisionLevel(1));
let idx = idx_newer.checked_sub(1)?;
Some(&pa.dated_derivations[idx].accumulated_intersection)
}
}

impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> PackageAssignments<P, VS, M> {
Expand Down

0 comments on commit 3daf4b1

Please sign in to comment.