From 3daf4b12a405615411d6a879b527206c2be8c48d Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 16 Oct 2024 11:02:57 +0200 Subject: [PATCH] Add a method to retrieve unchanging terms for a package 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 https://github.com/pubgrub-rs/pubgrub/issues/263#issuecomment-2414871726 --- src/internal/partial_solution.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/internal/partial_solution.rs b/src/internal/partial_solution.rs index ef2cb17e..1f605685 100644 --- a/src/internal/partial_solution.rs +++ b/src/internal/partial_solution.rs @@ -521,6 +521,18 @@ impl PartialSolution { 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> { + 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 PackageAssignments {