@@ -2,12 +2,11 @@ use super::dep_cache::RegistryQueryer;
22use super :: errors:: ActivateResult ;
33use super :: types:: { ConflictMap , ConflictReason , FeaturesSet , ResolveOpts } ;
44use super :: RequestedFeatures ;
5- use crate :: core:: { Dependency , PackageId , SourceId , Summary } ;
5+ use crate :: core:: { ActivationsKey , Dependency , PackageId , Summary } ;
66use crate :: util:: interning:: InternedString ;
77use crate :: util:: Graph ;
88use anyhow:: format_err;
99use std:: collections:: HashMap ;
10- use std:: num:: NonZeroU64 ;
1110use tracing:: debug;
1211
1312// A `Context` is basically a bunch of local resolution information which is
@@ -22,56 +21,21 @@ pub struct ResolverContext {
2221 pub resolve_features : im_rc:: HashMap < PackageId , FeaturesSet , rustc_hash:: FxBuildHasher > ,
2322 /// get the package that will be linking to a native library by its links attribute
2423 pub links : im_rc:: HashMap < InternedString , PackageId , rustc_hash:: FxBuildHasher > ,
25-
2624 /// a way to look up for a package in activations what packages required it
2725 /// and all of the exact deps that it fulfilled.
2826 pub parents : Graph < PackageId , im_rc:: HashSet < Dependency , rustc_hash:: FxBuildHasher > > ,
2927}
3028
29+ pub type Activations =
30+ im_rc:: HashMap < ActivationsKey , ( Summary , ContextAge ) , rustc_hash:: FxBuildHasher > ;
31+
3132/// When backtracking it can be useful to know how far back to go.
3233/// The `ContextAge` of a `Context` is a monotonically increasing counter of the number
3334/// of decisions made to get to this state.
3435/// Several structures store the `ContextAge` when it was added,
3536/// to be used in `find_candidate` for backtracking.
3637pub type ContextAge = usize ;
3738
38- /// Find the activated version of a crate based on the name, source, and semver compatibility.
39- /// By storing this in a hash map we ensure that there is only one
40- /// semver compatible version of each crate.
41- /// This all so stores the `ContextAge`.
42- pub type ActivationsKey = ( InternedString , SourceId , SemverCompatibility ) ;
43-
44- pub type Activations =
45- im_rc:: HashMap < ActivationsKey , ( Summary , ContextAge ) , rustc_hash:: FxBuildHasher > ;
46-
47- /// A type that represents when cargo treats two Versions as compatible.
48- /// Versions `a` and `b` are compatible if their left-most nonzero digit is the
49- /// same.
50- #[ derive( Clone , Copy , Eq , PartialEq , Hash , Debug , PartialOrd , Ord ) ]
51- pub enum SemverCompatibility {
52- Major ( NonZeroU64 ) ,
53- Minor ( NonZeroU64 ) ,
54- Patch ( u64 ) ,
55- }
56-
57- impl From < & semver:: Version > for SemverCompatibility {
58- fn from ( ver : & semver:: Version ) -> Self {
59- if let Some ( m) = NonZeroU64 :: new ( ver. major ) {
60- return SemverCompatibility :: Major ( m) ;
61- }
62- if let Some ( m) = NonZeroU64 :: new ( ver. minor ) {
63- return SemverCompatibility :: Minor ( m) ;
64- }
65- SemverCompatibility :: Patch ( ver. patch )
66- }
67- }
68-
69- impl PackageId {
70- pub fn as_activations_key ( self ) -> ActivationsKey {
71- ( self . name ( ) , self . source_id ( ) , self . version ( ) . into ( ) )
72- }
73- }
74-
7539impl ResolverContext {
7640 pub fn new ( ) -> ResolverContext {
7741 ResolverContext {
0 commit comments