@@ -9,7 +9,7 @@ use smallvec::SmallVec;
9
9
10
10
use crate :: {
11
11
internal:: {
12
- Arena , DecisionLevel , IncompDpId , Incompatibility , PartialSolution , Relation ,
12
+ Arena , DecisionLevel , Id , IncompDpId , Incompatibility , PartialSolution , Relation ,
13
13
SatisfierSearch ,
14
14
} ,
15
15
DependencyProvider , DerivationTree , Map , Package , PackageArena , Set , Term , VersionIndex ,
@@ -22,12 +22,10 @@ pub(crate) struct State<DP: DependencyProvider> {
22
22
root_package : Package ,
23
23
root_version_index : VersionIndex ,
24
24
25
- #[ allow( clippy:: type_complexity) ]
26
- incompatibilities : Map < Package , Vec < IncompDpId < DP > > > ,
25
+ incompatibilities : Vec < Vec < IncompDpId < DP > > > ,
27
26
28
27
/// All incompatibilities expressing dependencies,
29
28
/// with common dependents merged.
30
- #[ allow( clippy:: type_complexity) ]
31
29
merged_dependencies : Map < ( Package , Package ) , SmallVec < [ IncompDpId < DP > ; 4 ] > > ,
32
30
33
31
/// Partial solution.
@@ -49,13 +47,14 @@ impl<DP: DependencyProvider> State<DP> {
49
47
let mut incompatibility_store = Arena :: new ( ) ;
50
48
let not_root_id = incompatibility_store
51
49
. alloc ( Incompatibility :: not_root ( root_package, root_version_index) ) ;
52
- let mut incompatibilities = Map :: default ( ) ;
53
- incompatibilities. insert ( root_package, vec ! [ not_root_id] ) ;
50
+ let root_package_idx = root_package. 0 as usize ;
51
+ let mut incompatibilities = vec ! [ vec![ ] ; root_package_idx + 1 ] ;
52
+ incompatibilities[ root_package_idx] . push ( not_root_id) ;
54
53
Self {
55
54
root_package,
56
55
root_version_index,
57
56
incompatibilities,
58
- partial_solution : PartialSolution :: empty ( ) ,
57
+ partial_solution : PartialSolution :: empty ( root_package ) ,
59
58
incompatibility_store,
60
59
unit_propagation_buffer : Vec :: new ( ) ,
61
60
merged_dependencies : Map :: default ( ) ,
@@ -103,7 +102,8 @@ impl<DP: DependencyProvider> State<DP> {
103
102
// to evaluate first the newest incompatibilities.
104
103
let mut conflict_id = None ;
105
104
// We only care about incompatibilities if it contains the current package.
106
- for & incompat_id in self . incompatibilities [ & current_package] . iter ( ) . rev ( ) {
105
+ let idx = current_package. 0 as usize ;
106
+ for & incompat_id in self . incompatibilities [ idx] . iter ( ) . rev ( ) {
107
107
let current_incompat = & mut self . incompatibility_store [ incompat_id] ;
108
108
if self . partial_solution . is_contradicted ( current_incompat) {
109
109
continue ;
@@ -168,7 +168,6 @@ impl<DP: DependencyProvider> State<DP> {
168
168
169
169
/// Return the root cause or the terminal incompatibility.
170
170
/// CF <https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation>
171
- #[ allow( clippy:: type_complexity) ]
172
171
fn conflict_resolution (
173
172
& mut self ,
174
173
incompatibility : IncompDpId < DP > ,
@@ -248,6 +247,14 @@ impl<DP: DependencyProvider> State<DP> {
248
247
/// We could collapse them into { foo (1.0.0 ∪ 1.1.0), not bar ^1.0.0 }
249
248
/// without having to check the existence of other versions though.
250
249
fn merge_incompatibility ( & mut self , mut id : IncompDpId < DP > ) {
250
+ fn get_or_default < T > ( v : & mut Vec < Vec < Id < T > > > , pkg : Package ) -> & mut Vec < Id < T > > {
251
+ let pkg_idx = pkg. 0 as usize ;
252
+ if pkg_idx + 1 > v. len ( ) {
253
+ v. resize ( pkg_idx + 1 , Vec :: new ( ) ) ;
254
+ }
255
+ & mut v[ pkg_idx]
256
+ }
257
+
251
258
if let Some ( ( p1, p2) ) = self . incompatibility_store [ id] . as_dependency ( ) {
252
259
// If we are a dependency, there's a good chance we can be merged with a previous dependency
253
260
let deps_lookup = self . merged_dependencies . entry ( ( p1, p2) ) . or_default ( ) ;
@@ -258,10 +265,7 @@ impl<DP: DependencyProvider> State<DP> {
258
265
} ) {
259
266
let new = self . incompatibility_store . alloc ( merged) ;
260
267
for ( pkg, _) in self . incompatibility_store [ new] . iter ( ) {
261
- self . incompatibilities
262
- . entry ( pkg)
263
- . or_default ( )
264
- . retain ( |id| id != past) ;
268
+ get_or_default ( & mut self . incompatibilities , pkg) . retain ( |id| id != past) ;
265
269
}
266
270
* past = new;
267
271
id = new;
@@ -270,10 +274,8 @@ impl<DP: DependencyProvider> State<DP> {
270
274
}
271
275
}
272
276
for ( pkg, term) in self . incompatibility_store [ id] . iter ( ) {
273
- if cfg ! ( debug_assertions) {
274
- assert_ne ! ( term, Term :: any( ) ) ;
275
- }
276
- self . incompatibilities . entry ( pkg) . or_default ( ) . push ( id) ;
277
+ debug_assert_ne ! ( term, Term :: any( ) ) ;
278
+ get_or_default ( & mut self . incompatibilities , pkg) . push ( id) ;
277
279
}
278
280
}
279
281
0 commit comments