@@ -16,7 +16,7 @@ use crate::kani_middle::{check_reachable_items, dump_mir_items};
1616use crate :: kani_queries:: QueryDb ;
1717use cbmc:: goto_program:: Location ;
1818use cbmc:: irep:: goto_binary_serde:: write_goto_binary_file;
19- use cbmc:: RoundingMode ;
19+ use cbmc:: { InternString , RoundingMode } ;
2020use cbmc:: { InternedString , MachineModel } ;
2121use kani_metadata:: artifact:: convert_type;
2222use kani_metadata:: CompilerArtifactStub ;
@@ -32,12 +32,10 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
3232use rustc_data_structures:: temp_dir:: MaybeTempDir ;
3333use rustc_errors:: { ErrorGuaranteed , DEFAULT_LOCALE_RESOURCE } ;
3434use rustc_hir:: def_id:: LOCAL_CRATE ;
35- use rustc_hir:: definitions:: DefPathHash ;
3635use rustc_metadata:: creader:: MetadataLoaderDyn ;
3736use rustc_metadata:: fs:: { emit_wrapper_file, METADATA_FILENAME } ;
3837use rustc_metadata:: EncodedMetadata ;
3938use rustc_middle:: dep_graph:: { WorkProduct , WorkProductId } ;
40- use rustc_middle:: mir:: mono:: MonoItem ;
4139use rustc_middle:: ty:: TyCtxt ;
4240use rustc_middle:: util:: Providers ;
4341use rustc_session:: config:: { CrateType , OutputFilenames , OutputType } ;
@@ -46,7 +44,7 @@ use rustc_session::Session;
4644use rustc_smir:: rustc_internal;
4745use rustc_target:: abi:: Endian ;
4846use rustc_target:: spec:: PanicStrategy ;
49- use stable_mir:: mir:: mono:: MonoItem as MonoItemStable ;
47+ use stable_mir:: mir:: mono:: MonoItem ;
5048use stable_mir:: CrateDef ;
5149use std:: any:: Any ;
5250use std:: collections:: BTreeMap ;
@@ -82,10 +80,10 @@ impl GotocCodegenBackend {
8280 fn codegen_items < ' tcx > (
8381 & self ,
8482 tcx : TyCtxt < ' tcx > ,
85- starting_items : & [ MonoItem < ' tcx > ] ,
83+ starting_items : & [ MonoItem ] ,
8684 symtab_goto : & Path ,
8785 machine_model : & MachineModel ,
88- ) -> ( GotocCtx < ' tcx > , Vec < MonoItem < ' tcx > > ) {
86+ ) -> ( GotocCtx < ' tcx > , Vec < MonoItem > ) {
8987 let items = with_timer (
9088 || collect_reachable_items ( tcx, starting_items) ,
9189 "codegen reachability analysis" ,
@@ -103,17 +101,13 @@ impl GotocCodegenBackend {
103101 for item in & items {
104102 match * item {
105103 MonoItem :: Fn ( instance) => {
106- let instance = rustc_internal:: stable ( instance) ;
107104 gcx. call_with_panic_debug_info (
108105 |ctx| ctx. declare_function ( instance) ,
109106 format ! ( "declare_function: {}" , instance. name( ) ) ,
110107 instance. def ,
111108 ) ;
112109 }
113- MonoItem :: Static ( _) => {
114- let MonoItemStable :: Static ( def) = rustc_internal:: stable ( item) else {
115- unreachable ! ( )
116- } ;
110+ MonoItem :: Static ( def) => {
117111 gcx. call_with_panic_debug_info (
118112 |ctx| ctx. declare_static ( def) ,
119113 format ! ( "declare_static: {}" , def. name( ) ) ,
@@ -128,7 +122,6 @@ impl GotocCodegenBackend {
128122 for item in & items {
129123 match * item {
130124 MonoItem :: Fn ( instance) => {
131- let instance = rustc_internal:: stable ( instance) ;
132125 gcx. call_with_panic_debug_info (
133126 |ctx| ctx. codegen_function ( instance) ,
134127 format ! (
@@ -139,10 +132,7 @@ impl GotocCodegenBackend {
139132 instance. def ,
140133 ) ;
141134 }
142- MonoItem :: Static ( _) => {
143- let MonoItemStable :: Static ( def) = rustc_internal:: stable ( item) else {
144- unreachable ! ( )
145- } ;
135+ MonoItem :: Static ( def) => {
146136 gcx. call_with_panic_debug_info (
147137 |ctx| ctx. codegen_static ( def) ,
148138 format ! ( "codegen_static: {}" , def. name( ) ) ,
@@ -237,28 +227,30 @@ impl CodegenBackend for GotocCodegenBackend {
237227 ReachabilityType :: Harnesses => {
238228 // Cross-crate collecting of all items that are reachable from the crate harnesses.
239229 let harnesses = queries. target_harnesses ( ) ;
240- let mut items: HashSet < DefPathHash > = HashSet :: with_capacity ( harnesses. len ( ) ) ;
230+ let mut items: HashSet < _ > = HashSet :: with_capacity ( harnesses. len ( ) ) ;
241231 items. extend ( harnesses) ;
242- let harnesses = filter_crate_items ( tcx, |_, def_id | {
243- items. contains ( & tcx . def_path_hash ( def_id ) )
232+ let harnesses = filter_crate_items ( tcx, |_, instance | {
233+ items. contains ( & instance . name ( ) . intern ( ) )
244234 } ) ;
245235 for harness in harnesses {
246- let model_path = queries
247- . harness_model_path ( & tcx. def_path_hash ( harness. def_id ( ) ) )
248- . unwrap ( ) ;
249- let ( gcx, items) =
250- self . codegen_items ( tcx, & [ harness] , model_path, & results. machine_model ) ;
251- results. extend ( gcx, items, None ) ;
236+ let model_path = queries. harness_model_path ( & harness. name ( ) ) . unwrap ( ) ;
237+ let ( gcx, mono_items) = self . codegen_items (
238+ tcx,
239+ & [ MonoItem :: Fn ( harness) ] ,
240+ model_path,
241+ & results. machine_model ,
242+ ) ;
243+ results. extend ( gcx, mono_items, None ) ;
252244 }
253245 }
254246 ReachabilityType :: Tests => {
255247 // We're iterating over crate items here, so what we have to codegen is the "test description" containing the
256248 // test closure that we want to execute
257249 // TODO: Refactor this code so we can guarantee that the pair (test_fn, test_desc) actually match.
258250 let mut descriptions = vec ! [ ] ;
259- let harnesses = filter_const_crate_items ( tcx, |_, def_id | {
260- if is_test_harness_description ( tcx, def_id ) {
261- descriptions. push ( def_id ) ;
251+ let harnesses = filter_const_crate_items ( tcx, |_, item | {
252+ if is_test_harness_description ( tcx, item . def ) {
253+ descriptions. push ( item . def ) ;
262254 true
263255 } else {
264256 false
@@ -289,11 +281,10 @@ impl CodegenBackend for GotocCodegenBackend {
289281 }
290282 ReachabilityType :: None => { }
291283 ReachabilityType :: PubFns => {
292- let entry_fn = tcx. entry_fn ( ( ) ) . map ( |( id, _) | id) ;
293- let local_reachable = filter_crate_items ( tcx, |_, def_id| {
294- ( tcx. is_reachable_non_generic ( def_id) && tcx. def_kind ( def_id) . is_fn_like ( ) )
295- || entry_fn == Some ( def_id)
296- } ) ;
284+ let local_reachable = filter_crate_items ( tcx, |_, _| true )
285+ . into_iter ( )
286+ . map ( MonoItem :: Fn )
287+ . collect :: < Vec < _ > > ( ) ;
297288 let model_path = base_filename. with_extension ( ArtifactType :: SymTabGoto ) ;
298289 let ( gcx, items) = self . codegen_items (
299290 tcx,
@@ -527,17 +518,17 @@ where
527518 }
528519}
529520
530- struct GotoCodegenResults < ' tcx > {
521+ struct GotoCodegenResults {
531522 reachability : ReachabilityType ,
532523 harnesses : Vec < HarnessMetadata > ,
533524 unsupported_constructs : UnsupportedConstructs ,
534525 concurrent_constructs : UnsupportedConstructs ,
535- items : Vec < MonoItem < ' tcx > > ,
526+ items : Vec < MonoItem > ,
536527 crate_name : InternedString ,
537528 machine_model : MachineModel ,
538529}
539530
540- impl < ' tcx > GotoCodegenResults < ' tcx > {
531+ impl GotoCodegenResults {
541532 pub fn new ( tcx : TyCtxt , reachability : ReachabilityType ) -> Self {
542533 GotoCodegenResults {
543534 reachability,
@@ -585,12 +576,7 @@ impl<'tcx> GotoCodegenResults<'tcx> {
585576 }
586577 }
587578
588- fn extend (
589- & mut self ,
590- gcx : GotocCtx ,
591- items : Vec < MonoItem < ' tcx > > ,
592- metadata : Option < HarnessMetadata > ,
593- ) {
579+ fn extend ( & mut self , gcx : GotocCtx , items : Vec < MonoItem > , metadata : Option < HarnessMetadata > ) {
594580 let mut items = items;
595581 self . harnesses . extend ( metadata) ;
596582 self . concurrent_constructs . extend ( gcx. concurrent_constructs ) ;
@@ -599,7 +585,7 @@ impl<'tcx> GotoCodegenResults<'tcx> {
599585 }
600586
601587 /// Prints a report at the end of the compilation.
602- fn print_report ( & self , tcx : TyCtxt < ' tcx > ) {
588+ fn print_report ( & self , tcx : TyCtxt ) {
603589 // Print all unsupported constructs.
604590 if !self . unsupported_constructs . is_empty ( ) {
605591 // Sort alphabetically.
@@ -631,7 +617,7 @@ impl<'tcx> GotoCodegenResults<'tcx> {
631617
632618 // Print some compilation stats.
633619 if tracing:: enabled!( tracing:: Level :: INFO ) {
634- analysis:: print_stats ( tcx , & self . items ) ;
620+ analysis:: print_stats ( & self . items ) ;
635621 }
636622 }
637623}
0 commit comments