@@ -2153,62 +2153,22 @@ impl ClashingExternDeclarations {
21532153 b : Ty < ' tcx > ,
21542154 ckind : CItemKind ,
21552155 ) -> 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- }
21912156 fn structurally_same_type_impl < ' tcx > (
2192- seen_types : & mut SeenSet < ' tcx > ,
2157+ seen_types : & mut FxHashSet < ( Ty < ' tcx > , Ty < ' tcx > ) > ,
21932158 cx : & LateContext < ' tcx > ,
21942159 a : Ty < ' tcx > ,
21952160 b : Ty < ' tcx > ,
21962161 ckind : CItemKind ,
21972162 ) -> bool {
21982163 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 ;
22082168 }
2209- seen_types. mark_computing ( a, b) ;
2169+ seen_types. insert ( ( a, b) ) ;
22102170 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) {
22122172 // All nominally-same types are structurally same, too.
22132173 true
22142174 } else {
@@ -2333,11 +2293,9 @@ impl ClashingExternDeclarations {
23332293 // uninitialised memory.
23342294 _ => compare_layouts ( a, b) ,
23352295 }
2336- } ;
2337- seen_types. mark_computed ( a, b, result) ;
2338- result
2296+ }
23392297 }
2340- let mut seen_types = SeenSet :: new ( ) ;
2298+ let mut seen_types = FxHashSet :: default ( ) ;
23412299 structurally_same_type_impl ( & mut seen_types, cx, a, b, ckind)
23422300 }
23432301}
0 commit comments