Skip to content

Commit

Permalink
fix: expose provider
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Jun 7, 2024
1 parent 4e0ac96 commit ad6a1e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Problem {
solver: &'a Solver<D, RT>,
) -> DisplayUnsat<'a, D> {
let graph = self.graph(solver);
DisplayUnsat::new(graph, &solver.cache.provider)
DisplayUnsat::new(graph, &solver.provider())

Check failure on line 168 in src/problem.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

this expression creates a reference which is immediately dereferenced by the compiler
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/solver/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
/// Keeps a cache of previously computed and/or requested information about
/// solvables and version sets.
pub struct SolverCache<D: DependencyProvider> {
pub(crate) provider: D,
provider: D,

/// A mapping from package name to a list of candidates.
candidates: Arena<CandidatesId, Candidates>,
Expand Down Expand Up @@ -66,6 +66,11 @@ impl<D: DependencyProvider> SolverCache<D> {
}
}

/// Returns the [`DependencyProvider`] used by this cache.
pub fn provider(&self) -> &D {
&self.provider
}

/// Returns the candidates for the package with the given name. This will
/// either ask the [`DependencyProvider`] for the entries or a cached
/// value.
Expand Down
42 changes: 20 additions & 22 deletions src/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(crate) enum PropagationError {
impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
/// Returns the dependency provider used by this instance.
pub fn provider(&self) -> &D {
&self.cache.provider
self.cache.provider()
}

/// Set the runtime of the solver to `runtime`.
Expand Down Expand Up @@ -308,11 +308,11 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
};

for version_set_id in chain(requirements.iter(), constrains.iter()).copied() {
let dependency_name = self.cache.provider.version_set_name(version_set_id);
let dependency_name = self.provider().version_set_name(version_set_id);
if clauses_added_for_package.insert(dependency_name) {
tracing::trace!(
"┝━ adding clauses for package '{}'",
self.cache.provider.display_name(dependency_name),
self.provider().display_name(dependency_name),
);

pending_futures.push(
Expand Down Expand Up @@ -372,7 +372,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
// Get the solvable information and request its requirements and constraints
tracing::trace!(
"package candidates available for {}",
self.cache.provider.display_name(name_id)
self.provider().display_name(name_id)
);

let locked_solvable_id = package_candidates.locked;
Expand Down Expand Up @@ -444,10 +444,9 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
} => {
tracing::trace!(
"sorted candidates available for {} {}",
self.cache
.provider
.display_name(self.cache.provider.version_set_name(version_set_id)),
self.cache.provider.display_version_set(version_set_id),
self.provider()
.display_name(self.provider().version_set_name(version_set_id)),
self.provider().display_version_set(version_set_id),
);

// Queue requesting the dependencies of the candidates as well if they are
Expand Down Expand Up @@ -499,10 +498,9 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
} => {
tracing::trace!(
"non matching candidates available for {} {}",
self.cache
.provider
.display_name(self.cache.provider.version_set_name(version_set_id)),
self.cache.provider.display_version_set(version_set_id),
self.provider()
.display_name(self.provider().version_set_name(version_set_id)),
self.provider().display_version_set(version_set_id),
);

// Add forbidden clauses for the candidates
Expand Down Expand Up @@ -601,7 +599,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
// The conflict was caused because new clauses have been added dynamically.
// We need to start over.
tracing::debug!("├─ added clause {clause} introduces a conflict which invalidates the partial solution",
clause=self.clauses.borrow()[clause_id].display(&self.cache.provider));
clause=self.clauses.borrow()[clause_id].display(self.provider()));
level = 0;
self.decision_tracker.clear();
continue;
Expand Down Expand Up @@ -651,7 +649,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
.format_with("\n- ", |(id, derived_from), f| f(&format_args!(
"{} (derived from {})",
id.display(self.provider()),
self.clauses.borrow()[derived_from].display(&self.cache.provider),
self.clauses.borrow()[derived_from].display(self.provider()),
)))
);

Expand All @@ -663,7 +661,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
// Serially process the outputs, to reduce the need for synchronization
for &clause_id in &output.conflicting_clauses {
tracing::debug!("├─ added clause {clause} introduces a conflict which invalidates the partial solution",
clause=self.clauses.borrow()[clause_id].display(&self.cache.provider));
clause=self.clauses.borrow()[clause_id].display(self.provider()));
}

if let Err(_first_conflicting_clause_id) = self.process_add_clause_output(output) {
Expand Down Expand Up @@ -780,8 +778,8 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
if let Some((count, (candidate, _solvable_id, clause_id))) = best_decision {
tracing::info!(
"deciding to assign {}, ({}, {} possible candidates)",
self.cache.provider.display_solvable(candidate),
self.clauses.borrow()[clause_id].display(&self.cache.provider),
self.provider().display_solvable(candidate),
self.clauses.borrow()[clause_id].display(self.provider()),
count,
);
}
Expand Down Expand Up @@ -872,7 +870,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
);
tracing::info!(
"│ During unit propagation for clause: {}",
self.clauses.borrow()[conflicting_clause].display(&self.cache.provider)
self.clauses.borrow()[conflicting_clause].display(self.provider())
);

tracing::info!(
Expand All @@ -882,7 +880,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
.decision_tracker
.find_clause_for_assignment(conflicting_solvable)
.unwrap()]
.display(&self.cache.provider),
.display(self.provider()),
);
}

Expand All @@ -901,7 +899,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
tracing::info!(
"* ({level}) {action} {}. Reason: {}",
decision.solvable_id.display(self.provider()),
clause.display(&self.cache.provider),
clause.display(self.provider()),
);
}

Expand Down Expand Up @@ -941,7 +939,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
/// solvable has become false, in which case it picks a new solvable to
/// watch (if available) or triggers an assignment.
fn propagate(&mut self, level: u32) -> Result<(), PropagationError> {
if let Some(value) = self.cache.provider.should_cancel_with_value() {
if let Some(value) = self.provider().should_cancel_with_value() {
return Err(PropagationError::Cancelled(value));
};

Expand Down Expand Up @@ -1097,7 +1095,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
"├─ Propagate {} = {}. {}",
remaining_watch.solvable_id.display(self.provider()),
remaining_watch.satisfying_value(),
clause.display(&self.cache.provider),
clause.display(self.provider()),
);
}
}
Expand Down

0 comments on commit ad6a1e3

Please sign in to comment.