3
3
use std:: cell:: RefCell ;
4
4
use std:: cmp:: PartialEq ;
5
5
use std:: cmp:: { max, min} ;
6
- use std:: collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ;
6
+ use std:: collections:: { BTreeMap , HashMap , HashSet } ;
7
7
use std:: fmt;
8
8
use std:: fmt:: Write ;
9
9
use std:: rc:: Rc ;
@@ -18,7 +18,7 @@ use cargo::core::{Dependency, PackageId, Registry, Summary};
18
18
use cargo:: core:: { GitReference , SourceId } ;
19
19
use cargo:: sources:: source:: QueryKind ;
20
20
use cargo:: sources:: IndexSummary ;
21
- use cargo:: util:: { CargoResult , Config , Graph , IntoUrl , RustVersion } ;
21
+ use cargo:: util:: { CargoResult , Config , IntoUrl , RustVersion } ;
22
22
23
23
use proptest:: collection:: { btree_map, vec} ;
24
24
use proptest:: prelude:: * ;
@@ -70,33 +70,6 @@ pub fn resolve_and_validated(
70
70
let out = resolve. sort ( ) ;
71
71
assert_eq ! ( out. len( ) , used. len( ) ) ;
72
72
73
- let mut pub_deps: HashMap < PackageId , HashSet < _ > > = HashMap :: new ( ) ;
74
- for & p in out. iter ( ) {
75
- // make the list of `p` public dependencies
76
- let mut self_pub_dep = HashSet :: new ( ) ;
77
- self_pub_dep. insert ( p) ;
78
- for ( dp, deps) in resolve. deps ( p) {
79
- if deps. iter ( ) . any ( |d| d. is_public ( ) ) {
80
- self_pub_dep. extend ( pub_deps[ & dp] . iter ( ) . cloned ( ) )
81
- }
82
- }
83
- pub_deps. insert ( p, self_pub_dep) ;
84
-
85
- // check if `p` has a public dependencies conflicts
86
- let seen_dep: BTreeSet < _ > = resolve
87
- . deps ( p)
88
- . flat_map ( |( dp, _) | pub_deps[ & dp] . iter ( ) . cloned ( ) )
89
- . collect ( ) ;
90
- let seen_dep: Vec < _ > = seen_dep. iter ( ) . collect ( ) ;
91
- for a in seen_dep. windows ( 2 ) {
92
- if a[ 0 ] . name ( ) == a[ 1 ] . name ( ) {
93
- panic ! (
94
- "the package {:?} can publicly see {:?} and {:?}" ,
95
- p, a[ 0 ] , a[ 1 ]
96
- )
97
- }
98
- }
99
- }
100
73
let sat_resolve = sat_resolve. unwrap_or_else ( || SatResolve :: new ( registry) ) ;
101
74
if !sat_resolve. sat_is_valid_solution ( & out) {
102
75
panic ! (
@@ -201,7 +174,6 @@ pub fn resolve_with_config_raw(
201
174
& mut registry,
202
175
& version_prefs,
203
176
Some ( config) ,
204
- true ,
205
177
) ;
206
178
207
179
// The largest test in our suite takes less then 30 sec.
@@ -295,7 +267,7 @@ impl SatResolve {
295
267
) ;
296
268
297
269
// no two semver compatible versions of the same package
298
- let by_activations_keys = sat_at_most_one_by_key (
270
+ sat_at_most_one_by_key (
299
271
& mut cnf,
300
272
var_for_is_packages_used
301
273
. iter ( )
@@ -313,119 +285,22 @@ impl SatResolve {
313
285
314
286
let empty_vec = vec ! [ ] ;
315
287
316
- let mut graph: Graph < PackageId , ( ) > = Graph :: new ( ) ;
317
-
318
- let mut version_selected_for: HashMap <
319
- PackageId ,
320
- HashMap < Dependency , HashMap < _ , varisat:: Var > > ,
321
- > = HashMap :: new ( ) ;
322
288
// active packages need each of there `deps` to be satisfied
323
289
for p in registry. iter ( ) {
324
- graph. add ( p. package_id ( ) ) ;
325
290
for dep in p. dependencies ( ) {
326
- // This can more easily be written as:
327
- // !is_active(p) or one of the things that match dep is_active
328
- // All the complexity, from here to the end, is to support public and private dependencies!
329
- let mut by_key: HashMap < _ , Vec < varisat:: Lit > > = HashMap :: new ( ) ;
330
- for & m in by_name
291
+ let mut matches: Vec < varisat:: Lit > = by_name
331
292
. get ( dep. package_name ( ) . as_str ( ) )
332
293
. unwrap_or ( & empty_vec)
333
294
. iter ( )
334
295
. filter ( |& p| dep. matches_id ( * p) )
335
- {
336
- graph. link ( p. package_id ( ) , m) ;
337
- by_key
338
- . entry ( m. as_activations_key ( ) )
339
- . or_default ( )
340
- . push ( var_for_is_packages_used[ & m] . positive ( ) ) ;
341
- }
342
- let keys: HashMap < _ , _ > = by_key. keys ( ) . map ( |& k| ( k, cnf. new_var ( ) ) ) . collect ( ) ;
343
-
344
- // if `p` is active then we need to select one of the keys
345
- let matches: Vec < _ > = keys
346
- . values ( )
347
- . map ( |v| v. positive ( ) )
348
- . chain ( Some ( var_for_is_packages_used[ & p. package_id ( ) ] . negative ( ) ) )
296
+ . map ( |p| var_for_is_packages_used[ & p] . positive ( ) )
349
297
. collect ( ) ;
298
+ // ^ the `dep` is satisfied or `p` is not active
299
+ matches. push ( var_for_is_packages_used[ & p. package_id ( ) ] . negative ( ) ) ;
350
300
cnf. add_clause ( & matches) ;
351
-
352
- // if a key is active then we need to select one of the versions
353
- for ( key, vars) in by_key. iter ( ) {
354
- let mut matches = vars. clone ( ) ;
355
- matches. push ( keys[ key] . negative ( ) ) ;
356
- cnf. add_clause ( & matches) ;
357
- }
358
-
359
- version_selected_for
360
- . entry ( p. package_id ( ) )
361
- . or_default ( )
362
- . insert ( dep. clone ( ) , keys) ;
363
301
}
364
302
}
365
303
366
- let topological_order = graph. sort ( ) ;
367
-
368
- // we already ensure there is only one version for each `activations_key` so we can think of
369
- // `publicly_exports` as being in terms of a set of `activations_key`s
370
- let mut publicly_exports: HashMap < _ , HashMap < _ , varisat:: Var > > = HashMap :: new ( ) ;
371
-
372
- for & key in by_activations_keys. keys ( ) {
373
- // everything publicly depends on itself
374
- let var = publicly_exports
375
- . entry ( key)
376
- . or_default ( )
377
- . entry ( key)
378
- . or_insert_with ( || cnf. new_var ( ) ) ;
379
- cnf. add_clause ( & [ var. positive ( ) ] ) ;
380
- }
381
-
382
- // if a `dep` is public then `p` `publicly_exports` all the things that the selected version `publicly_exports`
383
- for & p in topological_order. iter ( ) {
384
- if let Some ( deps) = version_selected_for. get ( & p) {
385
- let mut p_exports = publicly_exports. remove ( & p. as_activations_key ( ) ) . unwrap ( ) ;
386
- for ( _, versions) in deps. iter ( ) . filter ( |( d, _) | d. is_public ( ) ) {
387
- for ( ver, sel) in versions {
388
- for ( & export_pid, & export_var) in publicly_exports[ ver] . iter ( ) {
389
- let our_var =
390
- p_exports. entry ( export_pid) . or_insert_with ( || cnf. new_var ( ) ) ;
391
- cnf. add_clause ( & [
392
- sel. negative ( ) ,
393
- export_var. negative ( ) ,
394
- our_var. positive ( ) ,
395
- ] ) ;
396
- }
397
- }
398
- }
399
- publicly_exports. insert ( p. as_activations_key ( ) , p_exports) ;
400
- }
401
- }
402
-
403
- // we already ensure there is only one version for each `activations_key` so we can think of
404
- // `can_see` as being in terms of a set of `activations_key`s
405
- // and if `p` `publicly_exports` `export` then it `can_see` `export`
406
- let mut can_see: HashMap < _ , HashMap < _ , varisat:: Var > > = HashMap :: new ( ) ;
407
-
408
- // if `p` has a `dep` that selected `ver` then it `can_see` all the things that the selected version `publicly_exports`
409
- for ( & p, deps) in version_selected_for. iter ( ) {
410
- let p_can_see = can_see. entry ( p) . or_default ( ) ;
411
- for ( _, versions) in deps. iter ( ) {
412
- for ( & ver, sel) in versions {
413
- for ( & export_pid, & export_var) in publicly_exports[ & ver] . iter ( ) {
414
- let our_var = p_can_see. entry ( export_pid) . or_insert_with ( || cnf. new_var ( ) ) ;
415
- cnf. add_clause ( & [
416
- sel. negative ( ) ,
417
- export_var. negative ( ) ,
418
- our_var. positive ( ) ,
419
- ] ) ;
420
- }
421
- }
422
- }
423
- }
424
-
425
- // a package `can_see` only one version by each name
426
- for ( _, see) in can_see. iter ( ) {
427
- sat_at_most_one_by_key ( & mut cnf, see. iter ( ) . map ( |( ( name, _, _) , & v) | ( name, v) ) ) ;
428
- }
429
304
let mut solver = varisat:: Solver :: new ( ) ;
430
305
solver. add_formula ( & cnf) ;
431
306
@@ -644,10 +519,9 @@ pub fn dep(name: &str) -> Dependency {
644
519
pub fn dep_req ( name : & str , req : & str ) -> Dependency {
645
520
Dependency :: parse ( name, Some ( req) , registry_loc ( ) ) . unwrap ( )
646
521
}
647
- pub fn dep_req_kind ( name : & str , req : & str , kind : DepKind , public : bool ) -> Dependency {
522
+ pub fn dep_req_kind ( name : & str , req : & str , kind : DepKind ) -> Dependency {
648
523
let mut dep = dep_req ( name, req) ;
649
524
dep. set_kind ( kind) ;
650
- dep. set_public ( public) ;
651
525
dep
652
526
}
653
527
@@ -740,8 +614,8 @@ fn meta_test_deep_pretty_print_registry() {
740
614
pkg!( ( "bar" , "2.0.0" ) => [ dep_req( "baz" , "=1.0.1" ) ] ) ,
741
615
pkg!( ( "baz" , "1.0.2" ) => [ dep_req( "other" , "2" ) ] ) ,
742
616
pkg!( ( "baz" , "1.0.1" ) ) ,
743
- pkg!( ( "cat" , "1.0.2" ) => [ dep_req_kind( "other" , "2" , DepKind :: Build , false ) ] ) ,
744
- pkg!( ( "cat" , "1.0.3" ) => [ dep_req_kind( "other" , "2" , DepKind :: Development , false ) ] ) ,
617
+ pkg!( ( "cat" , "1.0.2" ) => [ dep_req_kind( "other" , "2" , DepKind :: Build ) ] ) ,
618
+ pkg!( ( "cat" , "1.0.3" ) => [ dep_req_kind( "other" , "2" , DepKind :: Development ) ] ) ,
745
619
pkg!( ( "dep_req" , "1.0.0" ) ) ,
746
620
pkg!( ( "dep_req" , "2.0.0" ) ) ,
747
621
] )
@@ -804,14 +678,7 @@ pub fn registry_strategy(
804
678
let max_deps = max_versions * ( max_crates * ( max_crates - 1 ) ) / shrinkage;
805
679
806
680
let raw_version_range = ( any :: < Index > ( ) , any :: < Index > ( ) ) ;
807
- let raw_dependency = (
808
- any :: < Index > ( ) ,
809
- any :: < Index > ( ) ,
810
- raw_version_range,
811
- 0 ..=1 ,
812
- Just ( false ) ,
813
- // TODO: ^ this needs to be set back to `any::<bool>()` and work before public & private dependencies can stabilize
814
- ) ;
681
+ let raw_dependency = ( any :: < Index > ( ) , any :: < Index > ( ) , raw_version_range, 0 ..=1 ) ;
815
682
816
683
fn order_index ( a : Index , b : Index , size : usize ) -> ( usize , usize ) {
817
684
let ( a, b) = ( a. index ( size) , b. index ( size) ) ;
@@ -838,7 +705,7 @@ pub fn registry_strategy(
838
705
. collect ( ) ;
839
706
let len_all_pkgid = list_of_pkgid. len ( ) ;
840
707
let mut dependency_by_pkgid = vec ! [ vec![ ] ; len_all_pkgid] ;
841
- for ( a, b, ( c, d) , k, p ) in raw_dependencies {
708
+ for ( a, b, ( c, d) , k) in raw_dependencies {
842
709
let ( a, b) = order_index ( a, b, len_all_pkgid) ;
843
710
let ( a, b) = if reverse_alphabetical { ( b, a) } else { ( a, b) } ;
844
711
let ( ( dep_name, _) , _) = list_of_pkgid[ a] ;
@@ -868,7 +735,6 @@ pub fn registry_strategy(
868
735
// => DepKind::Development, // Development has no impact so don't gen
869
736
_ => panic ! ( "bad index for DepKind" ) ,
870
737
} ,
871
- p && k == 0 ,
872
738
) )
873
739
}
874
740
0 commit comments