@@ -9,6 +9,7 @@ use stable_mir::{
99 mir:: mono:: { Instance , MonoItem } ,
1010 ty:: { FnDef , RigidTy , Ty , TyKind } ,
1111} ;
12+ use std:: cmp:: Ordering ;
1213
1314mod kani;
1415mod serialization;
@@ -81,6 +82,7 @@ impl Function {
8182
8283 let mut callees = IndexSet :: new ( ) ;
8384 callgraph. recursive_callees ( item, & mut callees) ;
85+ callees. sort_by ( |a, b| cmp_callees ( a, b, tcx, src_map) ) ;
8486
8587 let func = source_code_with ( body. span , tcx, src_map) ;
8688 info ! ( " - {:?} ({span:?}): {func}" , inst_def. name( ) ) ;
@@ -119,3 +121,20 @@ fn source_code_with(
119121 let span = internal ( tcx, stable_mir_span) ;
120122 source_code ( span, src_map)
121123}
124+
125+ fn source_code_of_body ( inst : & Instance , tcx : TyCtxt , src_map : & SourceMap ) -> Option < String > {
126+ inst. body ( ) . map ( |body| source_code_with ( body. span , tcx, src_map) )
127+ }
128+
129+ fn cmp_callees ( a : & Instance , b : & Instance , tcx : TyCtxt , src_map : & SourceMap ) -> Ordering {
130+ let filename_a = a. def . span ( ) . get_filename ( ) ;
131+ let filename_b = b. def . span ( ) . get_filename ( ) ;
132+ match filename_a. cmp ( & filename_b) {
133+ Ordering :: Equal => ( ) ,
134+ ord => return ord,
135+ }
136+
137+ let body_a = source_code_of_body ( a, tcx, src_map) ;
138+ let body_b = source_code_of_body ( b, tcx, src_map) ;
139+ body_a. cmp ( & body_b)
140+ }
0 commit comments