@@ -15,38 +15,37 @@ use crate::internal::partial_solution::{DecisionLevel, PartialSolution};
15
15
use crate :: internal:: small_vec:: SmallVec ;
16
16
use crate :: package:: Package ;
17
17
use crate :: report:: DerivationTree ;
18
- use crate :: solver:: DependencyConstraints ;
19
- use crate :: type_aliases:: Map ;
20
- use crate :: version:: Version ;
18
+ use crate :: type_aliases:: { DependencyConstraints , Map } ;
19
+ use crate :: version_set:: VersionSet ;
21
20
22
21
/// Current state of the PubGrub algorithm.
23
22
#[ derive( Clone ) ]
24
- pub struct State < P : Package , V : Version > {
23
+ pub struct State < P : Package , VS : VersionSet > {
25
24
root_package : P ,
26
- root_version : V ,
25
+ root_version : VS :: V ,
27
26
28
- incompatibilities : Map < P , Vec < IncompId < P , V > > > ,
27
+ incompatibilities : Map < P , Vec < IncompId < P , VS > > > ,
29
28
30
29
/// Store the ids of incompatibilities that are already contradicted
31
30
/// and will stay that way until the next conflict and backtrack is operated.
32
- contradicted_incompatibilities : rustc_hash:: FxHashSet < IncompId < P , V > > ,
31
+ contradicted_incompatibilities : rustc_hash:: FxHashSet < IncompId < P , VS > > ,
33
32
34
33
/// Partial solution.
35
34
/// TODO: remove pub.
36
- pub partial_solution : PartialSolution < P , V > ,
35
+ pub partial_solution : PartialSolution < P , VS > ,
37
36
38
37
/// The store is the reference storage for all incompatibilities.
39
- pub incompatibility_store : Arena < Incompatibility < P , V > > ,
38
+ pub incompatibility_store : Arena < Incompatibility < P , VS > > ,
40
39
41
40
/// This is a stack of work to be done in `unit_propagation`.
42
41
/// It can definitely be a local variable to that method, but
43
42
/// this way we can reuse the same allocation for better performance.
44
43
unit_propagation_buffer : SmallVec < P > ,
45
44
}
46
45
47
- impl < P : Package , V : Version > State < P , V > {
46
+ impl < P : Package , VS : VersionSet > State < P , VS > {
48
47
/// Initialization of PubGrub state.
49
- pub fn init ( root_package : P , root_version : V ) -> Self {
48
+ pub fn init ( root_package : P , root_version : VS :: V ) -> Self {
50
49
let mut incompatibility_store = Arena :: new ( ) ;
51
50
let not_root_id = incompatibility_store. alloc ( Incompatibility :: not_root (
52
51
root_package. clone ( ) ,
@@ -66,7 +65,7 @@ impl<P: Package, V: Version> State<P, V> {
66
65
}
67
66
68
67
/// Add an incompatibility to the state.
69
- pub fn add_incompatibility ( & mut self , incompat : Incompatibility < P , V > ) {
68
+ pub fn add_incompatibility ( & mut self , incompat : Incompatibility < P , VS > ) {
70
69
let id = self . incompatibility_store . alloc ( incompat) ;
71
70
self . merge_incompatibility ( id) ;
72
71
}
@@ -75,9 +74,9 @@ impl<P: Package, V: Version> State<P, V> {
75
74
pub fn add_incompatibility_from_dependencies (
76
75
& mut self ,
77
76
package : P ,
78
- version : V ,
79
- deps : & DependencyConstraints < P , V > ,
80
- ) -> std:: ops:: Range < IncompId < P , V > > {
77
+ version : VS :: V ,
78
+ deps : & DependencyConstraints < P , VS > ,
79
+ ) -> std:: ops:: Range < IncompId < P , VS > > {
81
80
// Create incompatibilities and allocate them in the store.
82
81
let new_incompats_id_range = self
83
82
. incompatibility_store
@@ -92,13 +91,13 @@ impl<P: Package, V: Version> State<P, V> {
92
91
}
93
92
94
93
/// Check if an incompatibility is terminal.
95
- pub fn is_terminal ( & self , incompatibility : & Incompatibility < P , V > ) -> bool {
94
+ pub fn is_terminal ( & self , incompatibility : & Incompatibility < P , VS > ) -> bool {
96
95
incompatibility. is_terminal ( & self . root_package , & self . root_version )
97
96
}
98
97
99
98
/// Unit propagation is the core mechanism of the solving algorithm.
100
99
/// CF <https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation>
101
- pub fn unit_propagation ( & mut self , package : P ) -> Result < ( ) , PubGrubError < P , V > > {
100
+ pub fn unit_propagation ( & mut self , package : P ) -> Result < ( ) , PubGrubError < P , VS > > {
102
101
self . unit_propagation_buffer . clear ( ) ;
103
102
self . unit_propagation_buffer . push ( package) ;
104
103
while let Some ( current_package) = self . unit_propagation_buffer . pop ( ) {
@@ -162,8 +161,8 @@ impl<P: Package, V: Version> State<P, V> {
162
161
/// CF <https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation>
163
162
fn conflict_resolution (
164
163
& mut self ,
165
- incompatibility : IncompId < P , V > ,
166
- ) -> Result < ( P , IncompId < P , V > ) , PubGrubError < P , V > > {
164
+ incompatibility : IncompId < P , VS > ,
165
+ ) -> Result < ( P , IncompId < P , VS > ) , PubGrubError < P , VS > > {
167
166
let mut current_incompat_id = incompatibility;
168
167
let mut current_incompat_changed = false ;
169
168
loop {
@@ -209,7 +208,7 @@ impl<P: Package, V: Version> State<P, V> {
209
208
/// Backtracking.
210
209
fn backtrack (
211
210
& mut self ,
212
- incompat : IncompId < P , V > ,
211
+ incompat : IncompId < P , VS > ,
213
212
incompat_changed : bool ,
214
213
decision_level : DecisionLevel ,
215
214
) {
@@ -240,7 +239,7 @@ impl<P: Package, V: Version> State<P, V> {
240
239
/// Here we do the simple stupid thing of just growing the Vec.
241
240
/// It may not be trivial since those incompatibilities
242
241
/// may already have derived others.
243
- fn merge_incompatibility ( & mut self , id : IncompId < P , V > ) {
242
+ fn merge_incompatibility ( & mut self , id : IncompId < P , VS > ) {
244
243
for ( pkg, _term) in self . incompatibility_store [ id] . iter ( ) {
245
244
self . incompatibilities
246
245
. entry ( pkg. clone ( ) )
@@ -251,12 +250,12 @@ impl<P: Package, V: Version> State<P, V> {
251
250
252
251
// Error reporting #########################################################
253
252
254
- fn build_derivation_tree ( & self , incompat : IncompId < P , V > ) -> DerivationTree < P , V > {
253
+ fn build_derivation_tree ( & self , incompat : IncompId < P , VS > ) -> DerivationTree < P , VS > {
255
254
let shared_ids = self . find_shared_ids ( incompat) ;
256
255
Incompatibility :: build_derivation_tree ( incompat, & shared_ids, & self . incompatibility_store )
257
256
}
258
257
259
- fn find_shared_ids ( & self , incompat : IncompId < P , V > ) -> Set < IncompId < P , V > > {
258
+ fn find_shared_ids ( & self , incompat : IncompId < P , VS > ) -> Set < IncompId < P , VS > > {
260
259
let mut all_ids = Set :: new ( ) ;
261
260
let mut shared_ids = Set :: new ( ) ;
262
261
let mut stack = vec ! [ incompat] ;
0 commit comments