@@ -2,7 +2,7 @@ use super::dep_cache::RegistryQueryer;
2
2
use super :: errors:: ActivateResult ;
3
3
use super :: types:: { ConflictMap , ConflictReason , FeaturesSet , ResolveOpts } ;
4
4
use super :: RequestedFeatures ;
5
- use crate :: core:: { ActivationsKey , Dependency , PackageId , Summary } ;
5
+ use crate :: core:: { ActivationKey , Dependency , PackageId , Summary } ;
6
6
use crate :: util:: interning:: InternedString ;
7
7
use crate :: util:: Graph ;
8
8
use anyhow:: format_err;
@@ -26,8 +26,13 @@ pub struct ResolverContext {
26
26
pub parents : Graph < PackageId , im_rc:: HashSet < Dependency , rustc_hash:: FxBuildHasher > > ,
27
27
}
28
28
29
- pub type Activations =
30
- im_rc:: HashMap < ActivationsKey , ( Summary , ContextAge ) , rustc_hash:: FxBuildHasher > ;
29
+ /// By storing activation keys in a `HashMap` we ensure that there is only one
30
+ /// semver compatible version of each crate.
31
+ type Activations = im_rc:: HashMap <
32
+ ActivationKey ,
33
+ ( Summary , ContextAge ) ,
34
+ nohash_hasher:: BuildNoHashHasher < ActivationKey > ,
35
+ > ;
31
36
32
37
/// When backtracking it can be useful to know how far back to go.
33
38
/// The `ContextAge` of a `Context` is a monotonically increasing counter of the number
@@ -62,7 +67,7 @@ impl ResolverContext {
62
67
) -> ActivateResult < bool > {
63
68
let id = summary. package_id ( ) ;
64
69
let age: ContextAge = self . age ;
65
- match self . activations . entry ( id. as_activations_key ( ) ) {
70
+ match self . activations . entry ( id. activation_key ( ) ) {
66
71
im_rc:: hashmap:: Entry :: Occupied ( o) => {
67
72
debug_assert_eq ! (
68
73
& o. get( ) . 0 ,
@@ -101,8 +106,13 @@ impl ResolverContext {
101
106
// versions came from a `[patch]` source.
102
107
if let Some ( ( _, dep) ) = parent {
103
108
if dep. source_id ( ) != id. source_id ( ) {
104
- let key = ( id. name ( ) , dep. source_id ( ) , id. version ( ) . into ( ) ) ;
105
- let prev = self . activations . insert ( key, ( summary. clone ( ) , age) ) ;
109
+ let new_id =
110
+ PackageId :: new ( id. name ( ) , id. version ( ) . clone ( ) , dep. source_id ( ) ) ;
111
+
112
+ let prev = self
113
+ . activations
114
+ . insert ( new_id. activation_key ( ) , ( summary. clone ( ) , age) ) ;
115
+
106
116
if let Some ( ( previous_summary, _) ) = prev {
107
117
return Err (
108
118
( previous_summary. package_id ( ) , ConflictReason :: Semver ) . into ( )
@@ -145,9 +155,13 @@ impl ResolverContext {
145
155
146
156
/// If the package is active returns the `ContextAge` when it was added
147
157
pub fn is_active ( & self , id : PackageId ) -> Option < ContextAge > {
148
- self . activations
149
- . get ( & id. as_activations_key ( ) )
150
- . and_then ( |( s, l) | if s. package_id ( ) == id { Some ( * l) } else { None } )
158
+ let ( summary, age) = self . activations . get ( & id. activation_key ( ) ) ?;
159
+
160
+ if summary. package_id ( ) == id {
161
+ Some ( * age)
162
+ } else {
163
+ None
164
+ }
151
165
}
152
166
153
167
/// Checks whether all of `parent` and the keys of `conflicting activations`
@@ -163,8 +177,8 @@ impl ResolverContext {
163
177
max = std:: cmp:: max ( max, self . is_active ( parent) ?) ;
164
178
}
165
179
166
- for id in conflicting_activations. keys ( ) {
167
- max = std:: cmp:: max ( max, self . is_active ( * id) ?) ;
180
+ for & id in conflicting_activations. keys ( ) {
181
+ max = std:: cmp:: max ( max, self . is_active ( id) ?) ;
168
182
}
169
183
Some ( max)
170
184
}
0 commit comments