@@ -2153,62 +2153,22 @@ impl ClashingExternDeclarations {
2153
2153
b : Ty < ' tcx > ,
2154
2154
ckind : CItemKind ,
2155
2155
) -> bool {
2156
- // In order to avoid endlessly recursing on recursive types, we maintain a "seen" set.
2157
- // We'll need to store every combination of types we encounter anyway, so we also memoize
2158
- // the result.
2159
- struct SeenSet < ' tcx > ( FxHashMap < ( Ty < ' tcx > , Ty < ' tcx > ) , Option < bool > > ) ;
2160
-
2161
- enum SeenSetResult {
2162
- /// We've never seen this combination of types.
2163
- Unseen ,
2164
- /// We've seen this combination of types, but are still computing the result.
2165
- Computing ,
2166
- /// We've seen this combination of types, and have already computed the result.
2167
- Computed ( bool ) ,
2168
- }
2169
-
2170
- impl < ' tcx > SeenSet < ' tcx > {
2171
- fn new ( ) -> Self {
2172
- SeenSet ( FxHashMap :: default ( ) )
2173
- }
2174
- /// Mark (a, b) as `Computing`.
2175
- fn mark_computing ( & mut self , a : Ty < ' tcx > , b : Ty < ' tcx > ) {
2176
- self . 0 . insert ( ( a, b) , None ) ;
2177
- }
2178
- /// Mark (a, b) as `Computed(result)`.
2179
- fn mark_computed ( & mut self , a : Ty < ' tcx > , b : Ty < ' tcx > , result : bool ) {
2180
- * self . 0 . get_mut ( & ( a, b) ) . expect ( "Missing prior call to mark_computing" ) =
2181
- Some ( result) ;
2182
- }
2183
- fn get ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> SeenSetResult {
2184
- match self . 0 . get ( & ( a, b) ) {
2185
- None => SeenSetResult :: Unseen ,
2186
- Some ( None ) => SeenSetResult :: Computing ,
2187
- Some ( Some ( b) ) => SeenSetResult :: Computed ( * b) ,
2188
- }
2189
- }
2190
- }
2191
2156
fn structurally_same_type_impl < ' tcx > (
2192
- seen_types : & mut SeenSet < ' tcx > ,
2157
+ seen_types : & mut FxHashSet < ( Ty < ' tcx > , Ty < ' tcx > ) > ,
2193
2158
cx : & LateContext < ' tcx > ,
2194
2159
a : Ty < ' tcx > ,
2195
2160
b : Ty < ' tcx > ,
2196
2161
ckind : CItemKind ,
2197
2162
) -> bool {
2198
2163
debug ! ( "structurally_same_type_impl(cx, a = {:?}, b = {:?})" , a, b) ;
2199
- match seen_types. get ( a, b) {
2200
- // If we've already computed the result, just return the memoized result.
2201
- SeenSetResult :: Computed ( result) => return result,
2202
- // We are already in the process of computing structural sameness for this type,
2203
- // meaning we've found a cycle. The types are structurally same, then.
2204
- SeenSetResult :: Computing => return true ,
2205
- // We haven't seen this combination of types at all -- continue on to computing
2206
- // their sameness.
2207
- SeenSetResult :: Unseen => ( ) ,
2164
+ if seen_types. contains ( & ( a, b) ) {
2165
+ // We've encountered a cycle. There's no point going any further -- the types are
2166
+ // structurally the same.
2167
+ return true ;
2208
2168
}
2209
- seen_types. mark_computing ( a, b) ;
2169
+ seen_types. insert ( ( a, b) ) ;
2210
2170
let tcx = cx. tcx ;
2211
- let result = if a == b || rustc_middle:: ty:: TyS :: same_type ( a, b) {
2171
+ if a == b || rustc_middle:: ty:: TyS :: same_type ( a, b) {
2212
2172
// All nominally-same types are structurally same, too.
2213
2173
true
2214
2174
} else {
@@ -2333,11 +2293,9 @@ impl ClashingExternDeclarations {
2333
2293
// uninitialised memory.
2334
2294
_ => compare_layouts ( a, b) ,
2335
2295
}
2336
- } ;
2337
- seen_types. mark_computed ( a, b, result) ;
2338
- result
2296
+ }
2339
2297
}
2340
- let mut seen_types = SeenSet :: new ( ) ;
2298
+ let mut seen_types = FxHashSet :: default ( ) ;
2341
2299
structurally_same_type_impl ( & mut seen_types, cx, a, b, ckind)
2342
2300
}
2343
2301
}
0 commit comments