@@ -580,8 +580,8 @@ pub struct MiriMachine<'tcx> {
580580 /// Equivalent setting as RUST_BACKTRACE on encountering an error.
581581 pub ( crate ) backtrace_style : BacktraceStyle ,
582582
583- /// Crates which are considered local for the purposes of error reporting.
584- pub ( crate ) local_crates : Vec < CrateNum > ,
583+ /// Crates which are considered user-relevant for the purposes of error reporting.
584+ pub ( crate ) user_relevant_crates : Vec < CrateNum > ,
585585
586586 /// Mapping extern static names to their pointer.
587587 extern_statics : FxHashMap < Symbol , StrictPointer > ,
@@ -684,7 +684,7 @@ impl<'tcx> MiriMachine<'tcx> {
684684 genmc_ctx : Option < Rc < GenmcCtx > > ,
685685 ) -> Self {
686686 let tcx = layout_cx. tcx ( ) ;
687- let local_crates = helpers :: get_local_crates ( tcx) ;
687+ let user_relevant_crates = Self :: get_user_relevant_crates ( tcx, config ) ;
688688 let layouts =
689689 PrimitiveLayouts :: new ( layout_cx) . expect ( "Couldn't get layouts of primitive types" ) ;
690690 let profiler = config. measureme_out . as_ref ( ) . map ( |out| {
@@ -774,7 +774,7 @@ impl<'tcx> MiriMachine<'tcx> {
774774 string_cache : Default :: default ( ) ,
775775 exported_symbols_cache : FxHashMap :: default ( ) ,
776776 backtrace_style : config. backtrace_style ,
777- local_crates ,
777+ user_relevant_crates ,
778778 extern_statics : FxHashMap :: default ( ) ,
779779 rng : RefCell :: new ( rng) ,
780780 allocator : ( !config. native_lib . is_empty ( ) )
@@ -865,6 +865,29 @@ impl<'tcx> MiriMachine<'tcx> {
865865 symbols
866866 }
867867
868+ /// Retrieve the list of user-relevant crates based on MIRI_LOCAL_CRATES as set by cargo-miri,
869+ /// and extra crates set in the config.
870+ fn get_user_relevant_crates ( tcx : TyCtxt < ' _ > , config : & MiriConfig ) -> Vec < CrateNum > {
871+ // Convert the local crate names from the passed-in config into CrateNums so that they can
872+ // be looked up quickly during execution
873+ let local_crate_names = std:: env:: var ( "MIRI_LOCAL_CRATES" )
874+ . map ( |crates| crates. split ( ',' ) . map ( |krate| krate. to_string ( ) ) . collect :: < Vec < _ > > ( ) )
875+ . unwrap_or_default ( ) ;
876+ let mut local_crates = Vec :: new ( ) ;
877+ for & crate_num in tcx. crates ( ( ) ) {
878+ let name = tcx. crate_name ( crate_num) ;
879+ let name = name. as_str ( ) ;
880+ if local_crate_names
881+ . iter ( )
882+ . chain ( & config. user_relevant_crates )
883+ . any ( |local_name| local_name == name)
884+ {
885+ local_crates. push ( crate_num) ;
886+ }
887+ }
888+ local_crates
889+ }
890+
868891 pub ( crate ) fn late_init (
869892 ecx : & mut MiriInterpCx < ' tcx > ,
870893 config : & MiriConfig ,
@@ -889,7 +912,7 @@ impl<'tcx> MiriMachine<'tcx> {
889912 /// Check whether the stack frame that this `FrameInfo` refers to is part of a local crate.
890913 pub ( crate ) fn is_local ( & self , frame : & FrameInfo < ' _ > ) -> bool {
891914 let def_id = frame. instance . def_id ( ) ;
892- def_id. is_local ( ) || self . local_crates . contains ( & def_id. krate )
915+ def_id. is_local ( ) || self . user_relevant_crates . contains ( & def_id. krate )
893916 }
894917
895918 /// Called when the interpreter is going to shut down abnormally, such as due to a Ctrl-C.
@@ -1006,7 +1029,7 @@ impl VisitProvenance for MiriMachine<'_> {
10061029 string_cache : _,
10071030 exported_symbols_cache : _,
10081031 backtrace_style : _,
1009- local_crates : _,
1032+ user_relevant_crates : _,
10101033 rng : _,
10111034 allocator : _,
10121035 tracked_alloc_ids : _,
0 commit comments