33use  std:: cell:: RefCell ; 
44use  std:: cmp:: PartialEq ; 
55use  std:: cmp:: { max,  min} ; 
6- use  std:: collections:: { BTreeMap ,  BTreeSet ,   HashMap ,  HashSet } ; 
6+ use  std:: collections:: { BTreeMap ,  HashMap ,  HashSet } ; 
77use  std:: fmt; 
88use  std:: fmt:: Write ; 
99use  std:: rc:: Rc ; 
@@ -18,7 +18,7 @@ use cargo::core::{Dependency, PackageId, Registry, Summary};
1818use  cargo:: core:: { GitReference ,  SourceId } ; 
1919use  cargo:: sources:: source:: QueryKind ; 
2020use  cargo:: sources:: IndexSummary ; 
21- use  cargo:: util:: { CargoResult ,  Config ,  Graph ,   IntoUrl ,  RustVersion } ; 
21+ use  cargo:: util:: { CargoResult ,  Config ,  IntoUrl ,  RustVersion } ; 
2222
2323use  proptest:: collection:: { btree_map,  vec} ; 
2424use  proptest:: prelude:: * ; 
@@ -70,33 +70,6 @@ pub fn resolve_and_validated(
7070            let  out = resolve. sort ( ) ; 
7171            assert_eq ! ( out. len( ) ,  used. len( ) ) ; 
7272
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-             } 
10073            let  sat_resolve = sat_resolve. unwrap_or_else ( || SatResolve :: new ( registry) ) ; 
10174            if  !sat_resolve. sat_is_valid_solution ( & out)  { 
10275                panic ! ( 
@@ -201,7 +174,6 @@ pub fn resolve_with_config_raw(
201174        & mut  registry, 
202175        & version_prefs, 
203176        Some ( config) , 
204-         true , 
205177    ) ; 
206178
207179    // The largest test in our suite takes less then 30 sec. 
@@ -295,7 +267,7 @@ impl SatResolve {
295267        ) ; 
296268
297269        // 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 ( 
299271            & mut  cnf, 
300272            var_for_is_packages_used
301273                . iter ( ) 
@@ -313,119 +285,22 @@ impl SatResolve {
313285
314286        let  empty_vec = vec ! [ ] ; 
315287
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 ( ) ; 
322288        // active packages need each of there `deps` to be satisfied 
323289        for  p in  registry. iter ( )  { 
324-             graph. add ( p. package_id ( ) ) ; 
325290            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
331292                    . get ( dep. package_name ( ) . as_str ( ) ) 
332293                    . unwrap_or ( & empty_vec) 
333294                    . iter ( ) 
334295                    . 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 ( ) ) 
349297                    . collect ( ) ; 
298+                 // ^ the `dep` is satisfied or `p` is not active 
299+                 matches. push ( var_for_is_packages_used[ & p. package_id ( ) ] . negative ( ) ) ; 
350300                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) ; 
363301            } 
364302        } 
365303
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-         } 
429304        let  mut  solver = varisat:: Solver :: new ( ) ; 
430305        solver. add_formula ( & cnf) ; 
431306
@@ -644,10 +519,9 @@ pub fn dep(name: &str) -> Dependency {
644519pub  fn  dep_req ( name :  & str ,  req :  & str )  -> Dependency  { 
645520    Dependency :: parse ( name,  Some ( req) ,  registry_loc ( ) ) . unwrap ( ) 
646521} 
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  { 
648523    let  mut  dep = dep_req ( name,  req) ; 
649524    dep. set_kind ( kind) ; 
650-     dep. set_public ( public) ; 
651525    dep
652526} 
653527
@@ -740,8 +614,8 @@ fn meta_test_deep_pretty_print_registry() {
740614                pkg!( ( "bar" ,  "2.0.0" )  => [ dep_req( "baz" ,  "=1.0.1" ) ] ) , 
741615                pkg!( ( "baz" ,  "1.0.2" )  => [ dep_req( "other" ,  "2" ) ] ) , 
742616                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 ) ] ) , 
745619                pkg!( ( "dep_req" ,  "1.0.0" ) ) , 
746620                pkg!( ( "dep_req" ,  "2.0.0" ) ) , 
747621            ] ) 
@@ -804,14 +678,7 @@ pub fn registry_strategy(
804678    let  max_deps = max_versions *  ( max_crates *  ( max_crates - 1 ) )  / shrinkage; 
805679
806680    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 ) ; 
815682
816683    fn  order_index ( a :  Index ,  b :  Index ,  size :  usize )  -> ( usize ,  usize )  { 
817684        let  ( a,  b)  = ( a. index ( size) ,  b. index ( size) ) ; 
@@ -838,7 +705,7 @@ pub fn registry_strategy(
838705                    . collect ( ) ; 
839706                let  len_all_pkgid = list_of_pkgid. len ( ) ; 
840707                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 { 
842709                    let  ( a,  b)  = order_index ( a,  b,  len_all_pkgid) ; 
843710                    let  ( a,  b)  = if  reverse_alphabetical {  ( b,  a)  }  else  {  ( a,  b)  } ; 
844711                    let  ( ( dep_name,  _) ,  _)  = list_of_pkgid[ a] ; 
@@ -868,7 +735,6 @@ pub fn registry_strategy(
868735                            // => DepKind::Development, // Development has no impact so don't gen 
869736                            _ => panic ! ( "bad index for DepKind" ) , 
870737                        } , 
871-                         p && k == 0 , 
872738                    ) ) 
873739                } 
874740
0 commit comments