@@ -6,10 +6,7 @@ use super::utils::{SourceCode, source_code_with};
66use rustc_data_structures:: fx:: FxHashMap ;
77use rustc_middle:: ty:: TyCtxt ;
88use rustc_span:: source_map:: { SourceMap , get_source_map} ;
9- use stable_mir:: {
10- CrateDef , DefId ,
11- mir:: { Body , mono:: Instance } ,
12- } ;
9+ use stable_mir:: mir:: { Body , mono:: Instance } ;
1310use std:: { cell:: RefCell , cmp:: Ordering , sync:: Arc } ;
1411
1512thread_local ! {
@@ -45,39 +42,20 @@ pub fn get_source_code(inst: &Instance) -> Option<SourceCode> {
4542 get_cache_func ( inst, |cf| cf. src . clone ( ) )
4643}
4744
48- /// NOTE: this function doesn't auto insert SourceCode if Instance isn't handled.
49- pub fn share_same_source_code ( a : & Instance , b : & Instance ) -> bool {
50- get_cache ( |cache| {
51- let defid_a = a. def . def_id ( ) ;
52- let defid_b = b. def . def_id ( ) ;
53- let src_a = cache. set . get ( & defid_a) ;
54- let src_b = cache. set . get ( & defid_b) ;
55- match ( src_a, src_b) {
56- ( Some ( cache_a) , Some ( cache_b) ) => match ( cache_a, cache_b) {
57- ( Some ( func_a) , Some ( func_b) ) => func_a. src == func_b. src ,
58- ( None , None ) => defid_a == defid_b,
59- ( None , Some ( _) ) => false ,
60- ( Some ( _) , None ) => false ,
61- } ,
62- ( None , None ) => defid_a == defid_b,
63- ( None , Some ( _) ) => false ,
64- ( Some ( _) , None ) => false ,
65- }
66- } )
67- }
68-
6945pub fn cmp_callees ( a : & Instance , b : & Instance ) -> Ordering {
7046 get_cache ( |cache| {
7147 cache. get_or_insert ( a) ;
7248 cache. get_or_insert ( b) ;
73- let func_a = cache. set . get ( & a . def . def_id ( ) ) . unwrap ( ) . as_ref ( ) . map ( |f| & f. src ) ;
74- let func_b = cache. set . get ( & b . def . def_id ( ) ) . unwrap ( ) . as_ref ( ) . map ( |f| & f. src ) ;
49+ let func_a = cache. set . get ( a ) . unwrap ( ) . as_ref ( ) . map ( |f| & f. src ) ;
50+ let func_b = cache. set . get ( b ) . unwrap ( ) . as_ref ( ) . map ( |f| & f. src ) ;
7551 func_a. cmp ( & func_b)
7652 } )
7753}
7854
7955struct Cache {
80- set : FxHashMap < DefId , Option < CacheFunction > > ,
56+ /// The reason to have Instance as the key is
57+ /// https://github.com/os-checker/distributed-verification/issues/42
58+ set : FxHashMap < Instance , Option < CacheFunction > > ,
8159 rustc : Option < RustcCxt > ,
8260 path_prefixes : PathPrefixes ,
8361}
@@ -91,7 +69,7 @@ impl Cache {
9169
9270 fn get_or_insert ( & mut self , inst : & Instance ) -> Option < & CacheFunction > {
9371 self . set
94- . entry ( inst. def . def_id ( ) )
72+ . entry ( * inst)
9573 . or_insert_with ( || {
9674 let body = inst. body ( ) ?;
9775 let rustc = self . rustc . as_ref ( ) ?;
0 commit comments