-
Notifications
You must be signed in to change notification settings - Fork 29
Fix assertion failure when a package constrains itself #230
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
Open
dralley
wants to merge
1
commit into
prefix-dev:main
Choose a base branch
from
dralley:constrains-itself
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,6 +176,23 @@ impl<N> Clauses<N> { | |
|
|
||
| type RequirementCandidateVariables = Vec<Vec<VariableId>>; | ||
|
|
||
| /// Configuration options for the solver. | ||
| #[derive(Debug, Clone)] | ||
| pub struct SolverConfig { | ||
| /// When `true`, a package that conflicts with something it also provides | ||
| /// (i.e. it conflicts with itself) is marked uninstallable. When `false`, | ||
| /// self-conflicts are silently ignored. | ||
| pub forbid_self_conflicts: bool, | ||
| } | ||
|
|
||
| impl Default for SolverConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| forbid_self_conflicts: true, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Drives the SAT solving process. | ||
| pub struct Solver<D: DependencyProvider, RT: AsyncRuntime = NowOrNeverRuntime> { | ||
| /// The runtime to use for async operations. | ||
|
|
@@ -187,6 +204,9 @@ pub struct Solver<D: DependencyProvider, RT: AsyncRuntime = NowOrNeverRuntime> { | |
| /// Holds the current state of the solver. | ||
| pub(crate) state: SolverState<D>, | ||
|
|
||
| /// Solver configuration options. | ||
| config: SolverConfig, | ||
|
|
||
| /// The activity add factor. This is a value that is added to the activity | ||
| /// score of each package that is part of a conflict. | ||
| activity_add: f32, | ||
|
|
@@ -368,10 +388,12 @@ impl<D: DependencyProvider> Solver<D, NowOrNeverRuntime> { | |
| /// Creates a single threaded block solver, using the provided | ||
| /// [`DependencyProvider`]. | ||
| pub fn new(provider: D) -> Self { | ||
| let config = provider.solver_config(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uses the config provided by |
||
| Self { | ||
| cache: SolverCache::new(provider), | ||
| async_runtime: NowOrNeverRuntime, | ||
| state: SolverState::default(), | ||
| config, | ||
| activity_add: 1.0, | ||
| activity_decay: 0.95, | ||
| } | ||
|
|
@@ -448,6 +470,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> { | |
| async_runtime: runtime, | ||
| cache: self.cache, | ||
| state: self.state, | ||
| config: self.config, | ||
| activity_decay: self.activity_decay, | ||
| activity_add: self.activity_add, | ||
| } | ||
|
|
@@ -464,6 +487,12 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> { | |
| } | ||
| } | ||
|
|
||
| /// Set the solver configuration. | ||
| #[must_use] | ||
| pub fn with_config(self, config: SolverConfig) -> Self { | ||
| Self { config, ..self } | ||
| } | ||
|
|
||
| /// Solves the given [`Problem`]. | ||
| /// | ||
| /// The solver first solves for the root requirements and constraints, and | ||
|
|
@@ -634,7 +663,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> { | |
| #[cfg(feature = "diagnostics")] | ||
| let encoding_start = std::time::Instant::now(); | ||
| let conflicting_clauses = self.async_runtime.block_on( | ||
| Encoder::new(&mut self.state, &self.cache, root_deps, level) | ||
| Encoder::new(&mut self.state, &self.cache, &self.config, root_deps, level) | ||
| .encode([root_solvable]), | ||
| )?; | ||
| #[cfg(feature = "diagnostics")] | ||
|
|
@@ -789,7 +818,7 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> { | |
| #[cfg(feature = "diagnostics")] | ||
| let encoding_start = std::time::Instant::now(); | ||
| let conflicting_clauses = self.async_runtime.block_on( | ||
| Encoder::new(&mut self.state, &self.cache, root_deps, level) | ||
| Encoder::new(&mut self.state, &self.cache, &self.config, root_deps, level) | ||
| .encode_with_deferred(solvable_ids.iter().copied(), deferred_to_encode), | ||
| )?; | ||
| #[cfg(feature = "diagnostics")] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@baszalmstra Do you think this is reasonable?
Libsolv offers a couple such options (e.g. 1, 2), but I know your intention is to stay as generic as possible.
I also have a
Candidatesbased implementation, but I don't think it actually ends up simpler and is probably less performant, since it is treated as a a global option so if you were to emulate it with a map per-nameid or per-solvable then it would require a lot of hashmap insertions and subsequent lookups where the answer will always be the same. The additional flexibility isn't needed, at least not by RPM.